| helics 3.6.1

MessageOperators.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8
9 #include "../core/core-data.hpp"
10 #include "data_view.hpp"
11 #include "helics_cxx_export.h"
12
13 #include <atomic>
14 #include <functional>
15 #include <memory>
16 #include <string>
17 #include <vector>
22 namespace helics {
24 class HELICS_CXX_EXPORT MessageTimeOperator: public FilterOperator {
25 public:
27 MessageTimeOperator() = default;
29 explicit MessageTimeOperator(std::function<Time(Time)> userTimeFunction);
31 void setTimeFunction(std::function<Time(Time)> userTimeFunction);
32
33 private:
34 std::function<Time(Time)> TimeFunction;
35 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
36 };
37
39 class HELICS_CXX_EXPORT MessageDestOperator: public FilterOperator {
40 public:
42 MessageDestOperator() = default;
44 explicit MessageDestOperator(
45 std::function<std::string(const std::string&, const std::string&)> userDestFunction);
47 void setDestFunction(
48 std::function<std::string(const std::string&, const std::string&)> userDestFunction);
49 virtual bool isMessageGenerating() const override { return true; }
50
51 private:
52 std::function<std::string(const std::string&, const std::string&)>
53 DestUpdateFunction;
54 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
55 };
56
58 class HELICS_CXX_EXPORT MessageDataOperator: public FilterOperator {
59 public:
61 MessageDataOperator() = default;
63 explicit MessageDataOperator(std::function<void(SmallBuffer&)> userDataFunction);
65 void setDataFunction(std::function<void(SmallBuffer&)> userDataFunction);
66
67 private:
68 std::function<void(SmallBuffer&)> dataFunction;
69 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
70 };
71
76 class HELICS_CXX_EXPORT MessageConditionalOperator: public FilterOperator {
77 public:
79 MessageConditionalOperator() = default;
81 explicit MessageConditionalOperator(
82 std::function<bool(const Message*)> userConditionalFunction);
84 void setConditionFunction(std::function<bool(const Message*)> userConditionFunction);
85
86 private:
87 std::function<bool(const Message*)>
88 evalFunction;
89 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
90 };
91
96 class HELICS_CXX_EXPORT CloneOperator: public FilterOperator {
97 public:
99 CloneOperator() = default;
101 explicit CloneOperator(
102 std::function<std::vector<std::unique_ptr<Message>>(const Message*)> userCloneFunction);
104 void setCloneFunction(
105 std::function<std::vector<std::unique_ptr<Message>>(const Message*)> userCloneFunction);
106 virtual bool isMessageGenerating() const override { return true; }
107
108 private:
109 std::function<std::vector<std::unique_ptr<Message>>(const Message*)>
110 evalFunction;
111 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
112 virtual std::vector<std::unique_ptr<Message>>
113 processVector(std::unique_ptr<Message> message) override;
114 };
115
120 class HELICS_CXX_EXPORT FirewallOperator: public FilterOperator {
121 public:
123 enum class operations : int {
124 none = -1,
125 drop = 0,
126 pass = 1,
127 set_flag1 = 2,
128 set_flag2 = 3,
129 set_flag3 = 4
130 };
132 FirewallOperator() = default;
134 explicit FirewallOperator(std::function<bool(const Message*)> userCheckFunction);
136 void setCheckFunction(std::function<bool(const Message*)> userCheckFunction);
138 void setOperation(operations newop) { operation.store(newop); }
139
140 private:
141 std::function<bool(const Message*)>
142 checkFunction;
143 std::atomic<operations> operation{
144 operations::drop};
145 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
146 };
147
149 class HELICS_CXX_EXPORT CustomMessageOperator: public FilterOperator {
150 public:
152 CustomMessageOperator() = default;
154 explicit CustomMessageOperator(
155 std::function<std::unique_ptr<Message>(std::unique_ptr<Message>)> userMessageFunction);
157 void setMessageFunction(
158 std::function<std::unique_ptr<Message>(std::unique_ptr<Message>)> userMessageFunction);
159
160 private:
161 std::function<std::unique_ptr<Message>(std::unique_ptr<Message>)>
162 messageFunction;
163 virtual std::unique_ptr<Message> process(std::unique_ptr<Message> message) override;
164 };
165 } // namespace helics
helics::CloneOperator
Definition: MessageOperators.hpp:96
helics::CloneOperator::isMessageGenerating
virtual bool isMessageGenerating() const override
Definition: MessageOperators.hpp:106
helics::CloneOperator::CloneOperator
CloneOperator()=default
helics::CustomMessageOperator
Definition: MessageOperators.hpp:149
helics::CustomMessageOperator::CustomMessageOperator
CustomMessageOperator()=default
helics::FilterOperator
Definition: core-data.hpp:85
helics::FirewallOperator
Definition: MessageOperators.hpp:120
helics::FirewallOperator::operations
operations
Definition: MessageOperators.hpp:123
helics::FirewallOperator::setOperation
void setOperation(operations newop)
Definition: MessageOperators.hpp:138
helics::FirewallOperator::FirewallOperator
FirewallOperator()=default
helics::MessageConditionalOperator
Definition: MessageOperators.hpp:76
helics::MessageConditionalOperator::MessageConditionalOperator
MessageConditionalOperator()=default
helics::MessageDataOperator
Definition: MessageOperators.hpp:58
helics::MessageDataOperator::MessageDataOperator
MessageDataOperator()=default
helics::MessageDestOperator
Definition: MessageOperators.hpp:39
helics::MessageDestOperator::MessageDestOperator
MessageDestOperator()=default
helics::MessageDestOperator::isMessageGenerating
virtual bool isMessageGenerating() const override
Definition: MessageOperators.hpp:49
helics::MessageTimeOperator
Definition: MessageOperators.hpp:24
helics::MessageTimeOperator::MessageTimeOperator
MessageTimeOperator()=default
helics::Message
Definition: core-data.hpp:29
helics::SmallBuffer
Definition: SmallBuffer.hpp:25
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27