Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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 <stdexcept>
29#include <string>
30#include <unordered_set>
31#include <vector>
32
33namespace ScriptInterface {
34namespace CodeInfo {
35
36static auto get_feature_vector(char const *const ptr[], unsigned int len) {
37 return std::vector<std::string>{ptr, ptr + len};
38}
39
40static auto get_feature_set(char const *const ptr[], unsigned int len) {
41 return std::unordered_set<std::string>(ptr, ptr + len);
42}
43
44Variant CodeInfo::do_call_method(std::string const &name,
45 VariantMap const &parameters) {
46 if (name == "features") {
48 }
49 if (name == "all_features") {
52 }
53 if (name == "build_type") {
54 return std::string(ESPRESSO_BUILD_TYPE);
55 }
56 if (name == "scafacos_methods") {
57#ifdef SCAFACOS
59#else // SCAFACOS
60 return make_vector_of_variants(std::vector<std::string>(0));
61#endif // SCAFACOS
62 }
63 return {};
64}
65
66void check_features(std::vector<std::string> const &features) {
69 std::vector<std::string> missing_features{};
70 for (auto const &feature : features) {
71 if (not allowed.contains(feature)) {
72 throw std::runtime_error("Unknown feature '" + feature + "'");
73 }
74 if (not compiled_features.contains(feature)) {
75 missing_features.emplace_back(feature);
76 }
77 }
78 if (not missing_features.empty()) {
79 throw std::runtime_error("Missing features " +
80 boost::algorithm::join(missing_features, ", "));
81 }
82}
83
84} // namespace CodeInfo
85} // namespace ScriptInterface
Variant do_call_method(std::string const &name, VariantMap const &parameters) override
Definition CodeInfo.cpp:44
boost::string_ref name() const
static auto get_feature_vector(char const *const ptr[], unsigned int len)
Definition CodeInfo.cpp:36
void check_features(std::vector< std::string > const &features)
Definition CodeInfo.cpp:66
static auto get_feature_set(char const *const ptr[], unsigned int len)
Definition CodeInfo.cpp:40
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition scafacos.cpp:49
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:88
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:67