| helics 3.6.1

Publication.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_PUBLICATION_HPP_
8 #define HELICS_CPP98_PUBLICATION_HPP_
9 #pragma once
10
11 #include "DataBuffer.hpp"
12 #include "helics/helics.h"
13 #include "helicsExceptions.hpp"
14
15 #include <string>
16 #include <vector>
17
18 namespace helicscpp {
20 class Publication {
21 public:
23 explicit Publication(HelicsPublication hpub) HELICS_NOTHROW: pub(hpub) {}
25 Publication() HELICS_NOTHROW: pub(HELICS_NULL_POINTER) {}
27 Publication(const Publication& publication): pub(publication.pub) {}
29 Publication& operator=(const Publication& publication)
30 {
31 pub = publication.pub;
32 return *this;
33 }
34 // there is no need for move operators since copying the underlying object is fine, it is a
35 // non-owning pointer
37 operator HelicsPublication() const { return pub; }
39 HelicsPublication baseObject() const { return pub; }
40
42 bool isValid() const { return (helicsPublicationIsValid(pub) == HELICS_TRUE); }
43
47 void publish(const char* data, int len)
48 {
49 // returns helics_status
50 helicsPublicationPublishBytes(pub, data, len, HELICS_IGNORE_ERROR);
51 }
53 void publish(const char* str) { helicsPublicationPublishString(pub, str, HELICS_IGNORE_ERROR); }
55 void publish(const std::string& str)
56 {
57 helicsPublicationPublishString(pub, str.c_str(), HELICS_IGNORE_ERROR);
58 }
59
61 void publish(int64_t val)
62 {
63 // returns helics_status
64 helicsPublicationPublishInteger(pub, val, HELICS_IGNORE_ERROR);
65 }
67 void publish(double val) { helicsPublicationPublishDouble(pub, val, HELICS_IGNORE_ERROR); }
68
70 void publish(std::complex<double> cmplx)
71 {
72 helicsPublicationPublishComplex(pub, cmplx.real(), cmplx.imag(), HELICS_IGNORE_ERROR);
73 }
75 void publish(const std::vector<double>& data)
76 {
77 helicsPublicationPublishVector(pub,
78 data.data(),
79 static_cast<int>(data.size()),
80 HELICS_IGNORE_ERROR);
81 }
83 void publish(const double* data, int length)
84 {
85 helicsPublicationPublishVector(pub, data, length, HELICS_IGNORE_ERROR);
86 }
87
88 #if defined(__GNUC__)
89 # pragma GCC diagnostic push
90 # pragma GCC diagnostic ignored "-Wstrict-aliasing"
91 // std::complex is explicitly allowed to alias like this in the standard
92 #endif
94 void publish(const std::vector<std::complex<double> >& data)
95 {
96 helicsPublicationPublishComplexVector(pub,
97 reinterpret_cast<const double*>(data.data()),
98 static_cast<int>(data.size()),
99 HELICS_IGNORE_ERROR);
100 }
101 #if defined(__GNUC__)
102 # pragma GCC diagnostic pop
103 #endif
104
107 void publishComplex(const double* data, int length)
108 {
109 helicsPublicationPublishComplexVector(pub, data, length, HELICS_IGNORE_ERROR);
110 }
112 void publish(const std::string& name, double val)
113 {
114 helicsPublicationPublishNamedPoint(pub, name.c_str(), val, HELICS_IGNORE_ERROR);
115 }
117 void publish(bool val)
118 {
119 helicsPublicationPublishBoolean(pub, val ? HELICS_TRUE : HELICS_FALSE, HELICS_IGNORE_ERROR);
120 }
122 void publish(DataBuffer& buffer)
123 {
124 helicsPublicationPublishDataBuffer(pub, buffer.getHelicsDataBuffer(), hThrowOnError());
125 }
127 const char* getName() const { return helicsPublicationGetName(pub); }
129 const char* getUnits() const { return helicsPublicationGetUnits(pub); }
131 const char* getType() const { return helicsPublicationGetType(pub); }
133 const char* getInfo() const { return helicsPublicationGetInfo(pub); }
134
136 void setInfo(const std::string& info)
137 {
138 helicsPublicationSetInfo(pub, info.c_str(), HELICS_IGNORE_ERROR);
139 }
141 const char* getTag(const std::string& tagname) const
142 {
143 return helicsPublicationGetTag(pub, tagname.c_str());
144 }
146 void setTag(const std::string& tagname, const std::string& tagvalue)
147 {
148 helicsPublicationSetTag(pub, tagname.c_str(), tagvalue.c_str(), HELICS_IGNORE_ERROR);
149 }
150 void setOption(int32_t option, int32_t value = 1)
151 {
152 helicsPublicationSetOption(pub, option, value, HELICS_IGNORE_ERROR);
153 }
154 int32_t getOption(int32_t option) { return helicsPublicationGetOption(pub, option); }
155
156 private:
157 HelicsPublication pub;
158 };
159
160 } // namespace helicscpp
161 #endif
HelicsPublication
void * HelicsPublication
Definition: api-data.h:31
HELICS_FALSE
const HelicsBool HELICS_FALSE
Definition: api-data.h:121
HELICS_TRUE
const HelicsBool HELICS_TRUE
Definition: api-data.h:120
helicscpp::DataBuffer
Definition: DataBuffer.hpp:18
helicscpp::DataBuffer::getHelicsDataBuffer
HelicsDataBuffer getHelicsDataBuffer()
Definition: DataBuffer.hpp:165
helicscpp::Publication
Definition: Publication.hpp:20
helicscpp::Publication::publish
void publish(const char *str)
Definition: Publication.hpp:53
helicscpp::Publication::setInfo
void setInfo(const std::string &info)
Definition: Publication.hpp:136
helicscpp::Publication::setTag
void setTag(const std::string &tagname, const std::string &tagvalue)
Definition: Publication.hpp:146
helicscpp::Publication::Publication
Publication() HELICS_NOTHROW
Definition: Publication.hpp:25
helicscpp::Publication::publish
void publish(std::complex< double > cmplx)
Definition: Publication.hpp:70
helicscpp::Publication::operator=
Publication & operator=(const Publication &publication)
Definition: Publication.hpp:29
helicscpp::Publication::publish
void publish(const char *data, int len)
Definition: Publication.hpp:47
helicscpp::Publication::publishComplex
void publishComplex(const double *data, int length)
Definition: Publication.hpp:107
helicscpp::Publication::Publication
Publication(const Publication &publication)
Definition: Publication.hpp:27
helicscpp::Publication::getType
const char * getType() const
Definition: Publication.hpp:131
helicscpp::Publication::publish
void publish(int64_t val)
Definition: Publication.hpp:61
helicscpp::Publication::publish
void publish(const double *data, int length)
Definition: Publication.hpp:83
helicscpp::Publication::publish
void publish(bool val)
Definition: Publication.hpp:117
helicscpp::Publication::publish
void publish(double val)
Definition: Publication.hpp:67
helicscpp::Publication::isValid
bool isValid() const
Definition: Publication.hpp:42
helicscpp::Publication::publish
void publish(DataBuffer &buffer)
Definition: Publication.hpp:122
helicscpp::Publication::getUnits
const char * getUnits() const
Definition: Publication.hpp:129
helicscpp::Publication::getTag
const char * getTag(const std::string &tagname) const
Definition: Publication.hpp:141
helicscpp::Publication::getName
const char * getName() const
Definition: Publication.hpp:127
helicscpp::Publication::getInfo
const char * getInfo() const
Definition: Publication.hpp:133
helicscpp::Publication::publish
void publish(const std::string &str)
Definition: Publication.hpp:55
helicscpp::Publication::publish
void publish(const std::string &name, double val)
Definition: Publication.hpp:112
helicscpp::Publication::baseObject
HelicsPublication baseObject() const
Definition: Publication.hpp:39
helicscpp::Publication::publish
void publish(const std::vector< double > &data)
Definition: Publication.hpp:75
helicscpp::Publication::publish
void publish(const std::vector< std::complex< double > > &data)
Definition: Publication.hpp:94
helicscpp::Publication::Publication
Publication(HelicsPublication hpub) HELICS_NOTHROW
Definition: Publication.hpp:23
helicscpp::hThrowOnError
Definition: helicsExceptions.hpp:38
helicsPublicationSetInfo
void helicsPublicationSetInfo(HelicsPublication pub, const char *info, HelicsError *err)
Definition: ValueFederateExport.cpp:1462
helicsPublicationSetOption
void helicsPublicationSetOption(HelicsPublication pub, int option, int val, HelicsError *err)
Definition: ValueFederateExport.cpp:1592
helicsPublicationGetOption
int helicsPublicationGetOption(HelicsPublication pub, int option)
Definition: ValueFederateExport.cpp:1576
helicsPublicationGetTag
const char * helicsPublicationGetTag(HelicsPublication pub, const char *tagname)
Definition: ValueFederateExport.cpp:1511
helicsPublicationGetName
const char * helicsPublicationGetName(HelicsPublication pub)
Definition: ValueFederateExport.cpp:1346
helicsPublicationGetInfo
const char * helicsPublicationGetInfo(HelicsPublication pub)
Definition: ValueFederateExport.cpp:1445
helicsPublicationGetType
const char * helicsPublicationGetType(HelicsPublication pub)
Definition: ValueFederateExport.cpp:1287
helicsPublicationSetTag
void helicsPublicationSetTag(HelicsPublication pub, const char *tagname, const char *tagvalue, HelicsError *err)
Definition: ValueFederateExport.cpp:1528
helicsPublicationGetUnits
const char * helicsPublicationGetUnits(HelicsPublication pub)
Definition: ValueFederateExport.cpp:1402
helicsPublicationPublishNamedPoint
void helicsPublicationPublishNamedPoint(HelicsPublication pub, const char *field, double val, HelicsError *err)
Definition: ValueFederateExport.cpp:671
helicsPublicationPublishString
void helicsPublicationPublishString(HelicsPublication pub, const char *val, HelicsError *err)
Definition: ValueFederateExport.cpp:536
helicsPublicationPublishVector
void helicsPublicationPublishVector(HelicsPublication pub, const double *vectorInput, int vectorLength, HelicsError *err)
Definition: ValueFederateExport.cpp:635
helicsPublicationPublishDouble
void helicsPublicationPublishDouble(HelicsPublication pub, double val, HelicsError *err)
Definition: ValueFederateExport.cpp:578
helicsPublicationPublishComplex
void helicsPublicationPublishComplex(HelicsPublication pub, double real, double imag, HelicsError *err)
Definition: ValueFederateExport.cpp:621
helicsPublicationPublishBoolean
void helicsPublicationPublishBoolean(HelicsPublication pub, HelicsBool val, HelicsError *err)
Definition: ValueFederateExport.cpp:564
helicsPublicationIsValid
HelicsBool helicsPublicationIsValid(HelicsPublication pub)
Definition: ValueFederateExport.cpp:721
helicsPublicationPublishDataBuffer
void helicsPublicationPublishDataBuffer(HelicsPublication pub, HelicsDataBuffer buffer, HelicsError *err)
Definition: ValueFederateExport.cpp:689
helicsPublicationPublishInteger
void helicsPublicationPublishInteger(HelicsPublication pub, int64_t val, HelicsError *err)
Definition: ValueFederateExport.cpp:550
helicsPublicationPublishComplexVector
void helicsPublicationPublishComplexVector(HelicsPublication pub, const double *vectorInput, int vectorLength, HelicsError *err)
Definition: ValueFederateExport.cpp:653
helicsPublicationPublishBytes
void helicsPublicationPublishBytes(HelicsPublication pub, const void *data, int inputDataLength, HelicsError *err)
Definition: ValueFederateExport.cpp:522
helicscpp
Definition: cpp98/Broker.hpp:18