| helics 3.6.1

Filter.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 #ifndef HELICS_CPP98_FILTER_HPP_
8 #define HELICS_CPP98_FILTER_HPP_
9 #pragma once
10
11 #include "helics/helics.h"
12 #include "helicsExceptions.hpp"
13
14 #include <string>
15
16 namespace helicscpp {
18 class Filter {
19 public:
21 explicit Filter(HelicsFilter hfilt) HELICS_NOTHROW: filt(hfilt) {}
23 Filter() HELICS_NOTHROW: filt(HELICS_NULL_POINTER) {}
25 Filter(const Filter& filter): filt(filter.filt) {}
27 Filter& operator=(const Filter& filter)
28 {
29 filt = filter.filt;
30 return *this;
31 }
32
34 operator HelicsFilter() const { return filt; }
36 HelicsFilter baseObject() const { return filt; }
38 bool isValid() const { return (helicsFilterIsValid(filt) == HELICS_TRUE); }
40 const char* getName() const { return helicsFilterGetName(filt); }
45 void set(const std::string& property, double val)
46 {
47 helicsFilterSet(filt, property.c_str(), val, hThrowOnError());
48 }
53 void setString(const std::string& property, const std::string& val)
54 {
55 helicsFilterSetString(filt, property.c_str(), val.c_str(), hThrowOnError());
56 }
60 double getProperty(const std::string& property)
61 {
62 return helicsFilterGetPropertyDouble(filt, property.c_str());
63 }
67 const char* getString(const std::string& property)
68 {
69 return helicsFilterGetPropertyString(filt, property.c_str());
70 }
71
74 void addDestinationTarget(const std::string& dest)
75 {
76 helicsFilterAddDestinationTarget(filt, dest.c_str(), hThrowOnError());
77 }
78
81 void addSourceTarget(const std::string& source)
82 {
83 helicsFilterAddSourceTarget(filt, source.c_str(), hThrowOnError());
84 }
85
87 void removeTarget(const std::string& dest)
88 {
89 helicsFilterRemoveTarget(filt, dest.c_str(), hThrowOnError());
90 }
92 const char* getInfo() const { return helicsFilterGetInfo(filt); }
94 void setInfo(const std::string& info)
95 {
96 helicsFilterSetInfo(filt, info.c_str(), HELICS_IGNORE_ERROR);
97 }
99 const char* getTag(const std::string& tagname) const
100 {
101 return helicsFilterGetTag(filt, tagname.c_str());
102 }
104 void setTag(const std::string& tagname, const std::string& tagvalue)
105 {
106 helicsFilterSetTag(filt, tagname.c_str(), tagvalue.c_str(), HELICS_IGNORE_ERROR);
107 }
108 void setOption(int32_t option, int32_t value = 1)
109 {
110 helicsFilterSetOption(filt, option, value, HELICS_IGNORE_ERROR);
111 }
112 int32_t getOption(int32_t option) { return helicsFilterGetOption(filt, option); }
113
114 void setCallback(HelicsMessage (*filtCall)(HelicsMessage message, void* userData),
115 void* userData)
116 {
117 helicsFilterSetCustomCallback(filt, filtCall, userData, HELICS_IGNORE_ERROR);
118 }
119
120 protected:
121 HelicsFilter filt;
122 };
123
126 class CloningFilter: public Filter {
127 public:
129 explicit CloningFilter(HelicsFilter hfilt) HELICS_NOTHROW: Filter(hfilt) {}
131 CloningFilter() HELICS_NOTHROW {};
133 CloningFilter(const CloningFilter& filter): Filter(filter) {}
135 CloningFilter& operator=(const CloningFilter& filter)
136 {
137 Filter::operator=(filter);
138 return *this;
139 }
140
144 void addDeliveryEndpoint(const std::string& deliveryEndpoint)
145 {
146 helicsFilterAddDeliveryEndpoint(filt, deliveryEndpoint.c_str(), hThrowOnError());
147 }
148
150 void removeDeliveryEndpoint(const std::string& deliveryEndpoint)
151 {
152 helicsFilterRemoveDeliveryEndpoint(filt, deliveryEndpoint.c_str(), hThrowOnError());
153 }
154 };
155
156 } // namespace helicscpp
157 #endif
helicsFilterGetPropertyDouble
double helicsFilterGetPropertyDouble(HelicsFilter filt, const char *prop)
Definition: MessageFiltersExport.cpp:361
helicsFilterSetString
void helicsFilterSetString(HelicsFilter filt, const char *prop, const char *val, HelicsError *err)
Definition: MessageFiltersExport.cpp:346
helicsFilterGetName
const char * helicsFilterGetName(HelicsFilter filt)
Definition: MessageFiltersExport.cpp:321
helicsFilterAddSourceTarget
void helicsFilterAddSourceTarget(HelicsFilter filt, const char *source, HelicsError *err)
Definition: MessageFiltersExport.cpp:412
helicsFilterGetPropertyString
const char * helicsFilterGetPropertyString(HelicsFilter filt, const char *prop)
Definition: MessageFiltersExport.cpp:375
helicsFilterAddDestinationTarget
void helicsFilterAddDestinationTarget(HelicsFilter filt, const char *dst, HelicsError *err)
Definition: MessageFiltersExport.cpp:395
helicsFilterIsValid
HelicsBool helicsFilterIsValid(HelicsFilter filt)
Definition: MessageFiltersExport.cpp:311
helicsFilterSet
void helicsFilterSet(HelicsFilter filt, const char *prop, double val, HelicsError *err)
Definition: MessageFiltersExport.cpp:331
HelicsFilter
void * HelicsFilter
Definition: api-data.h:43
HelicsMessage
void * HelicsMessage
Definition: api-data.h:100
HELICS_TRUE
const HelicsBool HELICS_TRUE
Definition: api-data.h:120
helicscpp::CloningFilter
Definition: Filter.hpp:126
helicscpp::CloningFilter::CloningFilter
CloningFilter() HELICS_NOTHROW
Definition: Filter.hpp:131
helicscpp::CloningFilter::CloningFilter
CloningFilter(HelicsFilter hfilt) HELICS_NOTHROW
Definition: Filter.hpp:129
helicscpp::CloningFilter::addDeliveryEndpoint
void addDeliveryEndpoint(const std::string &deliveryEndpoint)
Definition: Filter.hpp:144
helicscpp::CloningFilter::operator=
CloningFilter & operator=(const CloningFilter &filter)
Definition: Filter.hpp:135
helicscpp::CloningFilter::removeDeliveryEndpoint
void removeDeliveryEndpoint(const std::string &deliveryEndpoint)
Definition: Filter.hpp:150
helicscpp::CloningFilter::CloningFilter
CloningFilter(const CloningFilter &filter)
Definition: Filter.hpp:133
helicscpp::Filter
Definition: Filter.hpp:18
helicscpp::Filter::addDestinationTarget
void addDestinationTarget(const std::string &dest)
Definition: Filter.hpp:74
helicscpp::Filter::baseObject
HelicsFilter baseObject() const
Definition: Filter.hpp:36
helicscpp::Filter::Filter
Filter(HelicsFilter hfilt) HELICS_NOTHROW
Definition: Filter.hpp:21
helicscpp::Filter::getProperty
double getProperty(const std::string &property)
Definition: Filter.hpp:60
helicscpp::Filter::addSourceTarget
void addSourceTarget(const std::string &source)
Definition: Filter.hpp:81
helicscpp::Filter::getString
const char * getString(const std::string &property)
Definition: Filter.hpp:67
helicscpp::Filter::getTag
const char * getTag(const std::string &tagname) const
Definition: Filter.hpp:99
helicscpp::Filter::setTag
void setTag(const std::string &tagname, const std::string &tagvalue)
Definition: Filter.hpp:104
helicscpp::Filter::Filter
Filter(const Filter &filter)
Definition: Filter.hpp:25
helicscpp::Filter::setString
void setString(const std::string &property, const std::string &val)
Definition: Filter.hpp:53
helicscpp::Filter::removeTarget
void removeTarget(const std::string &dest)
Definition: Filter.hpp:87
helicscpp::Filter::Filter
Filter() HELICS_NOTHROW
Definition: Filter.hpp:23
helicscpp::Filter::getName
const char * getName() const
Definition: Filter.hpp:40
helicscpp::Filter::set
void set(const std::string &property, double val)
Definition: Filter.hpp:45
helicscpp::Filter::getInfo
const char * getInfo() const
Definition: Filter.hpp:92
helicscpp::Filter::operator=
Filter & operator=(const Filter &filter)
Definition: Filter.hpp:27
helicscpp::Filter::isValid
bool isValid() const
Definition: Filter.hpp:38
helicscpp::Filter::setInfo
void setInfo(const std::string &info)
Definition: Filter.hpp:94
helicscpp::Filter::filt
HelicsFilter filt
the reference to the underlying publication
Definition: Filter.hpp:121
helicscpp::hThrowOnError
Definition: helicsExceptions.hpp:38
helicsFilterAddDeliveryEndpoint
void helicsFilterAddDeliveryEndpoint(HelicsFilter filt, const char *deliveryEndpoint, HelicsError *err)
Definition: MessageFiltersExport.cpp:429
helicsFilterRemoveTarget
void helicsFilterRemoveTarget(HelicsFilter filt, const char *target, HelicsError *err)
Definition: MessageFiltersExport.cpp:446
helicsFilterGetInfo
const char * helicsFilterGetInfo(HelicsFilter filt)
Definition: MessageFiltersExport.cpp:480
helicsFilterSetTag
void helicsFilterSetTag(HelicsFilter filt, const char *tagname, const char *tagvalue, HelicsError *err)
Definition: MessageFiltersExport.cpp:530
helicsFilterGetOption
int helicsFilterGetOption(HelicsFilter filt, int option)
Definition: MessageFiltersExport.cpp:562
helicsFilterRemoveDeliveryEndpoint
void helicsFilterRemoveDeliveryEndpoint(HelicsFilter filt, const char *deliveryEndpoint, HelicsError *err)
Definition: MessageFiltersExport.cpp:463
helicsFilterSetOption
void helicsFilterSetOption(HelicsFilter filt, int option, int value, HelicsError *err)
Definition: MessageFiltersExport.cpp:546
helicsFilterGetTag
const char * helicsFilterGetTag(HelicsFilter filt, const char *tagname)
Definition: MessageFiltersExport.cpp:513
helicsFilterSetInfo
void helicsFilterSetInfo(HelicsFilter filt, const char *info, HelicsError *err)
Definition: MessageFiltersExport.cpp:497
helicsFilterSetCustomCallback
void helicsFilterSetCustomCallback(HelicsFilter filter, HelicsMessage(*filtCall)(HelicsMessage message, void *userData), void *userdata, HelicsError *err)
Definition: MessageFiltersExport.cpp:578
helicscpp
Definition: cpp98/Broker.hpp:18