Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
UnitConversionServerEx.h
Go to the documentation of this file.
1#pragma once
3#include <gii/gen/Variable.h>
4#include <gii/global.h>
5#include <memory>
6
7namespace sf
8{
9
16{
17 public:
22
27
31 void flush();
32
36 void setUnitSystem(int us) override;
37
44 bool load(std::istream& is) override;
45
52 bool save(std::ostream& os) override;
53
61 void setEnable(bool enable);
62
66 [[nodiscard]] id_type getEnableId() const;
67
72
79 void convertVariable(const Variable& var, bool regular = false);
80
85
91
95 [[nodiscard]] static const char* getFollowersSectionName();
96
97 protected:
101 bool handler(UnitConversionEvent& ev) override;
102
103 private:
107 void variableEventHandler(EEvent event, const Variable& call_var, Variable& link_var, bool same_inst) override;
108
116 void storeConfig(bool save);
117
121 class Entry final : VariableHandler
122 {
123 public:
128 explicit Entry(UnitConversionServerEx* owner);
129
137 Variable _vMaster;
141 std::vector<Variable::id_type> _ids;
145 std::string _unit;
149 std::string _script;
150
154 void updateConversion();
155
161 bool convertVariable(const Variable& var) const;
162
163 private:
167 void variableEventHandler(EEvent event, const Variable& call_var, Variable& link_var, bool same_inst) override;
168 };
169
173 UnitConversionServerClosure _askHandler;
177 bool _enabled{false};
181 Variable _vEnable;
185 std::vector<std::unique_ptr<Entry>> _entries;
189 std::map<Variable::id_type, Entry*> _map;
190};
191
192}// namespace sf
unsigned long long id_type
Type used for the identifying integer (64-bits).
Definition InformationBase.h:30
Extended UnitConversionServer with master and slaved variables.
Definition UnitConversionServerEx.h:16
void flush()
Flushes all conversion lists from this container.
void setUnitSystem(int us) override
Overridden from base class to intercept a change.
void setEnable(bool enable)
Enables or disables the conversion on Variables that are following the master.
bool handler(UnitConversionEvent &ev) override
Overridden from base class to intercept conversion failure.
~UnitConversionServerEx() override
Destructor.
void reinitialize()
Generates a lookup table and resets the existing conversion values.
void convertVariable(const Variable &var, bool regular=false)
Converts this variable when a slave using the masters value.
bool load(std::istream &is) override
Load the conversion configuration.
bool save(std::ostream &os) override
Load the conversion configuration.
UnitConversionServerEx()
Default constructor.
void setAskHandler(const UnitConversionServerClosure &closure=UnitConversionServerClosure())
Assigns a handler for when a conversion is not provided. Calling this method with default arguments d...
static const char * getFollowersSectionName()
Gets the name of the followers section.
id_type getEnableId() const
Gets the enabled variable ID.
void setEnableId(id_type)
Sets the enabled variable ID.
Implementation of a unit conversion server using an ini-file. This conversion class installs a handle...
Definition UnitConversionServer.h:16
Base class used for giving a Variable instance access to a member functions of a derived class....
Definition VariableHandler.h:14
EEvent
Events send to the handler set with sf::Variable::setHandler.
Definition VariableTypes.h:130
Class for creating and referencing global or local created parameters or settings called variables....
Definition Variable.h:16
#define _GII_CLASS
Definition gii/global.h:38
Definition Application.h:10
Structure passed to handle unit conversions.
Definition UnitConversion.h:14