| helics 3.6.1

cpp98/Core.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_CORE_HPP_
8 #define HELICS_CPP98_CORE_HPP_
9 #pragma once
10
11 #include "Filter.hpp"
12 #include "config.hpp"
13 #include "helics/helics.h"
14
15 #include <stdexcept>
16 #include <string>
17
18 namespace helicscpp {
19 class Core {
20 public:
22 Core() HELICS_NOTHROW: core(HELICS_NULL_POINTER) {}
24 Core(const std::string& type, const std::string& name, const std::string& initString)
25 {
26 core = helicsCreateCore(type.c_str(), name.c_str(), initString.c_str(), hThrowOnError());
27 }
29 Core(const std::string& type, const std::string& name, int argc, char** argv)
30 {
31 core = helicsCreateCoreFromArgs(type.c_str(), name.c_str(), argc, argv, hThrowOnError());
32 }
34 explicit Core(HelicsCore cr) HELICS_NOTHROW: core(cr) {}
35
37 ~Core() { helicsCoreFree(core); }
39 operator HelicsCore() { return core; }
41 HelicsCore baseObject() const { return core; }
43 bool isConnected() const { return (helicsCoreIsConnected(core) != HELICS_FALSE); }
45 Core(const Core& cr) { core = helicsCoreClone(cr.core, hThrowOnError()); }
47 Core& operator=(const Core& cr)
48 {
49 core = helicsCoreClone(cr.core, hThrowOnError());
50 return *this;
51 }
52 #ifdef HELICS_HAS_RVALUE_REFS
54 Core(Core&& cr) HELICS_NOTHROW: core(cr.core) { cr.core = HELICS_NULL_POINTER; }
56 Core& operator=(Core&& cr) HELICS_NOTHROW
57 {
58 core = cr.core;
59 cr.core = HELICS_NULL_POINTER;
60 return *this;
61 }
62 #endif
66 void setReadyToInit() { helicsCoreSetReadyToInit(core, hThrowOnError()); }
67
71 void disconnect() { helicsCoreDisconnect(core, hThrowOnError()); }
76 bool waitForDisconnect(int msToWait = -1)
77 {
78 return (helicsCoreWaitForDisconnect(core, msToWait, hThrowOnError()) != HELICS_FALSE);
79 }
82 const char* getIdentifier() const { return helicsCoreGetIdentifier(core); }
84 const char* getAddress() const { return helicsCoreGetAddress(core); }
93 Filter registerFilter(HelicsFilterTypes type, const std::string& name = std::string())
94 {
95 return Filter(helicsCoreRegisterFilter(core, type, name.c_str(), hThrowOnError()));
96 }
97
104 CloningFilter registerCloningFilter(const std::string& deliveryEndpoint)
105 {
106 return CloningFilter(
107 helicsCoreRegisterCloningFilter(core, deliveryEndpoint.c_str(), hThrowOnError()));
108 }
109
114 void setGlobal(const std::string& valueName, const std::string& value)
115 {
116 helicsCoreSetGlobal(core, valueName.c_str(), value.c_str(), hThrowOnError());
117 }
118
123 void addAlias(const std::string& interfaceName, const std::string& alias)
124 {
125 helicsCoreAddAlias(core, interfaceName.c_str(), alias.c_str(), hThrowOnError());
126 }
127
128 void globalError(int errorCode, const std::string& errorString)
129 {
130 helicsCoreGlobalError(core, errorCode, errorString.c_str(), HELICS_IGNORE_ERROR);
131 }
136 void sendCommand(const std::string& target, const std::string& command)
137 {
138 helicsCoreSendCommand(core, target.c_str(), command.c_str(), hThrowOnError());
139 }
140
154 std::string query(const std::string& target,
155 const std::string& queryStr,
156 HelicsSequencingModes mode = HELICS_SEQUENCING_MODE_FAST) const
157 {
158 // returns HelicsQuery
159 HelicsQuery q = helicsCreateQuery(target.c_str(), queryStr.c_str());
160 if (mode != HELICS_SEQUENCING_MODE_FAST) {
161 helicsQuerySetOrdering(q, mode, HELICS_IGNORE_ERROR);
162 }
163 std::string result(helicsQueryCoreExecute(q, core, hThrowOnError()));
164 helicsQueryFree(q);
165 return result;
166 }
167
168 protected:
169 HelicsCore core;
170 };
171
172 } // namespace helicscpp
173 #endif
helicsCoreRegisterCloningFilter
HelicsFilter helicsCoreRegisterCloningFilter(HelicsCore core, const char *name, HelicsError *err)
Definition: MessageFiltersExport.cpp:208
helicsCoreRegisterFilter
HelicsFilter helicsCoreRegisterFilter(HelicsCore core, HelicsFilterTypes type, const char *name, HelicsError *err)
Definition: MessageFiltersExport.cpp:147
HelicsCore
void * HelicsCore
Definition: api-data.h:54
HelicsQuery
void * HelicsQuery
Definition: api-data.h:83
HELICS_FALSE
const HelicsBool HELICS_FALSE
Definition: api-data.h:121
helicscpp::CloningFilter
Definition: Filter.hpp:126
helicscpp::Core
Definition: cpp98/Core.hpp:19
helicscpp::Core::operator=
Core & operator=(const Core &cr)
Definition: cpp98/Core.hpp:47
helicscpp::Core::disconnect
void disconnect()
Definition: cpp98/Core.hpp:71
helicscpp::Core::setGlobal
void setGlobal(const std::string &valueName, const std::string &value)
Definition: cpp98/Core.hpp:114
helicscpp::Core::Core
Core(const Core &cr)
Definition: cpp98/Core.hpp:45
helicscpp::Core::waitForDisconnect
bool waitForDisconnect(int msToWait=-1)
Definition: cpp98/Core.hpp:76
helicscpp::Core::addAlias
void addAlias(const std::string &interfaceName, const std::string &alias)
Definition: cpp98/Core.hpp:123
helicscpp::Core::getAddress
const char * getAddress() const
Definition: cpp98/Core.hpp:84
helicscpp::Core::Core
Core(HelicsCore cr) HELICS_NOTHROW
Definition: cpp98/Core.hpp:34
helicscpp::Core::Core
Core() HELICS_NOTHROW
Definition: cpp98/Core.hpp:22
helicscpp::Core::Core
Core(const std::string &type, const std::string &name, int argc, char **argv)
Definition: cpp98/Core.hpp:29
helicscpp::Core::~Core
~Core()
Definition: cpp98/Core.hpp:37
helicscpp::Core::isConnected
bool isConnected() const
Definition: cpp98/Core.hpp:43
helicscpp::Core::core
HelicsCore core
reference to the underlying core object
Definition: cpp98/Core.hpp:169
helicscpp::Core::setReadyToInit
void setReadyToInit()
Definition: cpp98/Core.hpp:66
helicscpp::Core::sendCommand
void sendCommand(const std::string &target, const std::string &command)
Definition: cpp98/Core.hpp:136
helicscpp::Core::registerFilter
Filter registerFilter(HelicsFilterTypes type, const std::string &name=std::string())
Definition: cpp98/Core.hpp:93
helicscpp::Core::baseObject
HelicsCore baseObject() const
Definition: cpp98/Core.hpp:41
helicscpp::Core::Core
Core(const std::string &type, const std::string &name, const std::string &initString)
Definition: cpp98/Core.hpp:24
helicscpp::Core::getIdentifier
const char * getIdentifier() const
Definition: cpp98/Core.hpp:82
helicscpp::Core::registerCloningFilter
CloningFilter registerCloningFilter(const std::string &deliveryEndpoint)
Definition: cpp98/Core.hpp:104
helicscpp::Core::query
std::string query(const std::string &target, const std::string &queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) const
Definition: cpp98/Core.hpp:154
helicscpp::Filter
Definition: Filter.hpp:18
helicscpp::hThrowOnError
Definition: helicsExceptions.hpp:38
helicsCoreSetGlobal
void helicsCoreSetGlobal(HelicsCore core, const char *valueName, const char *value, HelicsError *err)
Definition: helicsExport.cpp:807
helicsCoreSendCommand
void helicsCoreSendCommand(HelicsCore core, const char *target, const char *command, HelicsError *err)
Definition: helicsExport.cpp:827
helicsCoreDisconnect
void helicsCoreDisconnect(HelicsCore core, HelicsError *err)
Definition: helicsExport.cpp:952
helicsCoreGetAddress
const char * helicsCoreGetAddress(HelicsCore core)
Definition: helicsExport.cpp:907
helicsQuerySetOrdering
void helicsQuerySetOrdering(HelicsQuery query, int32_t mode, HelicsError *err)
Definition: helicsExport.cpp:1305
helicsCoreClone
HelicsCore helicsCoreClone(HelicsCore core, HelicsError *err)
Definition: helicsExport.cpp:438
helicsCoreAddAlias
void helicsCoreAddAlias(HelicsCore core, const char *interfaceName, const char *alias, HelicsError *err)
Definition: helicsExport.cpp:607
helicsQueryFree
void helicsQueryFree(HelicsQuery query)
Definition: helicsExport.cpp:1314
helicsCoreGetIdentifier
const char * helicsCoreGetIdentifier(HelicsCore core)
Definition: helicsExport.cpp:885
helicsCoreSetReadyToInit
void helicsCoreSetReadyToInit(HelicsCore core, HelicsError *err)
Definition: helicsExport.cpp:918
helicsCoreGlobalError
void helicsCoreGlobalError(HelicsCore core, int errorCode, const char *errorString, HelicsError *err)
Definition: helicsExport.cpp:709
helicsCreateQuery
HelicsQuery helicsCreateQuery(const char *target, const char *query)
Definition: helicsExport.cpp:1128
helicsCreateCore
HelicsCore helicsCreateCore(const char *type, const char *name, const char *initString, HelicsError *err)
Definition: helicsExport.cpp:368
helicsCreateCoreFromArgs
HelicsCore helicsCreateCoreFromArgs(const char *type, const char *name, int argc, const char *const *argv, HelicsError *err)
Definition: helicsExport.cpp:403
helicsCoreFree
void helicsCoreFree(HelicsCore core)
Definition: helicsExport.cpp:1039
helicsCoreWaitForDisconnect
HelicsBool helicsCoreWaitForDisconnect(HelicsCore core, int msToWait, HelicsError *err)
Definition: helicsExport.cpp:987
helicsQueryCoreExecute
const char * helicsQueryCoreExecute(HelicsQuery query, HelicsCore core, HelicsError *err)
Definition: helicsExport.cpp:1169
helicsCoreIsConnected
HelicsBool helicsCoreIsConnected(HelicsCore core)
Definition: helicsExport.cpp:798
HelicsFilterTypes
HelicsFilterTypes
Definition: helics_enums.h:391
HelicsSequencingModes
HelicsSequencingModes
Definition: helics_enums.h:427
HELICS_SEQUENCING_MODE_FAST
@ HELICS_SEQUENCING_MODE_FAST
Definition: helics_enums.h:429
helicscpp
Definition: cpp98/Broker.hpp:18