helics 3.7.0
Loading...
Searching...
No Matches
cpp98/Federate.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7#ifndef HELICS_CPP98_FEDERATE_HPP_
8#define HELICS_CPP98_FEDERATE_HPP_
9#pragma once
10
11#include "Filter.hpp"
12#include "Translator.hpp"
13#include "config.hpp"
14#include "helics/helics.h"
15#include "helicsExceptions.hpp"
16
17#include <complex>
18#include <string>
19#include <vector>
20
21#if defined(HELICS_HAS_FUNCTIONAL) && HELICS_HAS_FUNCTIONAL != 0
22# include <functional>
23# include <utility>
24#endif
25
26namespace helicscpp {
29 public:
31 FederateInfo() { fedInfo = helicsCreateFederateInfo(); }
34 explicit FederateInfo(const std::string& coretype)
35 {
36 fedInfo = helicsCreateFederateInfo();
37 helicsFederateInfoSetCoreTypeFromString(fedInfo, coretype.c_str(), hThrowOnError());
38 }
41 explicit FederateInfo(int coretype)
42 {
43 fedInfo = helicsCreateFederateInfo();
44 helicsFederateInfoSetCoreType(fedInfo, coretype, hThrowOnError());
45 }
47 FederateInfo(const FederateInfo& otherFedInfo)
48 {
49 fedInfo = helicsFederateClone(otherFedInfo.fedInfo, hThrowOnError());
50 }
52 FederateInfo& operator=(const FederateInfo& otherFedInfo)
53 {
54 HelicsFederateInfo fi_new = helicsFederateClone(otherFedInfo.fedInfo, hThrowOnError());
55 helicsFederateInfoFree(fedInfo);
56 fedInfo = fi_new;
57 return *this;
58 }
59#ifdef HELICS_HAS_RVALUE_REFS
61 FederateInfo(FederateInfo&& otherFedInfo) HELICS_NOTHROW
62 {
63 fedInfo = otherFedInfo.fedInfo;
64 otherFedInfo.fedInfo = HELICS_NULL_POINTER;
65 }
67 FederateInfo& operator=(FederateInfo&& otherFedInfo) HELICS_NOTHROW
68 {
69 helicsFederateInfoFree(fedInfo);
70 fedInfo = otherFedInfo.fedInfo;
71 otherFedInfo.fedInfo = HELICS_NULL_POINTER;
72 return *this;
73 }
74#endif
76 ~FederateInfo() { helicsFederateInfoFree(fedInfo); }
77 void loadFromArgs(const std::string& argString)
78 {
79 helicsFederateInfoLoadFromString(fedInfo, argString.c_str(), HELICS_NULL_POINTER);
80 }
83 void setCoreName(const std::string& coreName)
84 {
85 helicsFederateInfoSetCoreName(fedInfo, coreName.c_str(), HELICS_NULL_POINTER);
86 }
88 void setSeparator(char sep)
89 {
90 helicsFederateInfoSetSeparator(fedInfo, sep, HELICS_NULL_POINTER);
91 }
94 void setCoreInit(const std::string& coreInit)
95 {
96 helicsFederateInfoSetCoreInitString(fedInfo, coreInit.c_str(), HELICS_NULL_POINTER);
97 }
99 void setBrokerInit(const std::string& brokerInit)
100 {
101 helicsFederateInfoSetBrokerInitString(fedInfo, brokerInit.c_str(), HELICS_IGNORE_ERROR);
102 }
106 void setCoreType(const std::string& coretype)
107 {
108 helicsFederateInfoSetCoreTypeFromString(fedInfo, coretype.c_str(), hThrowOnError());
109 }
113 void setCoreType(int coretype)
114 {
115 helicsFederateInfoSetCoreType(fedInfo, coretype, HELICS_NULL_POINTER);
116 }
120 void setBroker(const std::string& broker)
121 {
122 helicsFederateInfoSetBroker(fedInfo, broker.c_str(), HELICS_NULL_POINTER);
123 }
127 void setBrokerKey(const std::string& brokerkey)
128 {
129 helicsFederateInfoSetBrokerKey(fedInfo, brokerkey.c_str(), HELICS_NULL_POINTER);
130 }
135 void setFlagOption(int flag, bool value = true)
136 {
137 helicsFederateInfoSetFlagOption(fedInfo,
138 flag,
139 value ? HELICS_TRUE : HELICS_FALSE,
140 HELICS_NULL_POINTER);
141 }
146 void setProperty(int timeProperty, HelicsTime timeValue)
147 {
148 helicsFederateInfoSetTimeProperty(fedInfo, timeProperty, timeValue, HELICS_NULL_POINTER);
149 }
154 void setProperty(int integerProperty, int propertyValue)
155 {
156 helicsFederateInfoSetIntegerProperty(fedInfo,
157 integerProperty,
158 propertyValue,
159 HELICS_NULL_POINTER);
160 }
161
163 HELICS_NODISCARD HelicsFederateInfo getInfo() { return fedInfo; }
164
165 private:
166 HelicsFederateInfo fedInfo;
167};
168
169#if defined(HELICS_HAS_FUNCTIONAL) && HELICS_HAS_FUNCTIONAL != 0
170namespace details {
172 inline void helicCppQueryCallbackExecutor(const char* query,
173 int stringSize,
174 HelicsQueryBuffer buffer,
175 void* userData)
176 {
177 auto cback = reinterpret_cast<std::function<std::string(const std::string&)>*>(userData);
178 std::string val(query, stringSize);
179 std::string result = (*cback)(val);
180 helicsQueryBufferFill(buffer, result.c_str(), static_cast<int>(result.size()), nullptr);
181 }
182
184 inline void
185 helicCppTimeUpdateCallbackExecutor(HelicsTime time, HelicsBool iterating, void* userData)
186 {
187 auto cback = reinterpret_cast<std::function<void(HelicsTime, bool)>*>(userData);
188 (*cback)(time, iterating == HELICS_TRUE);
189 }
190
192 inline void helicCppStateChangeCallbackExecutor(HelicsFederateState newState,
193 HelicsFederateState oldState,
194 void* userData)
195 {
196 auto cback =
197 reinterpret_cast<std::function<void(HelicsFederateState, HelicsFederateState)>*>(
198 userData);
199 (*cback)(newState, oldState);
200 }
201
203 inline void helicCppTimeRequestEntryCallbackExecutor(HelicsTime currentTime,
204 HelicsTime requestTime,
205 HelicsBool iterating,
206 void* userData)
207 {
208 auto cback = reinterpret_cast<std::function<void(HelicsTime, HelicsTime, bool)>*>(userData);
209 (*cback)(currentTime, requestTime, iterating == HELICS_TRUE);
210 }
212 inline void helicCppTimeRequestReturnCallbackExecutor(HelicsTime newTime,
213 HelicsBool iterating,
214 void* userData)
215 {
216 auto cback = reinterpret_cast<std::function<void(HelicsTime, bool)>*>(userData);
217 (*cback)(newTime, iterating == HELICS_TRUE);
218 }
219} // namespace details
220#endif
221
227
229class Federate {
230 public:
232 Federate() HELICS_NOTHROW: fed(NULL), exec_async_iterate(false) {}
235 {
236 fed = helicsFederateClone(fedObj.fed, hThrowOnError());
237 }
240 {
242 fed = helicsFederateClone(fedObj.fed, hThrowOnError());
243 return *this;
244 }
245#ifdef HELICS_HAS_RVALUE_REFS
247 Federate(Federate&& fedObj) HELICS_NOTHROW:
248 fed(fedObj.fed),
249 exec_async_iterate(fedObj.exec_async_iterate)
250 {
251 fedObj.fed = HELICS_NULL_POINTER;
252 }
254 Federate& operator=(Federate&& fedObj) HELICS_NOTHROW
255 {
256 exec_async_iterate = fedObj.exec_async_iterate;
257 fed = fedObj.fed;
258 fedObj.fed = HELICS_NULL_POINTER;
259 return *this;
260 }
261#endif
263 virtual ~Federate()
264 {
265 if (fed != HELICS_NULL_POINTER) {
267 }
268#if defined(HELICS_HAS_FUNCTIONAL) && HELICS_HAS_FUNCTIONAL != 0
269 freeCallbacks();
270#endif
271 }
273 operator HelicsFederate() const { return fed; }
275 HELICS_NODISCARD HelicsFederate baseObject() const { return fed; }
280 void setFlagOption(int flag, bool flagValue = true)
281 {
282 helicsFederateSetFlagOption(fed,
283 flag,
284 flagValue ? HELICS_TRUE : HELICS_FALSE,
285 hThrowOnError());
286 }
291 void setProperty(int tProperty, HelicsTime timeValue)
292 {
293 helicsFederateSetTimeProperty(fed, tProperty, timeValue, hThrowOnError());
294 }
299 void setProperty(int intProperty, int value)
300 {
301 helicsFederateSetIntegerProperty(fed, intProperty, value, hThrowOnError());
302 }
303
307 HELICS_NODISCARD bool getFlagOption(int flag) const
308 {
309 return (helicsFederateGetFlagOption(fed, flag, hThrowOnError()) != HELICS_FALSE);
310 }
314 HELICS_NODISCARD HelicsTime getTimeProperty(int tProperty) const
315 {
316 return helicsFederateGetTimeProperty(fed, tProperty, hThrowOnError());
317 }
321 HELICS_NODISCARD int getIntegerProperty(int intProperty) const
322 {
323 return helicsFederateGetIntegerProperty(fed, intProperty, hThrowOnError());
324 }
332 void setSeparator(char sep) { helicsFederateSetSeparator(fed, sep, HELICS_NULL_POINTER); }
338 void registerInterfaces(const std::string& configString)
339 {
340 helicsFederateRegisterInterfaces(fed, configString.c_str(), hThrowOnError());
341 }
343 HELICS_NODISCARD HelicsFederateState getCurrentMode() const
344 {
345 return helicsFederateGetState(fed, HELICS_NULL_POINTER);
346 }
351 HELICS_NODISCARD bool isAsyncOperationCompleted() const
352 {
353 // returns int, 1 = true, 0 = false
354 return helicsFederateIsAsyncOperationCompleted(fed, HELICS_NULL_POINTER) != HELICS_FALSE;
355 }
359 void enterInitializingMode() { helicsFederateEnterInitializingMode(fed, hThrowOnError()); }
365 {
366 helicsFederateEnterInitializingModeAsync(fed, hThrowOnError());
367 }
368
373 {
374 helicsFederateEnterInitializingModeComplete(fed, hThrowOnError());
375 }
376
383 {
384 helicsFederateEnterInitializingModeIterative(fed, hThrowOnError());
385 }
391 {
392 helicsFederateEnterInitializingModeIterativeAsync(fed, hThrowOnError());
393 }
394
399 {
400 helicsFederateEnterInitializingModeIterativeComplete(fed, hThrowOnError());
401 }
402
409 {
412 helicsFederateEnterExecutingMode(fed, hThrowOnError());
413 } else {
414 out_iterate = helicsFederateEnterExecutingModeIterative(fed, iterate, hThrowOnError());
415 }
416 return out_iterate;
417 }
425 {
427 helicsFederateEnterExecutingModeAsync(fed, hThrowOnError());
428 exec_async_iterate = false;
429 } else {
430 helicsFederateEnterExecutingModeIterativeAsync(fed, iterate, hThrowOnError());
431 exec_async_iterate = true;
432 }
433 }
434
440 {
442 if (exec_async_iterate) {
443 out_iterate = helicsFederateEnterExecutingModeIterativeComplete(fed, hThrowOnError());
444 } else {
445 helicsFederateEnterExecutingModeComplete(fed, hThrowOnError());
446 }
447 return out_iterate;
448 }
452 void finalize() { helicsFederateFinalize(fed, hThrowOnError()); }
455 void finalizeAsync() { helicsFederateFinalizeAsync(fed, hThrowOnError()); }
457 void finalizeComplete() { helicsFederateFinalizeComplete(fed, hThrowOnError()); }
459 HELICS_NODISCARD HelicsTime getCurrentTime()
460 {
461 return helicsFederateGetCurrentTime(fed, hThrowOnError());
462 }
467 {
468 return helicsFederateRequestTime(fed, time, hThrowOnError());
469 }
472 HelicsTime requestNextStep() { return helicsFederateRequestNextStep(fed, hThrowOnError()); }
473
478 {
479 return helicsFederateRequestTimeAdvance(fed, timeDelta, hThrowOnError());
480 }
486 {
487 HelicsIterationTime itTime;
488 itTime.grantedTime = helicsFederateRequestTimeIterative(
489 fed, time, iterate, &(itTime.status), hThrowOnError());
490 return itTime;
491 }
497 {
498 helicsFederateRequestTimeAsync(fed, time, hThrowOnError());
499 }
500
508 {
509 helicsFederateRequestTimeIterativeAsync(fed, time, iterate, hThrowOnError());
510 }
511
515 {
516 return helicsFederateRequestTimeComplete(fed, hThrowOnError());
517 }
518
523 {
524 HelicsIterationTime itTime;
525 itTime.grantedTime =
526 helicsFederateRequestTimeIterativeComplete(fed, &(itTime.status), hThrowOnError());
527 return itTime;
528 }
529
530 void processCommunication(HelicsTime period)
531 {
532 helicsFederateProcessCommunications(fed, period, HELICS_IGNORE_ERROR);
533 }
535 HELICS_NODISCARD const char* getName() const { return helicsFederateGetName(fed); }
536
538 void protect() { helicsFederateProtect(helicsFederateGetName(fed), HELICS_IGNORE_ERROR); }
539
541 void unProtect() { helicsFederateUnProtect(helicsFederateGetName(fed), HELICS_IGNORE_ERROR); }
542
556 std::string query(const std::string& target,
557 const std::string& queryStr,
559 {
560 // returns HelicsQuery
561 HelicsQuery q = helicsCreateQuery(target.c_str(), queryStr.c_str());
562 if (mode != HELICS_SEQUENCING_MODE_FAST) {
563 helicsQuerySetOrdering(q, mode, HELICS_IGNORE_ERROR);
564 }
565 std::string result(helicsQueryExecute(q, fed, hThrowOnError()));
567 return result;
568 }
569
583 std::string query(const std::string& queryStr,
585 {
586 // returns HelicsQuery
587 HelicsQuery q = helicsCreateQuery(HELICS_NULL_POINTER, queryStr.c_str());
588 if (mode != HELICS_SEQUENCING_MODE_FAST) {
589 helicsQuerySetOrdering(q, mode, HELICS_IGNORE_ERROR);
590 }
591 std::string result(helicsQueryExecute(q, fed, hThrowOnError()));
593 return result;
594 }
595
603 void sendCommand(const std::string& target, const std::string& cmd)
604 {
605 helicsFederateSendCommand(fed, target.c_str(), cmd.c_str(), HELICS_IGNORE_ERROR);
606 }
607
614 HELICS_NODISCARD const char* getCommand()
615 {
616 return helicsFederateGetCommand(fed, HELICS_IGNORE_ERROR);
617 }
618
625 HELICS_NODISCARD const char* waitCommand()
626 {
627 return helicsFederateWaitCommand(fed, HELICS_IGNORE_ERROR);
628 }
629
636 HELICS_NODISCARD const char* getCommandSource()
637 {
638 return helicsFederateGetCommandSource(fed, HELICS_IGNORE_ERROR);
639 }
640
641 void setQueryCallback(
642 void (*queryAnswer)(const char* query, int querySize, HelicsQueryBuffer, void* userdata),
643 void* userdata)
644
645 {
646 helicsFederateSetQueryCallback(fed, queryAnswer, userdata, hThrowOnError());
647 }
648
649 void setTimeRequestEntryCallback(void (*timeRequestEntry)(HelicsTime currentTime,
651 HelicsBool iterating,
652 void* userdata),
653 void* userdata)
654
655 {
656 helicsFederateSetTimeRequestEntryCallback(fed, timeRequestEntry, userdata, hThrowOnError());
657 }
658
659 void setTimeUpdateCallback(void (*timeUpdate)(HelicsTime time,
660 HelicsBool iterating,
661 void* userdata),
662 void* userdata)
663
664 {
665 helicsFederateSetTimeUpdateCallback(fed, timeUpdate, userdata, hThrowOnError());
666 }
667
668 void setStateChangeCallback(void (*stateChange)(HelicsFederateState newState,
669 HelicsFederateState oldState,
670 void* userdata),
671 void* userdata)
672
673 {
674 helicsFederateSetStateChangeCallback(fed, stateChange, userdata, hThrowOnError());
675 }
676
677 void setTimeRequestReturnCallback(void (*timeRequestReturn)(HelicsTime newTime,
678 HelicsBool iterating,
679 void* userdata),
680 void* userdata)
681
682 {
683 helicsFederateSetTimeRequestReturnCallback(fed,
684 timeRequestReturn,
685 userdata,
686 hThrowOnError());
687 }
688#if defined(HELICS_HAS_FUNCTIONAL) && HELICS_HAS_FUNCTIONAL != 0
689 void setQueryCallback(std::function<std::string(const std::string&)> callback)
690
691 {
692 checkCallbackAllocation();
693 callbackBuffers[queryCallbackLocation] =
694 new std::function<std::string(const std::string&)>(std::move(callback));
695 helicsFederateSetQueryCallback(fed,
696 details::helicCppQueryCallbackExecutor,
697 callbackBuffers[queryCallbackLocation],
698 hThrowOnError());
699 }
700
701 void setTimeRequestEntryCallback(
702 std::function<void(HelicsTime currentTime, HelicsTime requestTime, bool iterating)>
703 callback)
704
705 {
706 checkCallbackAllocation();
707 callbackBuffers[timeRequestEntryCallbackLocation] =
708 new std::function<void(HelicsTime, HelicsTime, bool)>(std::move(callback));
709 helicsFederateSetTimeRequestEntryCallback(fed,
710 details::helicCppTimeRequestEntryCallbackExecutor,
711 callbackBuffers[timeRequestEntryCallbackLocation],
712 hThrowOnError());
713 }
714
715 void setTimeUpdateCallback(std::function<void(HelicsTime time, bool iterating)> callback)
716
717 {
718 checkCallbackAllocation();
719 callbackBuffers[timeUpdateCallbackLocation] =
720 new std::function<void(HelicsTime time, bool iterating)>(std::move(callback));
721 helicsFederateSetTimeUpdateCallback(fed,
722 details::helicCppTimeUpdateCallbackExecutor,
723 callbackBuffers[timeUpdateCallbackLocation],
724 hThrowOnError());
725 }
726
727 void setStateChangeCallback(
728 std::function<void(HelicsFederateState, HelicsFederateState)> callback)
729
730 {
731 checkCallbackAllocation();
732 callbackBuffers[stateChangeCallbackLocation] =
733 new std::function<void(HelicsFederateState, HelicsFederateState)>(std::move(callback));
734 helicsFederateSetStateChangeCallback(fed,
735 details::helicCppStateChangeCallbackExecutor,
736 callbackBuffers[stateChangeCallbackLocation],
737 hThrowOnError());
738 }
739
740 void setTimeRequestReturnCallback(
741 std::function<void(HelicsTime newTime, bool iterating)> callback)
742
743 {
744 checkCallbackAllocation();
745 callbackBuffers[timeRequestReturnCallbackLocation] =
746 new std::function<void(HelicsTime, bool)>(std::move(callback));
747 helicsFederateSetTimeRequestReturnCallback(
748 fed,
749 details::helicCppTimeRequestReturnCallbackExecutor,
750 callbackBuffers[timeRequestReturnCallbackLocation],
751 hThrowOnError());
752 }
753#endif
759 Filter registerFilter(HelicsFilterTypes type, const std::string& filterName = std::string())
760 {
761 return Filter(helicsFederateRegisterFilter(fed, type, filterName.c_str(), hThrowOnError()));
762 }
763
770 CloningFilter registerCloningFilter(const std::string& deliveryEndpoint)
771 {
772 return CloningFilter(
773 helicsFederateRegisterCloningFilter(fed, deliveryEndpoint.c_str(), hThrowOnError()));
774 }
781 const std::string& filterName = std::string())
782 {
783 return Filter(
784 helicsFederateRegisterGlobalFilter(fed, type, filterName.c_str(), hThrowOnError()));
785 }
786
793 CloningFilter registerGlobalCloningFilter(const std::string& deliveryEndpoint)
794 {
796 deliveryEndpoint.c_str(),
797 hThrowOnError()));
798 }
800 HELICS_NODISCARD int getFilterCount() const { return helicsFederateGetFilterCount(fed); }
804 HELICS_NODISCARD Filter getFilter(const std::string& filterName)
805 {
806 return Filter(helicsFederateGetFilter(fed, filterName.c_str(), hThrowOnError()));
807 }
811 HELICS_NODISCARD Filter getFilter(int index)
812 {
814 }
815
821 void setGlobal(const std::string& valueName, const std::string& value)
822 {
823 helicsFederateSetGlobal(fed, valueName.c_str(), value.c_str(), hThrowOnError());
824 }
825
830 void addAlias(const std::string& interfaceName, const std::string& alias)
831 {
832 helicsFederateAddAlias(fed, interfaceName.c_str(), alias.c_str(), hThrowOnError());
833 }
834
840 void setTag(const std::string& tag, const std::string& value)
841 {
842 helicsFederateSetTag(fed, tag.c_str(), value.c_str(), hThrowOnError());
843 }
850 HELICS_NODISCARD const char* getTag(const std::string& tag) const
851 {
852 return helicsFederateGetTag(fed, tag.c_str(), hThrowOnError());
853 }
854
859 void addDependency(const std::string& fedName)
860 {
861 helicsFederateAddDependency(fed, fedName.c_str(), hThrowOnError());
862 }
863
868 void localError(int errorCode, const std::string& errorString)
869 {
870 helicsFederateLocalError(fed, errorCode, errorString.c_str(), hThrowOnError());
871 }
872
877 void globalError(int errorCode, const std::string& errorString)
878 {
879 helicsFederateGlobalError(fed, errorCode, errorString.c_str(), hThrowOnError());
880 }
881
883 void logErrorMessage(const std::string& message)
884 {
885 helicsFederateLogErrorMessage(fed, message.c_str(), hThrowOnError());
886 }
888 void logWarningMessage(const std::string& message)
889 {
890 helicsFederateLogWarningMessage(fed, message.c_str(), hThrowOnError());
891 }
893 void logInfoMessage(const std::string& message)
894 {
895 helicsFederateLogInfoMessage(fed, message.c_str(), hThrowOnError());
896 }
898 void logDebugMessage(const std::string& message)
899 {
900 helicsFederateLogDebugMessage(fed, message.c_str(), hThrowOnError());
901 }
903 void logMessage(int level, const std::string& message)
904 {
905 helicsFederateLogLevelMessage(fed, level, message.c_str(), hThrowOnError());
906 }
908 HELICS_NODISCARD HelicsCore getCore() { return helicsFederateGetCore(fed, hThrowOnError()); }
910 HELICS_NODISCARD HelicsFederate getObject() const { return fed; }
911
912 protected:
915#if defined(HELICS_HAS_FUNCTIONAL) && HELICS_HAS_FUNCTIONAL != 0
916 private:
917 static constexpr int numberOfCallbacks = 5;
918 static constexpr int timeRequestEntryCallbackLocation = 0;
919 static constexpr int timeUpdateCallbackLocation = 1;
920 static constexpr int stateChangeCallbackLocation = 2;
921 static constexpr int queryCallbackLocation = 3;
922 static constexpr int timeRequestReturnCallbackLocation = 4;
923 void** callbackBuffers{nullptr};
924
925 void checkCallbackAllocation()
926 {
927 if (callbackBuffers == nullptr) {
928 callbackBuffers = new void*[numberOfCallbacks];
929 for (int ii = 0; ii < numberOfCallbacks; ++ii) {
930 callbackBuffers[ii] = nullptr;
931 }
932 }
933 }
934 void freeCallbacks()
935 {
936 if (callbackBuffers == nullptr) {
937 return;
938 }
939 if (callbackBuffers[queryCallbackLocation] != nullptr) {
940 auto cback = reinterpret_cast<std::function<std::string(const std::string&)>*>(
941 callbackBuffers[queryCallbackLocation]);
942 delete cback;
943 }
944 if (callbackBuffers[timeRequestEntryCallbackLocation] != nullptr) {
945 auto cback = reinterpret_cast<std::function<void(HelicsTime, HelicsTime, bool)>*>(
946 callbackBuffers[timeRequestEntryCallbackLocation]);
947 delete cback;
948 }
949 if (callbackBuffers[timeUpdateCallbackLocation] != nullptr) {
950 auto cback = reinterpret_cast<std::function<void(HelicsTime, bool)>*>(
951 callbackBuffers[timeUpdateCallbackLocation]);
952 delete cback;
953 }
954 if (callbackBuffers[stateChangeCallbackLocation] != nullptr) {
955 auto cback =
956 reinterpret_cast<std::function<void(HelicsFederateState, HelicsFederateState)>*>(
957 callbackBuffers[stateChangeCallbackLocation]);
958 delete cback;
959 }
960 if (callbackBuffers[timeRequestReturnCallbackLocation] != nullptr) {
961 auto cback = reinterpret_cast<std::function<void(HelicsTime, bool)>*>(
962 callbackBuffers[timeRequestReturnCallbackLocation]);
963 delete cback;
964 }
965 delete[] callbackBuffers;
966 }
967#endif
968};
969
970inline void protect(const std::string& name)
971{
972 helicsFederateProtect(name.c_str(), hThrowOnError());
973}
974inline void unProtect(const std::string& name)
975{
976 helicsFederateUnProtect(name.c_str(), hThrowOnError());
977}
978
979inline bool isProtected(const std::string& name)
980{
981 return (helicsFederateIsProtected(name.c_str(), hThrowOnError()) == HELICS_TRUE) ? true : false;
982}
983
984} // namespace helicscpp
985
986#endif
HelicsFilter helicsFederateRegisterCloningFilter(HelicsFederate fed, const char *name, HelicsError *err)
Definition MessageFiltersExport.cpp:167
int helicsFederateGetFilterCount(HelicsFederate fed)
Definition MessageFiltersExport.cpp:255
HelicsFilter helicsFederateRegisterGlobalCloningFilter(HelicsFederate fed, const char *name, HelicsError *err)
Definition MessageFiltersExport.cpp:187
HelicsFilter helicsFederateGetFilterByIndex(HelicsFederate fed, int index, HelicsError *err)
Definition MessageFiltersExport.cpp:264
HelicsFilter helicsFederateGetFilter(HelicsFederate fed, const char *name, HelicsError *err)
Definition MessageFiltersExport.cpp:231
HelicsFilter helicsFederateRegisterGlobalFilter(HelicsFederate fed, HelicsFilterTypes type, const char *name, HelicsError *err)
Definition MessageFiltersExport.cpp:124
HelicsFilter helicsFederateRegisterFilter(HelicsFederate fed, HelicsFilterTypes type, const char *name, HelicsError *err)
Definition MessageFiltersExport.cpp:103
void * HelicsFederateInfo
Definition api-data.h:77
void * HelicsCore
Definition api-data.h:54
double HelicsTime
Definition api-data.h:106
HelicsIterationResult
Definition api-data.h:139
@ HELICS_ITERATION_RESULT_NEXT_STEP
Definition api-data.h:140
int HelicsBool
Definition api-data.h:120
void * HelicsQuery
Definition api-data.h:83
HelicsFederateState
Definition api-data.h:149
HelicsIterationRequest
Definition api-data.h:128
@ HELICS_ITERATION_REQUEST_NO_ITERATION
Definition api-data.h:129
void * HelicsFederate
Definition api-data.h:65
const HelicsBool HELICS_FALSE
Definition api-data.h:123
void * HelicsQueryBuffer
Definition api-data.h:94
const HelicsBool HELICS_TRUE
Definition api-data.h:122
Definition Filter.hpp:129
Definition cpp98/Federate.hpp:28
FederateInfo(int coretype)
Definition cpp98/Federate.hpp:41
FederateInfo(const FederateInfo &otherFedInfo)
Definition cpp98/Federate.hpp:47
void setCoreType(int coretype)
Definition cpp98/Federate.hpp:113
void setProperty(int integerProperty, int propertyValue)
Definition cpp98/Federate.hpp:154
void setProperty(int timeProperty, HelicsTime timeValue)
Definition cpp98/Federate.hpp:146
~FederateInfo()
Definition cpp98/Federate.hpp:76
void setFlagOption(int flag, bool value=true)
Definition cpp98/Federate.hpp:135
void setBrokerInit(const std::string &brokerInit)
Set a string for the broker initialization in command line argument format.
Definition cpp98/Federate.hpp:99
void setCoreName(const std::string &coreName)
Definition cpp98/Federate.hpp:83
void setBroker(const std::string &broker)
Definition cpp98/Federate.hpp:120
FederateInfo & operator=(const FederateInfo &otherFedInfo)
Definition cpp98/Federate.hpp:52
HELICS_NODISCARD HelicsFederateInfo getInfo()
Definition cpp98/Federate.hpp:163
FederateInfo(const std::string &coretype)
Definition cpp98/Federate.hpp:34
void setBrokerKey(const std::string &brokerkey)
Definition cpp98/Federate.hpp:127
void setCoreType(const std::string &coretype)
Definition cpp98/Federate.hpp:106
FederateInfo()
Definition cpp98/Federate.hpp:31
void setSeparator(char sep)
Set the separator character.
Definition cpp98/Federate.hpp:88
void setCoreInit(const std::string &coreInit)
Definition cpp98/Federate.hpp:94
Definition cpp98/Federate.hpp:229
HELICS_NODISCARD HelicsCore getCore()
Definition cpp98/Federate.hpp:908
void enterInitializingMode()
Definition cpp98/Federate.hpp:359
Filter registerGlobalFilter(HelicsFilterTypes type, const std::string &filterName=std::string())
Definition cpp98/Federate.hpp:780
void unProtect()
Definition cpp98/Federate.hpp:541
std::string query(const std::string &queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) const
Definition cpp98/Federate.hpp:583
HelicsFederate fed
underlying HelicsFederate object
Definition cpp98/Federate.hpp:913
HelicsIterationResult enterExecutingModeComplete()
Definition cpp98/Federate.hpp:439
HELICS_NODISCARD const char * getName() const
Definition cpp98/Federate.hpp:535
void setProperty(int intProperty, int value)
Definition cpp98/Federate.hpp:299
void protect()
Definition cpp98/Federate.hpp:538
Federate & operator=(const Federate &fedObj)
Copy assignment operator.
Definition cpp98/Federate.hpp:239
void enterInitializingModeComplete()
Definition cpp98/Federate.hpp:372
void enterExecutingModeAsync(HelicsIterationRequest iterate=HELICS_ITERATION_REQUEST_NO_ITERATION)
Definition cpp98/Federate.hpp:423
HelicsTime requestTimeComplete()
Definition cpp98/Federate.hpp:514
HELICS_NODISCARD Filter getFilter(const std::string &filterName)
Definition cpp98/Federate.hpp:804
void logWarningMessage(const std::string &message)
Definition cpp98/Federate.hpp:888
void registerInterfaces(const std::string &configString)
Definition cpp98/Federate.hpp:338
void localError(int errorCode, const std::string &errorString)
Definition cpp98/Federate.hpp:868
void addAlias(const std::string &interfaceName, const std::string &alias)
Definition cpp98/Federate.hpp:830
void enterInitializingModeIterativeAsync()
Definition cpp98/Federate.hpp:390
HelicsIterationTime requestTimeIterativeComplete()
Definition cpp98/Federate.hpp:522
HelicsTime requestTimeAdvance(HelicsTime timeDelta)
Definition cpp98/Federate.hpp:477
HelicsTime requestNextStep()
Definition cpp98/Federate.hpp:472
CloningFilter registerCloningFilter(const std::string &deliveryEndpoint)
Definition cpp98/Federate.hpp:770
HELICS_NODISCARD HelicsFederate baseObject() const
Definition cpp98/Federate.hpp:275
void requestTimeAsync(HelicsTime time)
Definition cpp98/Federate.hpp:496
void enterInitializingModeIterativeComplete()
Definition cpp98/Federate.hpp:398
Federate(const Federate &fedObj)
Copy constructor.
Definition cpp98/Federate.hpp:234
HELICS_NODISCARD int getFilterCount() const
Definition cpp98/Federate.hpp:800
HELICS_NODISCARD int getIntegerProperty(int intProperty) const
Definition cpp98/Federate.hpp:321
Filter registerFilter(HelicsFilterTypes type, const std::string &filterName=std::string())
Definition cpp98/Federate.hpp:759
void setProperty(int tProperty, HelicsTime timeValue)
Definition cpp98/Federate.hpp:291
void finalize()
Definition cpp98/Federate.hpp:452
HELICS_NODISCARD const char * getCommand()
Definition cpp98/Federate.hpp:614
void setGlobal(const std::string &valueName, const std::string &value)
Definition cpp98/Federate.hpp:821
void setFlagOption(int flag, bool flagValue=true)
Definition cpp98/Federate.hpp:280
void setTag(const std::string &tag, const std::string &value)
Definition cpp98/Federate.hpp:840
void logErrorMessage(const std::string &message)
Definition cpp98/Federate.hpp:883
void logInfoMessage(const std::string &message)
Definition cpp98/Federate.hpp:893
CloningFilter registerGlobalCloningFilter(const std::string &deliveryEndpoint)
Definition cpp98/Federate.hpp:793
void requestTimeIterativeAsync(HelicsTime time, HelicsIterationRequest iterate)
Definition cpp98/Federate.hpp:507
void logDebugMessage(const std::string &message)
Definition cpp98/Federate.hpp:898
HELICS_NODISCARD bool getFlagOption(int flag) const
Definition cpp98/Federate.hpp:307
void logMessage(int level, const std::string &message)
Definition cpp98/Federate.hpp:903
HELICS_NODISCARD Filter getFilter(int index)
Definition cpp98/Federate.hpp:811
void addDependency(const std::string &fedName)
Definition cpp98/Federate.hpp:859
bool exec_async_iterate
indicator that the federate is in an async operation
Definition cpp98/Federate.hpp:914
void sendCommand(const std::string &target, const std::string &cmd)
Definition cpp98/Federate.hpp:603
HELICS_NODISCARD HelicsFederateState getCurrentMode() const
Definition cpp98/Federate.hpp:343
void enterInitializingModeAsync()
Definition cpp98/Federate.hpp:364
void enterInitializingModeIterative()
Definition cpp98/Federate.hpp:382
HELICS_NODISCARD const char * getCommandSource()
Definition cpp98/Federate.hpp:636
HELICS_NODISCARD HelicsTime getTimeProperty(int tProperty) const
Definition cpp98/Federate.hpp:314
HELICS_NODISCARD const char * waitCommand()
Definition cpp98/Federate.hpp:625
HELICS_NODISCARD const char * getTag(const std::string &tag) const
Definition cpp98/Federate.hpp:850
virtual ~Federate()
Definition cpp98/Federate.hpp:263
std::string query(const std::string &target, const std::string &queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) const
Definition cpp98/Federate.hpp:556
void globalError(int errorCode, const std::string &errorString)
Definition cpp98/Federate.hpp:877
void setSeparator(char sep)
Definition cpp98/Federate.hpp:332
HelicsIterationTime requestTimeIterative(HelicsTime time, HelicsIterationRequest iterate)
Definition cpp98/Federate.hpp:485
HelicsTime requestTime(HelicsTime time)
Definition cpp98/Federate.hpp:466
HELICS_NODISCARD HelicsTime getCurrentTime()
Definition cpp98/Federate.hpp:459
void finalizeAsync()
Definition cpp98/Federate.hpp:455
HELICS_NODISCARD HelicsFederate getObject() const
Definition cpp98/Federate.hpp:910
void finalizeComplete()
Definition cpp98/Federate.hpp:457
HELICS_NODISCARD bool isAsyncOperationCompleted() const
Definition cpp98/Federate.hpp:351
HelicsIterationResult enterExecutingMode(HelicsIterationRequest iterate=HELICS_ITERATION_REQUEST_NO_ITERATION)
Definition cpp98/Federate.hpp:408
Federate() HELICS_NOTHROW
Default constructor.
Definition cpp98/Federate.hpp:232
Definition Filter.hpp:18
Definition helicsExceptions.hpp:38
const char * helicsQueryExecute(HelicsQuery query, HelicsFederate fed, HelicsError *err)
Definition helicsExport.cpp:1158
void helicsQuerySetOrdering(HelicsQuery query, int32_t mode, HelicsError *err)
Definition helicsExport.cpp:1322
void helicsQueryFree(HelicsQuery query)
Definition helicsExport.cpp:1331
void helicsFederateFree(HelicsFederate fed)
Definition helicsExport.cpp:1076
HelicsQuery helicsCreateQuery(const char *target, const char *query)
Definition helicsExport.cpp:1145
HelicsFilterTypes
Definition helics_enums.h:393
HelicsSequencingModes
Definition helics_enums.h:429
@ HELICS_SEQUENCING_MODE_FAST
Definition helics_enums.h:431
Definition cpp98/Broker.hpp:18
Definition cpp98/Federate.hpp:223
HelicsIterationResult status
the convergence state
Definition cpp98/Federate.hpp:225
HelicsTime grantedTime
the time of the granted step
Definition cpp98/Federate.hpp:224