| helics 3.6.1

FilterOperations.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
13 #include "../common/GuardedTypes.hpp"
14 #include "../core/helicsTime.hpp"
15 #include "gmlc/libguarded/cow_guarded.hpp"
16
17 #include <atomic>
18 #include <memory>
19 #include <set>
20 #include <string>
21 #include <string_view>
22 #include <vector>
23
24 namespace helics {
25 class Core;
26 class FilterOperator;
27 class MessageTimeOperator;
28 class Message;
29 class MessageConditionalOperator;
30 class MessageDestOperator;
31 class CloneOperator;
32 class FirewallOperator;
34 class FilterOperations {
35 public:
36 FilterOperations() = default;
37 virtual ~FilterOperations() = default;
38 // still figuring out if these functions have a use or not
39 FilterOperations(const FilterOperations& fo) = delete;
40 FilterOperations(FilterOperations&& fo) = delete;
41 FilterOperations& operator=(const FilterOperations& fo) = delete;
42 FilterOperations& operator=(FilterOperations&& fo) = delete;
43
48 virtual void set(std::string_view property, double val);
53 virtual void setString(std::string_view property, std::string_view val);
54
58 virtual double getProperty(std::string_view property);
62 virtual std::string getString(std::string_view property);
63
65 virtual std::shared_ptr<FilterOperator> getOperator() = 0;
66 };
67
69 class DelayFilterOperation: public FilterOperations {
70 private:
71 std::atomic<Time> delay{timeZero};
72 std::shared_ptr<MessageTimeOperator> td;
73
74 public:
75 explicit DelayFilterOperation(Time delayTime = timeZero);
76 virtual void set(std::string_view property, double val) override;
77 virtual void setString(std::string_view property, std::string_view val) override;
78 virtual double getProperty(std::string_view property) override;
79 virtual std::string getString(std::string_view property) override;
80 virtual std::shared_ptr<FilterOperator> getOperator() override;
81 };
82
83 class RandomDelayGenerator;
84
86 class RandomDelayFilterOperation: public FilterOperations {
87 private:
88 std::shared_ptr<MessageTimeOperator> td;
89 std::unique_ptr<RandomDelayGenerator> rdelayGen;
90
91 public:
93 RandomDelayFilterOperation();
94 // the destructor is defined mainly to prevent the need to define the RandomDelayGenerator
95 // object here
97 ~RandomDelayFilterOperation();
98 virtual void set(std::string_view property, double val) override;
99 virtual void setString(std::string_view property, std::string_view val) override;
100 virtual double getProperty(std::string_view property) override;
101 virtual std::string getString(std::string_view property) override;
102 virtual std::shared_ptr<FilterOperator> getOperator() override;
103 };
104
106 class RandomDropFilterOperation: public FilterOperations {
107 private:
108 std::atomic<double> dropProb{0.0};
109 std::shared_ptr<MessageConditionalOperator> tcond;
110
111 public:
112 RandomDropFilterOperation();
113 ~RandomDropFilterOperation();
114 virtual void set(std::string_view property, double val) override;
115 virtual void setString(std::string_view property, std::string_view val) override;
116 virtual double getProperty(std::string_view property) override;
117 virtual std::string getString(std::string_view property) override;
118 virtual std::shared_ptr<FilterOperator> getOperator() override;
119 };
120
122 class RerouteFilterOperation: public FilterOperations {
123 private:
124 std::shared_ptr<MessageDestOperator> op;
125 atomic_guarded<std::string> newDest;
126 shared_guarded<std::set<std::string>>
127 conditions;
128
129 public:
130 RerouteFilterOperation();
131 ~RerouteFilterOperation();
132 virtual void set(std::string_view property, double val) override;
133 virtual void setString(std::string_view property, std::string_view val) override;
134 virtual double getProperty(std::string_view property) override;
135 virtual std::string getString(std::string_view property) override;
136 virtual std::shared_ptr<FilterOperator> getOperator() override;
137
138 private:
140 std::string rerouteOperation(const std::string& src, const std::string& dest) const;
141 };
142
144 class FirewallFilterOperation: public FilterOperations {
145 private:
146 std::shared_ptr<FirewallOperator> op;
148 gmlc::libguarded::cow_guarded<std::vector<std::string>> allowed;
150 gmlc::libguarded::cow_guarded<std::vector<std::string>> blocked;
151
152 public:
153 FirewallFilterOperation();
154 ~FirewallFilterOperation();
155 virtual void set(std::string_view property, double val) override;
156 virtual void setString(std::string_view property, std::string_view val) override;
157 virtual double getProperty(std::string_view property) override;
158 virtual std::string getString(std::string_view property) override;
159 virtual std::shared_ptr<FilterOperator> getOperator() override;
160
161 private:
163 bool allowPassed(const Message* mess) const;
164 };
165
167 class CloneFilterOperation: public FilterOperations {
168 private:
169 std::shared_ptr<CloneOperator> op;
171 shared_guarded<std::vector<std::string>> deliveryAddresses;
172
173 public:
174 explicit CloneFilterOperation();
175
176 ~CloneFilterOperation();
177 virtual void set(std::string_view property, double val) override;
178 virtual void setString(std::string_view property, std::string_view val) override;
179 virtual double getProperty(std::string_view property) override;
180 virtual std::string getString(std::string_view property) override;
181 virtual std::shared_ptr<FilterOperator> getOperator() override;
182
183 private:
186 std::vector<std::unique_ptr<Message>> sendMessage(const Message* mess) const;
187 };
188
189 } // namespace helics
gmlc::libguarded::shared_guarded
Definition: application_api/Federate.hpp:27
helics::CloneFilterOperation
Definition: FilterOperations.hpp:167
helics::CloneFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:506
helics::CloneFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:473
helics::CloneFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:467
helics::CloneFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:501
helics::CloneFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:530
helics::DelayFilterOperation
Definition: FilterOperations.hpp:69
helics::DelayFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:69
helics::DelayFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:77
helics::DelayFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:85
helics::DelayFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:48
helics::DelayFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:57
helics::FilterOperations
Definition: FilterOperations.hpp:34
helics::FilterOperations::setString
virtual void setString(std::string_view property, std::string_view val)
Definition: FilterOperations.cpp:28
helics::FilterOperations::set
virtual void set(std::string_view property, double val)
Definition: FilterOperations.cpp:27
helics::FilterOperations::getOperator
virtual std::shared_ptr< FilterOperator > getOperator()=0
helics::FilterOperations::getString
virtual std::string getString(std::string_view property)
Definition: FilterOperations.cpp:34
helics::FilterOperations::getProperty
virtual double getProperty(std::string_view property)
Definition: FilterOperations.cpp:30
helics::FirewallFilterOperation
Definition: FilterOperations.hpp:144
helics::FirewallFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:436
helics::FirewallFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:443
helics::FirewallFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:438
helics::FirewallFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:434
helics::FirewallFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:448
helics::Message
Definition: core-data.hpp:29
helics::RandomDelayFilterOperation
Definition: FilterOperations.hpp:86
helics::RandomDelayFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:224
helics::RandomDelayFilterOperation::~RandomDelayFilterOperation
~RandomDelayFilterOperation()
helics::RandomDelayFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:284
helics::RandomDelayFilterOperation::RandomDelayFilterOperation
RandomDelayFilterOperation()
Definition: FilterOperations.cpp:216
helics::RandomDelayFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:234
helics::RandomDelayFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:252
helics::RandomDelayFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:265
helics::RandomDropFilterOperation
Definition: FilterOperations.hpp:106
helics::RandomDropFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:303
helics::RandomDropFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:315
helics::RandomDropFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:307
helics::RandomDropFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:297
helics::RandomDropFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:323
helics::RerouteFilterOperation
Definition: FilterOperations.hpp:122
helics::RerouteFilterOperation::getProperty
virtual double getProperty(std::string_view property) override
Definition: FilterOperations.cpp:360
helics::RerouteFilterOperation::getString
virtual std::string getString(std::string_view property) override
Definition: FilterOperations.cpp:365
helics::RerouteFilterOperation::getOperator
virtual std::shared_ptr< FilterOperator > getOperator() override
Definition: FilterOperations.cpp:392
helics::RerouteFilterOperation::set
virtual void set(std::string_view property, double val) override
Definition: FilterOperations.cpp:338
helics::RerouteFilterOperation::setString
virtual void setString(std::string_view property, std::string_view val) override
Definition: FilterOperations.cpp:340
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27