| helics 3.6.1

Filters.hpp
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.hpp"
10 #include "Federate.hpp"
11 #include "helics/helics_enums.h"
12
13 #include <memory>
14 #include <string>
15
16 namespace helics {
17 class FilterOperations;
18 class FilterOperator;
19 class CoreApp;
21 enum class FilterTypes {
22 CUSTOM = HELICS_FILTER_TYPE_CUSTOM,
23 DELAY = HELICS_FILTER_TYPE_DELAY,
24 RANDOM_DELAY = HELICS_FILTER_TYPE_RANDOM_DELAY,
25 RANDOM_DROP = HELICS_FILTER_TYPE_RANDOM_DROP,
26 REROUTE = HELICS_FILTER_TYPE_REROUTE,
27 CLONE = HELICS_FILTER_TYPE_CLONE,
28 FIREWALL = HELICS_FILTER_TYPE_FIREWALL,
29 UNRECOGNIZED = 7
30
31 };
32
33 #define EMPTY_STRING std::string_view()
34
36 HELICS_CXX_EXPORT FilterTypes filterTypeFromString(std::string_view filterType) noexcept;
37
39 class HELICS_CXX_EXPORT Filter: public Interface {
40 protected:
41 bool cloning = false;
42 bool disableAssign = false;
43 private:
44 std::shared_ptr<FilterOperations>
45 filtOp;
46 public:
48 Filter() = default;
50 explicit Filter(Federate* ffed, std::string_view filtName = EMPTY_STRING);
52 Filter(Federate* ffed, std::string_view filtName, InterfaceHandle ihandle);
54 Filter(Core* core, std::string_view filtName, InterfaceHandle ihandle);
56 Filter(InterfaceVisibility locality, Federate* ffed, std::string_view filtName = EMPTY_STRING);
58 explicit Filter(Core* core, std::string_view filtName = EMPTY_STRING);
60 virtual ~Filter() = default;
61
62 Filter(Filter&& filt) = default;
64 Filter(const Filter& filt) = default;
65 Filter& operator=(Filter&& filt) = default;
67 Filter& operator=(const Filter& filt) = default;
69 bool isCloningFilter() const { return cloning; }
71 void setOperator(std::shared_ptr<FilterOperator> filterOp);
72
73 virtual const std::string& getDisplayName() const override { return getName(); }
74
79 virtual void set(std::string_view property, double val);
80
85 virtual void setString(std::string_view property, std::string_view val);
86
90 virtual std::string getString(std::string_view property);
91
95 virtual double getProperty(std::string_view property);
96
98 void addTarget(std::string_view target) { addSourceTarget(target); }
99
101 void setFilterType(std::int32_t type);
102
103 protected:
105 void setFilterOperations(std::shared_ptr<FilterOperations> filterOps);
107 friend void addOperations(Filter* filt, FilterTypes type, Core* cptr);
108 };
109
111 class HELICS_CXX_EXPORT CloningFilter: public Filter {
112 public:
114 CloningFilter() = default;
117 explicit CloningFilter(Core* core, std::string_view filtName = EMPTY_STRING);
120 explicit CloningFilter(Federate* ffed, std::string_view filtName = EMPTY_STRING);
123 CloningFilter(InterfaceVisibility locality,
124 Federate* ffed,
125 std::string_view filtName = EMPTY_STRING);
126
128 CloningFilter(Federate* ffed, std::string_view filtName, InterfaceHandle handle);
130 CloningFilter(CloningFilter&& filt) = default;
132 CloningFilter(const CloningFilter& filt) = default;
134 CloningFilter& operator=(CloningFilter&& filt) = default;
136 CloningFilter& operator=(const CloningFilter& filt) = default;
138 ~CloningFilter() = default;
140 void addDeliveryEndpoint(std::string_view endpoint);
141
143 void removeDeliveryEndpoint(std::string_view endpoint);
144
145 virtual void setString(std::string_view property, std::string_view val) override;
146
147 private:
148 friend class FilterFederateManager;
149 };
150
158 HELICS_CXX_EXPORT Filter&
159 make_filter(FilterTypes type, Federate* fed, std::string_view name = EMPTY_STRING);
160
169 HELICS_CXX_EXPORT Filter& make_filter(InterfaceVisibility locality,
170 FilterTypes type,
171 Federate* fed,
172 std::string_view name = EMPTY_STRING);
173
181 HELICS_CXX_EXPORT std::unique_ptr<Filter>
182 make_filter(FilterTypes type, Core* core, std::string_view name = EMPTY_STRING);
183
191 HELICS_CXX_EXPORT std::unique_ptr<Filter>
192 make_filter(FilterTypes type, CoreApp& core, std::string_view name = EMPTY_STRING);
193
202 HELICS_CXX_EXPORT CloningFilter& make_cloning_filter(FilterTypes type,
203 Federate* fed,
204 std::string_view delivery,
205 std::string_view name = EMPTY_STRING);
206
216 HELICS_CXX_EXPORT CloningFilter& make_cloning_filter(InterfaceVisibility locality,
217 FilterTypes type,
218 Federate* fed,
219 std::string_view delivery,
220 std::string_view name = EMPTY_STRING);
221
230 HELICS_CXX_EXPORT std::unique_ptr<CloningFilter>
231 make_cloning_filter(FilterTypes type,
232 Core* core,
233 std::string_view delivery,
234 std::string_view name = EMPTY_STRING);
235
244 HELICS_CXX_EXPORT std::unique_ptr<CloningFilter>
245 make_cloning_filter(FilterTypes type,
246 CoreApp& core,
247 std::string_view delivery,
248 std::string_view name = EMPTY_STRING);
249
250 } // namespace helics
helics::CloningFilter
Definition: Filters.hpp:111
helics::CloningFilter::operator=
CloningFilter & operator=(CloningFilter &&filt)=default
helics::CloningFilter::CloningFilter
CloningFilter()=default
helics::CloningFilter::CloningFilter
CloningFilter(const CloningFilter &filt)=default
helics::CloningFilter::CloningFilter
CloningFilter(CloningFilter &&filt)=default
helics::CloningFilter::operator=
CloningFilter & operator=(const CloningFilter &filt)=default
helics::CloningFilter::~CloningFilter
~CloningFilter()=default
helics::CoreApp
Definition: application_api/CoreApp.hpp:25
helics::Core
Definition: core/Core.hpp:41
helics::Federate
Definition: application_api/Federate.hpp:48
helics::Filter
Definition: Filters.hpp:39
helics::Filter::Filter
Filter(const Filter &filt)=default
helics::Filter::operator=
Filter & operator=(const Filter &filt)=default
helics::Filter::~Filter
virtual ~Filter()=default
helics::Filter::addTarget
void addTarget(std::string_view target)
Definition: Filters.hpp:98
helics::Filter::getDisplayName
virtual const std::string & getDisplayName() const override
Definition: Filters.hpp:73
helics::Filter::isCloningFilter
bool isCloningFilter() const
Definition: Filters.hpp:69
helics::Filter::Filter
Filter()=default
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::Interface
Definition: application_api/Federate.hpp:880
helics_enums.h
base helics enumerations for C and C++ API's
HELICS_FILTER_TYPE_FIREWALL
@ HELICS_FILTER_TYPE_FIREWALL
Definition: helics_enums.h:408
HELICS_FILTER_TYPE_RANDOM_DELAY
@ HELICS_FILTER_TYPE_RANDOM_DELAY
Definition: helics_enums.h:397
HELICS_FILTER_TYPE_REROUTE
@ HELICS_FILTER_TYPE_REROUTE
Definition: helics_enums.h:402
HELICS_FILTER_TYPE_CLONE
@ HELICS_FILTER_TYPE_CLONE
Definition: helics_enums.h:405
HELICS_FILTER_TYPE_CUSTOM
@ HELICS_FILTER_TYPE_CUSTOM
Definition: helics_enums.h:393
HELICS_FILTER_TYPE_RANDOM_DROP
@ HELICS_FILTER_TYPE_RANDOM_DROP
Definition: helics_enums.h:399
HELICS_FILTER_TYPE_DELAY
@ HELICS_FILTER_TYPE_DELAY
Definition: helics_enums.h:395
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::make_filter
Filter & make_filter(FilterTypes type, Federate *mFed, std::string_view name)
Definition: Filters.cpp:224
helics::addOperations
void addOperations(Filter *filt, FilterTypes type, Core *)
Definition: Filters.cpp:54
helics::make_cloning_filter
CloningFilter & make_cloning_filter(FilterTypes type, Federate *mFed, std::string_view delivery, std::string_view name)
Definition: Filters.cpp:274
helics::FilterTypes
FilterTypes
Definition: Filters.hpp:21
helics::filterTypeFromString
FilterTypes filterTypeFromString(std::string_view filterType) noexcept
Definition: Filters.cpp:34
helics::InterfaceVisibility
InterfaceVisibility
Definition: helicsTypes.hpp:40