ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CodeInfo.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "CodeInfo.hpp"
21
22#include "config/config-features.hpp"
23#include "config/version.hpp"
25
26#include <boost/algorithm/string/join.hpp>
27
28#include <algorithm>
29#include <string>
30#include <vector>
31
32namespace ScriptInterface {
33namespace CodeInfo {
34
35static auto get_feature_vector(char const *const ptr[], unsigned int len) {
36 return std::vector<std::string>{ptr, ptr + len};
37}
38
39static Variant get_feature_list(char const *const ptr[], unsigned int len) {
40 return make_vector_of_variants(std::vector<std::string>{ptr, ptr + len});
41}
42
43Variant CodeInfo::do_call_method(std::string const &name,
44 VariantMap const &parameters) {
45 if (name == "features") {
46 return get_feature_list(FEATURES, NUM_FEATURES);
47 }
48 if (name == "all_features") {
49 return get_feature_list(FEATURES_ALL, NUM_FEATURES_ALL);
50 }
51 if (name == "build_type") {
52 return std::string(ESPRESSO_BUILD_TYPE);
53 }
54 if (name == "scafacos_methods") {
55#ifdef SCAFACOS
57#else // SCAFACOS
58 return make_vector_of_variants(std::vector<std::string>(0));
59#endif // SCAFACOS
60 }
61 return {};
62}
63
64void check_features(std::vector<std::string> const &features) {
65 auto const allowed = get_feature_vector(FEATURES_ALL, NUM_FEATURES_ALL);
66 auto const built = get_feature_vector(FEATURES, NUM_FEATURES);
67 std::vector<std::string> missing_features{};
68 for (auto const &feature : features) {
69 if (std::find(allowed.begin(), allowed.end(), feature) == allowed.end()) {
70 throw std::runtime_error("Unknown feature '" + feature + "'");
71 }
72 if (std::find(built.begin(), built.end(), feature) == built.end()) {
73 missing_features.emplace_back(feature);
74 }
75 }
76 if (not missing_features.empty()) {
77 throw std::runtime_error("Missing features " +
78 boost::algorithm::join(missing_features, ", "));
79 }
80}
81
82} // namespace CodeInfo
83} // namespace ScriptInterface
Variant do_call_method(std::string const &name, VariantMap const &parameters) override
Definition CodeInfo.cpp:43
boost::string_ref name() const
static auto get_feature_vector(char const *const ptr[], unsigned int len)
Definition CodeInfo.cpp:35
void check_features(std::vector< std::string > const &features)
Definition CodeInfo.cpp:64
static Variant get_feature_list(char const *const ptr[], unsigned int len)
Definition CodeInfo.cpp:39
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition scafacos.cpp:49
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:101
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80