NRP Core  1.4.1
input_dummy.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef INPUT_DUMMY_H
23 #define INPUT_DUMMY_H
24 
25 #include <boost/python.hpp>
26 
29 
33 class InputDummy : public InputNode<boost::python::object> {
34 public:
35 
36  InputDummy(const std::string &id, boost::python::object value) :
37  InputNode(id),
38  _value(std::move(value))
39  {}
40 
41 protected:
42 
43  void configure() override
44  {}
45 
46  bool updatePortData(const std::string& id) override
47  {
48  _portMap.at(id).clear();
49  _portMap.at(id).addMsg(&_value);
50 
51  return true;
52  }
53 
54 private:
55 
56  boost::python::object _value;
57 };
58 
59 
60 class InputDummyEdge : public SimpleInputEdge<boost::python::object, InputDummy> {
61 
62 public:
63 
64  InputDummyEdge(const std::string& keyword, const std::string& id, boost::python::object value) :
65  SimpleInputEdge<boost::python::object, InputDummy>(keyword, id, id, InputNodePolicies::LAST, InputNodePolicies::KEEP_CACHE),
66  _value(std::move(value))
67  {}
68 
69 protected:
70 
71  boost::python::object _value;
72 
74  { return new InputDummy(this->_id, _value); }
75 };
76 
77 
78 #endif //INPUT_DUMMY_H
InputDummy
Dummy input node which always sends the same msg upon request.
Definition: input_dummy.h:33
input_node.h
InputNodePolicies::KEEP_CACHE
@ KEEP_CACHE
Definition: computational_node_policies.h:29
InputNode
Implementation of an input node in the computation graph.
Definition: input_node.h:129
InputNode< boost::python::object >::_portMap
std::map< std::string, DataPortHandle< boost::python::object > > _portMap
Map containing data to handle topics. Data is guaranteed to be unchanged between 'compute' calls
Definition: input_node.h:219
InputDummy::configure
void configure() override
Configures the node making it ready to execute 'compute'.
Definition: input_dummy.h:43
ComputationalNode::id
const std::string & id() const
Returns the node 'id'.
Definition: computational_node.h:57
InputDummyEdge::InputDummyEdge
InputDummyEdge(const std::string &keyword, const std::string &id, boost::python::object value)
Definition: input_dummy.h:64
InputEdge::_id
std::string _id
Definition: input_edge.h:151
InputDummy::updatePortData
bool updatePortData(const std::string &id) override
Updates pointers stored in _portMap for port 'id'.
Definition: input_dummy.h:46
input_edge.h
InputNodePolicies::LAST
@ LAST
Definition: computational_node_policies.h:34
InputDummyEdge::_value
boost::python::object _value
Definition: input_dummy.h:71
InputDummyEdge::makeNewNode
InputDummy * makeNewNode()
Definition: input_dummy.h:73
InputEdge
Helper template class used to implement Python input edge decorators.
Definition: input_edge.h:38
InputDummyEdge
Definition: input_dummy.h:60
InputDummy::InputDummy
InputDummy(const std::string &id, boost::python::object value)
Definition: input_dummy.h:36
InputNodePolicies
Definition: computational_node_policies.h:25