| helics 3.6.1

application_api/Translator.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 #pragma once
8
9 #include "../core/Core.hpp"
10 #include "Federate.hpp"
11 #include "helics/helics_enums.h"
12
13 #include <memory>
14 #include <string>
15
16 namespace helics {
17 class TranslatorOperations;
18 class TranslatorOperator;
19 class CoreApp;
21 enum TranslatorTypes : std::int32_t {
22 CUSTOM = HELICS_TRANSLATOR_TYPE_CUSTOM,
23 JSON = HELICS_TRANSLATOR_TYPE_JSON,
24 BINARY = HELICS_TRANSLATOR_TYPE_BINARY,
25 UNRECOGNIZED = 7
26 };
27
28 constexpr std::string_view emptyString{""};
29
31 HELICS_CXX_EXPORT TranslatorTypes
32 translatorTypeFromString(std::string_view translatorType) noexcept;
33
35 class HELICS_CXX_EXPORT Translator: public Interface {
36 protected:
37 bool disableAssign = false;
38 private:
39 std::shared_ptr<TranslatorOperations>
40 transOp;
41 public:
43 Translator() = default;
45 Translator(Federate* ffed, std::string_view translatorName, InterfaceHandle ihandle);
47 Translator(Core* core, std::string_view translatorName, InterfaceHandle ihandle);
49 explicit Translator(Core* core, std::string_view translatorName = emptyString);
51 virtual ~Translator() = default;
52
53 Translator(Translator&& trans) = default;
55 Translator(const Translator& trans) = default;
56 Translator& operator=(Translator&& trans) = default;
58 Translator& operator=(const Translator& trans) = default;
59
61 void setOperator(std::shared_ptr<TranslatorOperator> operation);
62
63 virtual const std::string& getDisplayName() const override { return getName(); }
64
69 virtual void set(std::string_view property, double val);
70
75 virtual void setString(std::string_view property, std::string_view val);
76
77 void addPublication(std::string_view target)
78 {
79 addSourceTarget(target, InterfaceType::PUBLICATION);
80 }
81 void addInputTarget(std::string_view target)
82 {
83 addDestinationTarget(target, InterfaceType::INPUT);
84 }
85 void addSourceEndpoint(std::string_view target)
86 {
87 addSourceTarget(target, InterfaceType::ENDPOINT);
88 }
89 void addDestinationEndpoint(std::string_view target)
90 {
91 addDestinationTarget(target, InterfaceType::ENDPOINT);
92 }
93 void addSourceFilter(std::string_view filterName)
94 {
95 addSourceTarget(filterName, InterfaceType::FILTER);
96 }
98 void addDestinationFilter(std::string_view filterName)
99 {
100 addDestinationTarget(filterName, InterfaceType::FILTER);
101 }
103 void setTranslatorType(std::int32_t type);
104
105 protected:
107 void setTranslatorOperations(std::shared_ptr<TranslatorOperations> translatorOps);
109 friend void addOperations(Translator* translator, TranslatorTypes type);
110 };
111
112 } // namespace helics
helics::Core
Definition: core/Core.hpp:41
helics::Federate
Definition: application_api/Federate.hpp:48
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::Interface
Definition: application_api/Federate.hpp:880
helics::Translator
Definition: application_api/Translator.hpp:35
helics::Translator::addDestinationFilter
void addDestinationFilter(std::string_view filterName)
Definition: application_api/Translator.hpp:98
helics::Translator::Translator
Translator()=default
helics::Translator::operator=
Translator & operator=(const Translator &trans)=default
helics::Translator::~Translator
virtual ~Translator()=default
helics::Translator::getDisplayName
virtual const std::string & getDisplayName() const override
Definition: application_api/Translator.hpp:63
helics::Translator::Translator
Translator(const Translator &trans)=default
helics_enums.h
base helics enumerations for C and C++ API's
HELICS_TRANSLATOR_TYPE_JSON
@ HELICS_TRANSLATOR_TYPE_JSON
Definition: helics_enums.h:416
HELICS_TRANSLATOR_TYPE_CUSTOM
@ HELICS_TRANSLATOR_TYPE_CUSTOM
Definition: helics_enums.h:414
HELICS_TRANSLATOR_TYPE_BINARY
@ HELICS_TRANSLATOR_TYPE_BINARY
Definition: helics_enums.h:418
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::addOperations
void addOperations(Filter *filt, FilterTypes type, Core *)
Definition: Filters.cpp:54
helics::TranslatorTypes
TranslatorTypes
Definition: application_api/Translator.hpp:21
helics::InterfaceType::ENDPOINT
@ ENDPOINT
handle to an endpoint
helics::InterfaceType::PUBLICATION
@ PUBLICATION
handle to output interface
helics::InterfaceType::INPUT
@ INPUT
handle to a input interface
helics::InterfaceType::FILTER
@ FILTER
handle to a filter
helics::translatorTypeFromString
TranslatorTypes translatorTypeFromString(std::string_view translatorType) noexcept
Definition: Translator.cpp:25