ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
SystemFacade.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-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#pragma once
21
22#include "System.hpp"
23
25
26#include <memory>
27#include <string>
28
29namespace ScriptInterface {
30namespace System {
31
32/**
33 * @brief Facade for the real @ref System class.
34 * All calls are forwarded to the real class.
35 * This construct is needed to satisfy the requirements
36 * of the checkpointing mechanism, which instantiates
37 * the @c SystemFacade after all other script interface
38 * objects have been instantiated.
39 */
40class SystemFacade : public ObjectHandle {
41 std::shared_ptr<System> m_instance;
42
43public:
45 // create a dummy system to be able to read the list of parameters
46 m_instance = std::make_shared<System>();
47 }
48 void do_construct(VariantMap const &) override {};
49 Variant get_parameter(const std::string &name) const override {
50 return m_instance->get_parameter(name);
51 }
52 void do_set_parameter(const std::string &name, const Variant &v) override {
53 m_instance->do_set_parameter(name, v);
54 }
56 return m_instance->valid_parameters();
57 }
58 Variant do_call_method(std::string const &name,
59 VariantMap const &params) override {
60 if (name == "get_system_handle") {
61 return m_instance;
62 }
63 if (name == "set_system_handle") {
64 m_instance = std::dynamic_pointer_cast<System>(
65 get_value<ObjectRef>(params, "obj"));
66 return {};
67 }
68 return m_instance->do_call_method(name, params);
69 }
70};
71
72} // namespace System
73} // namespace ScriptInterface
Base class for interface handles.
boost::string_ref name() const
Facade for the real System class.
Utils::Span< const boost::string_ref > valid_parameters() const override
Variant do_call_method(std::string const &name, VariantMap const &params) override
Variant get_parameter(const std::string &name) const override
void do_set_parameter(const std::string &name, const Variant &v) override
void do_construct(VariantMap const &) override
A stripped-down version of std::span from C++17.
Definition Span.hpp:38
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
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
static SteepestDescentParameters params
Currently active steepest descent instance.