| helics 3.6.1

TranslatorOperations.hpp
Go to the documentation of this file.
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
13 #include "../common/GuardedTypes.hpp"
14 #include "../core/core-data.hpp"
15 #include "../core/helicsTime.hpp"
16
17 #include <atomic>
18 #include <functional>
19 #include <memory>
20 #include <set>
21 #include <string>
22 #include <utility>
23 #include <vector>
24
25 namespace helics {
26 class Core;
27
29 class JsonTranslatorOperator: public TranslatorOperator {
30 public:
32 JsonTranslatorOperator() = default;
33
34 private:
35 virtual SmallBuffer convertToValue(std::unique_ptr<Message> message) override;
36 virtual std::unique_ptr<Message> convertToMessage(const SmallBuffer& value) override;
37 };
38
41 class BinaryTranslatorOperator: public TranslatorOperator {
42 public:
44 BinaryTranslatorOperator() = default;
45
46 private:
47 virtual SmallBuffer convertToValue(std::unique_ptr<Message> message) override;
48 virtual std::unique_ptr<Message> convertToMessage(const SmallBuffer& value) override;
49 };
50
52 class CustomTranslatorOperator: public TranslatorOperator {
53 public:
55 CustomTranslatorOperator() = default;
56
58 void setToValueFunction(
59 std::function<SmallBuffer(std::unique_ptr<Message> message)> userToValueFunction)
60 {
61 toValueFunction = std::move(userToValueFunction);
62 }
63
65 void setToMessageFunction(
66 std::function<std::unique_ptr<Message>(const SmallBuffer& value)> userToMessageFunction)
67 {
68 toMessageFunction = std::move(userToMessageFunction);
69 }
70
71 private:
73 std::function<SmallBuffer(std::unique_ptr<Message> message)> toValueFunction;
75 std::function<std::unique_ptr<Message>(const SmallBuffer& value)> toMessageFunction;
76
77 virtual SmallBuffer convertToValue(std::unique_ptr<Message> message) override;
78 virtual std::unique_ptr<Message> convertToMessage(const SmallBuffer& value) override;
79 };
80
82 class TranslatorOperations {
83 public:
84 TranslatorOperations() = default;
85 virtual ~TranslatorOperations() = default;
86 // still figuring out if these functions have a use or not
87 TranslatorOperations(const TranslatorOperations& fo) = delete;
88 TranslatorOperations(TranslatorOperations&& fo) = delete;
89 TranslatorOperations& operator=(const TranslatorOperations& fo) = delete;
90 TranslatorOperations& operator=(TranslatorOperations&& fo) = delete;
91
96 virtual void set(std::string_view property, double val);
101 virtual void setString(std::string_view property, std::string_view val);
102 virtual std::shared_ptr<TranslatorOperator> getOperator() = 0;
103 };
104
106 class CustomTranslatorOperation: public TranslatorOperations {
107 private:
108 std::shared_ptr<TranslatorOperator> to;
109
110 public:
111 explicit CustomTranslatorOperation(std::shared_ptr<TranslatorOperator> op): to(std::move(op)) {}
112 virtual std::shared_ptr<TranslatorOperator> getOperator() override { return to; }
113 };
114
116 class JsonTranslatorOperation: public TranslatorOperations {
117 private:
118 std::shared_ptr<JsonTranslatorOperator> to;
119
120 public:
121 JsonTranslatorOperation();
122 virtual std::shared_ptr<TranslatorOperator> getOperator() override
123 {
124 return std::static_pointer_cast<TranslatorOperator>(to);
125 }
126 };
127
129 class BinaryTranslatorOperation: public TranslatorOperations {
130 private:
131 std::shared_ptr<BinaryTranslatorOperator> to;
132
133 public:
135 BinaryTranslatorOperation();
136
137 virtual std::shared_ptr<TranslatorOperator> getOperator() override
138 {
139 return std::static_pointer_cast<TranslatorOperator>(to);
140 }
141 };
142
143 } // namespace helics
helics::BinaryTranslatorOperation
Definition: TranslatorOperations.hpp:129
helics::BinaryTranslatorOperation::BinaryTranslatorOperation
BinaryTranslatorOperation()
Definition: TranslatorOperations.cpp:91
helics::BinaryTranslatorOperator
Definition: TranslatorOperations.hpp:41
helics::BinaryTranslatorOperator::BinaryTranslatorOperator
BinaryTranslatorOperator()=default
helics::CustomTranslatorOperation
Definition: TranslatorOperations.hpp:106
helics::CustomTranslatorOperator
Definition: TranslatorOperations.hpp:52
helics::CustomTranslatorOperator::CustomTranslatorOperator
CustomTranslatorOperator()=default
helics::CustomTranslatorOperator::setToValueFunction
void setToValueFunction(std::function< SmallBuffer(std::unique_ptr< Message > message)> userToValueFunction)
Definition: TranslatorOperations.hpp:58
helics::CustomTranslatorOperator::setToMessageFunction
void setToMessageFunction(std::function< std::unique_ptr< Message >(const SmallBuffer &value)> userToMessageFunction)
Definition: TranslatorOperations.hpp:65
helics::JsonTranslatorOperation
Definition: TranslatorOperations.hpp:116
helics::JsonTranslatorOperator
Definition: TranslatorOperations.hpp:29
helics::JsonTranslatorOperator::JsonTranslatorOperator
JsonTranslatorOperator()=default
helics::SmallBuffer
Definition: SmallBuffer.hpp:25
helics::TranslatorOperations
Definition: TranslatorOperations.hpp:82
helics::TranslatorOperations::setString
virtual void setString(std::string_view property, std::string_view val)
Definition: TranslatorOperations.cpp:79
helics::TranslatorOperations::set
virtual void set(std::string_view property, double val)
Definition: TranslatorOperations.cpp:71
helics::TranslatorOperator
Definition: core-data.hpp:131
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14