Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::Variable Class Reference

Class for creating and referencing global or local created parameters or settings called variables. This class allows linking of member functions of other classes to handle events generated. See the Example on how to use this class and the 'TVariableHandler' template class. More...

#include <Variable.h>

Inheritance diagram for sf::Variable:
Collaboration diagram for sf::Variable:

Public Member Functions

 Variable ()
 Default constructor for a default global variable.
 
 Variable (const Variable &v)
 Copy constructor. Copies also the Desired ID data member.
 
 Variable (id_type id, bool set_desired)
 Creates an instance having a reference with 'id'.
 
 Variable (const std::string &definition, id_type id_ofs=0)
 Creates a variable according to the definition std::string passed to it. The "id" from the definition string is the passed id offset added to form a final id. This used when instances are created from resource strings for multiple instances of the same module.
 
 Variable (const Definition &def, id_type id_ofs=0)
 Creates a variable using the passed definition structure.
 
 ~Variable () override
 Virtual destructor.
 
bool setup (const std::string &definition, id_type id_ofs=0)
 Creates a variable according to the definition std::string passed to it. The passed identifier offset 'id_ofs' is added to the id in the string. This used when instances are created from resource strings for multiple instances of the same module.
 
bool setup (const Definition &definition, id_type id_ofs=0)
 Creates a variable using the definition structure.
 
bool setup (const Variable &v)
 Sets reference to other variable. This is the only way for local variables.
 
bool setup (id_type id, bool set_did=false)
 Sets reference to other by id. The global list of references is searched for the passed id and referenced when found. When found event veIdChanged is emitted. When the desired id was set and changed the veDesiredId event is emitted. Cannot be used for local variables.
 
bool setId (id_type id, bool skip_self=false) const
 Only for local non exported owning variables to set the id after setup is called using a string. The id can not be zero and attached local variables are notify with a veNewId event.
 
bool isValid () const
 Checks validity of the attached reference and used after a setup call.
 
bool isConverted () const
 Checks if the current instance is converting floating point values.
 
bool setConvert (bool enable)
 Enables or disables conversion of floating point values. If a change was triggered a veConverted event was emitted.
 
bool isNumber () const
 Checks if the value is a number or not. Result is true when the value type is either Value::vitFloat or Value::vitInteger.
 
void makeOwner ()
 Makes this instance owner of this variable instance and emits the appropriate events. When the owner really changes instances the new owner handler receives a veGetOwner event and the previous one veLostOwner.
 
VariablegetOwner () const
 Gets a reference to the owner/server instance of this variable.
 
bool isOwner () const
 Checks if this instance is the owner of this variable.
 
bool isGlobal () const
 Check if this instance is a global variable or not.
 
bool setGlobal (bool global)
 Sets the variable to be global. This can only happen if it attached to Zero Variable so when the id is zero.
 
bool setExport (bool global)
 Makes an owning local variable appear globally. Useful when reading/creating instances from stored files. First as local instances and then making them global.
 
bool isExported () const
 Checks if the variable is an exported local variable.
 
bool isTemporary () const
 Checks if a temporary is used instead of current actual value.
 
void setTemporary (bool on_off)
 When true is passed a local temporary value is used instead of current.
 
bool applyTemporary (bool skip_self=true) const
 Applies the temporary value of this instance. Used mainly in dialogs to apply the changed value to become the actual current one. The 'skip_self' flag is set to true by default because an event was already sent using setCur().
 
bool updateTemporary (bool skip_self=false)
 Updates the temporary value with the real value.
 
bool isTemporaryDifferent () const
 Check if the temporary value differs from the actual value. Used mainly in dialogs to enable an apply button.
 
void setHandler (VariableHandler *handler)
 Only one link is available at a time. Sets an event handler for this variable, passing NULL wil disable the link.
 
VariableHandlergetHandler () const
 Gets the link set by setHandler().
 
size_type emitEvent (EEvent event, bool skip_self=false)
 Initiate event for all instances of this variable depending on the event value. Returns the amount of effected variables by this call.
 
void setDesiredId ()
 Sets the desired id member variable to the current attached reference id.
 
void setDesiredId (id_type id)
 Sets the desired id member variable to the passed id. If the passed 'id' is zero the automatic attachment mechanism is disabled.
 
template<typename T >
void setData (T data)
 Sets the data for this instance for user purposes.
 
template<typename T = uint64_t>
getData () const
 Gets the data for this instance for user purposes Set with setData().
 
bool setCur (const Value &value, bool skip_self=false)
 Both return true if there was a change and notify all variables of the same variable id through an event.
 
bool setCur (const Value &value, bool skip_self=false) const
 Same as setCur() but for const instances objects of this instance.
 
bool loadCur (const Value &value) const
 Used in settings loading routines which use the owner to Set a new value. Checks if clients have write access and is global before applying the new value.
 
bool increase (int steps, bool skip_self=false)
 Increase current variable value by step increments also negative values. Emits event veValueChange when a change is flags occurred.
 
bool unsetFlag (flags_type flag, bool skip_self=false) const
 Unsets a flag or multiple flags of the attached VariableReference. Emits event veValueChange when a change in flags occurred.
 
bool setFlag (flags_type flag, bool skip_self=false) const
 Sets a flag or multiple flags on the reference. Only for an owner can call this function successful. Emits event veFlagsChange when a change in flags occurred.
 
bool updateFlags (flags_type flags, bool skip_self=false) const
 Replaces all flags with the passed flags. Only for an owner can call this function successful. Emits event veFlagsChange when a change in flags occurred.
 
flags_type getFlags () const
 Gets the flags at the time the instance was created.
 
flags_type getCurFlags () const
 Gets the current flags for this instance.
 
bool setConvertValues (const std::string &unit, const Value &multiplier, const Value &offset, int digits=std::numeric_limits< int >::max()) const
 Sets the global conversion values and signals the clients. Only with owners a call is successful and effective. The formula is: converted = (current * multiplier) + offset When successful event veConverted emitted.
 
bool setConvertValues (bool convert=true) const
 Enables or disables unit conversion. Only owners can make this call successfully.
Depending on the globally set handler using setConvertHandler() this function calls the handler with event veConvert which then should apply the conversion values using setConvertValues() on the 'call_var' passed.
When the global conversion handler has not been set the Makes a call to the unit conversion interface and tries to get conversion values from it.
When the global conversion handler not set it uses the locally available conversion values.
 
id_type getId () const
 Gets the current attached ID.
 
id_type getDesiredId () const
 Gets the desired id of this instance.
 
std::string getName (int levels=0) const
 Gets the name or a part of the name of the attached variable. Returns the variable name which is default (level 0) the full variable path name. When levels is 'n' and larger than zero the last 'n' levels are returned. When levels is 'n' and smaller than zero the first 'n' levels are omitted.
 
int getNameLevelCount () const
 Gets the amount of levels of the full name path.
 
std::string getUnit () const
 Gets the variable unit.
 
std::string getUnit (bool converted) const
 Gets variable unit of converted or non-converted value.
 
std::string getConvertOption () const
 Gets the conversion option string. This string determines how the value is to be converted when exporting.
 
EStringType getStringType () const
 Gets the string type which is determined by the character(s) in the unit field. The maximum length is determined by the round value in the setup string.
 
std::string getDescription () const
 Gets the purpose description of the attached variable.
 
bool isFlag (int flag) const
 Gets if a flag or flags has been set currently.
 
std::string getCurFlagsString () const
 Gets the current flags in a std::string form.
 
std::string getFlagsString () const
 Gets the flags at setup in a std::string form.
 
bool isReadOnly () const
 Checks if variable is allowed to change its value.
 
int getSigDigits () const
 Gets the normalized decimal point location for this instance.
 
int getSigDigits (bool converted) const
 Gets the normalized decimal point location for this instance converted or not converted.
 
int getRequiredDigits () const
 Gets the required digits for this instance based on round, min and max values. Converted or not the value is the same. This method is useful for drawing a scale using numberString()
 
const ValuegetDef () const
 Gets the variable default value. Is converted when converted flag is true.
 
const ValuegetMin () const
 Gets the variable Minimum value. Is converted when converted flag is true.
 
const ValuegetMax () const
 Gets the variable Maximum value. Is converted when converted flag is true.
 
const ValuegetRnd () const
 Gets the variable Rounding value. Converted when converted flag is true.
 
const ValuegetCur () const
 Gets the variable current value. Is converted when converted flag is true.
 
const ValuegetDef (bool converted) const
 Gets the default value converted or not Is converted independent of the conversion flag.
 
const ValuegetMin (bool converted) const
 Gets the Minimum value converted or not converted independent of the conversion flag.
 
const ValuegetMax (bool converted) const
 Gets the Maximum value converted or not converted independent of the conversion flag.
 
const ValuegetRnd (bool converted) const
 Gets the Rounding value converted or not converted independent of the conversion flag.
 
const ValuegetCur (bool converted) const
 Gets the current value converted or not converted independent of the conversion flag.
 
const State::Vector & getStates () const
 Gets the complete state vector as a reference.
 
size_type getUsageCount () const
 Gets the usage count of this variable reference.
 
size_type getStateCount () const
 Gets the state count.
 
size_type getState (const Value &v) const
 Gets the state index of passed value when it exists.
 
std::string getStateName (size_type state) const
 Gets the display name of the passed state's index.
 
const ValuegetStateValue (size_type state) const
 Gets the value of the passed state index.
 
Value::EType getType () const
 Gets current type enumerate of this variable instance.
 
Variableoperator= (const Variable &v)
 Assignment operator that attaches this instance to the same VariableReference as 'v'.
 
int operator== (const Variable &v) const
 Comparison operator.
 
std::string getCurString (bool use_states=true) const
 Gets current converted value in default formatted string or state. When a temporary value is used that value is returned.
 
std::string getSetupString () const
 Gets the setup std::string for this variable.
 
void clipRound (Value &value) const
 Clips the passed value between min and max values.
 
Value convert (const Value &value, bool to_org=false) const
 Gets the passed value converted to new units or back again.
 
bool writeUpdate (std::ostream &os) const
 Writes id and current value and flags to the stream.
 
bool write (std::ostream &os) const
 Writes id and current value to the stream.
 
void operator delete (void *)
 During events no instances should be deleted. The destructor will be called but the data still exist.
 
- Public Member Functions inherited from sf::InformationBase
virtual ~InformationBase ()=default
 Virtual destructor so derived classes can be destroyed by a pointer of this type.
 
- Public Member Functions inherited from sf::InformationTypes
template<typename T >
constexpr std::enable_if_t<(sizeof(T)<=sizeof(data_type)), data_typetoDataType (T value) const
 Casts any type to a data_type value.
 
template<typename T >
constexpr std::enable_if_t<(sizeof(T)<=sizeof(data_type)), T > fromDataType (data_type value) const
 Casts a data_type value to a given type.
 

Static Public Member Functions

static void initialize ()
 Must be called to initialize the statics which this class depends on.
 
static void uninitialize ()
 Called when terminating the application.
 
static void setConvertHandler (VariableHandler *handler)
 Special handler for converting float variables globally. Sets an event handler for this variable, passing NULL wil disable the handler.
 
static VariableHandlergetConvertHandler ()
 Gets the link to the global conversion handler.
 
static std::string filterString (const std::string &str, EStringType type, size_t max_len)
 Filters the passed string according the given type.
 
static std::string_view getStringType (EStringType type)
 Gets the description string for passed string type.
 
static EStringType getStringType (const std::string &flags)
 Gets the string type value of the passed string.
 
static Value::EType getType (std::string_view type)
 Gets enumerate value of the passed string.
 
static std::string getType (Value::EType type)
 Gets type string of given enumerate value.
 
static size_type getCount ()
 Gets the amount of variables having different ID's in the system.
 
static size_type getInstanceCount (bool global_only=true)
 Gets the total amount of variable instances in the system.
 
static PtrVector getList ()
 Retrieves a list of instances available (global + exported). Useful in populating a selection dialog.
 
static std::string getFieldName (int field)
 Gets the name of the passed field enumerate EField.
 
static const VariablegetInstanceById (id_type id)
 Gets variable with the given id. When not found it returns the zero variable.
 
static VariablegetInstanceById (id_type id, PtrVector &list)
 Gets variable with the given id. When not found it returns the zero variable.
 
static const VariablegetInstanceById (id_type id, const PtrVector &list)
 Gets variable with the given id. When not found it returns the zero variable.
 
static bool readUpdate (std::istream &is, bool skip_self=false, PtrVector &list=null_ref< PtrVector >())
 load single current value and flags from stream. If 'list' is other than the default that list is used to seek the according variable instead of the global list.
 
static Definition getDefinition (const std::string &str)
 
static bool read (std::istream &is, bool skip_self=false, PtrVector &list=null_ref< PtrVector >())
 
static bool create (std::istream &is, PtrVector &list=null_ref< PtrVector >(), bool global=true, int &err_line=null_ref< int >())
 Reads multiple variable setup strings from stream separated by newline characters. Gets true when no error occurred during the process. On error returns false and line returns the error line in the stream. If 'list' is other than a NULL_REF the created variables are added to that list.
 
static flags_type toFlags (const std::string &flags)
 Converts a std::string with flag characters to an integer.
 
static std::string getFlagsString (flags_type flags)
 Gets the passed flags in a std::string form.
 
static std::string_view getEventName (EEvent event)
 Gets the event name to make debugging easier.
 

Protected Member Functions

 Variable (bool global)
 Creates global or local variable instance depending on the value passed.
 

Friends

class VariableHandler
 
class VariableReference
 
class VariableStatic
 

Additional Inherited Members

- Public Types inherited from sf::VariableTypes
enum  EEvent : int {
  veConvert = 64000 , veNewId = -32000 , veUserGlobal , veFirstLocal = 0 ,
  veFlagsChange = 1 , veValueChange = 2 , veInvalid = 3 , veConverted = 4 ,
  veUserLocal = 5 , veFirstPrivate = 16000 , veIdChanged = 16001 , veDesiredId = 16002 ,
  veRemove = 16003 , veGetOwner = 16004 , veLostOwner = 16005 , veLinked = 16006 ,
  veUnlinked = 16007 , veSetup = 16008 , veUserPrivate = 16009
}
 Events send to the handler set with sf::Variable::setHandler. More...
 
enum  EField : int {
  vfId = 0 , vfName , vfUnit , vfFlags ,
  vfDescription , vfType , vfConversionType , vfRound ,
  vfDefault , vfMinimum , vfMaximum , vfFirstState
}
 Enumeration of the order of fields in the setup string. More...
 
enum  EFlag : flags_type {
  flgReadonly = 1 << 0 , flgArchive = 1 << 1 , flgShare = 1 << 2 , flgLink = 1 << 3 ,
  flgFunction = 1 << 4 , flgParameter = 1 << 5 , flgHidden = 1 << 6 , flgExport = 1 << 7 ,
  flgWriteable = 1 << 8
}
 Enumeration type for specifying flags. More...
 
enum  EStringType : int {
  stNormal = 0 , stMulti , stPath , stDirectory ,
  stFilename , stSubdirectory
}
 Enumeration of string types used for filtering. More...
 
typedef TVector< Variable * > PtrVector
 Vector for pointers to variables.
 
typedef TVector< VariableVector
 Vector for instances of variables.
 
typedef TVector< VariableReference * > ReferenceVector
 Types for internal use.
 
- Public Types inherited from sf::InformationTypes
typedef unsigned long long id_type
 Type used for the identifying integer (64-bits).
 
typedef int32_t flags_type
 Type used for the flag integer.
 
typedef size_t size_type
 Type used for size of vectors.
 
typedef uint64_t data_type
 Type used for containing a single data element which is the largest integer.
 
typedef int64_t sdata_type
 Type used for containing a single data element which is the largest signed integer.
 
typedef TVector< id_typeIdVector
 Vector for lists of information ID's.
 
typedef TVector< InformationBase * > Vector
 Vector for containing different information base derived classes.
 
- Static Public Attributes inherited from sf::InformationTypes
static constexpr size_t npos = std::numeric_limits<size_type>::max()
 Unsigned size value indicating not found or no index.
 

Detailed Description

Class for creating and referencing global or local created parameters or settings called variables. This class allows linking of member functions of other classes to handle events generated. See the Example on how to use this class and the 'TVariableHandler' template class.

Constructor & Destructor Documentation

◆ Variable() [1/6]

sf::Variable::Variable ( )

Default constructor for a default global variable.

◆ Variable() [2/6]

sf::Variable::Variable ( const Variable v)
inline

Copy constructor. Copies also the Desired ID data member.

◆ Variable() [3/6]

sf::Variable::Variable ( id_type  id,
bool  set_desired 
)
inline

Creates an instance having a reference with 'id'.

Parameters
idIdentifying number.
set_desiredWhen true the desired id data member is set to the passed id as well.

◆ Variable() [4/6]

sf::Variable::Variable ( const std::string &  definition,
id_type  id_ofs = 0 
)
explicit

Creates a variable according to the definition std::string passed to it. The "id" from the definition string is the passed id offset added to form a final id. This used when instances are created from resource strings for multiple instances of the same module.

Parameters
definitionDefinition string.
id_ofsoffset for the 'id'.

◆ Variable() [5/6]

sf::Variable::Variable ( const Definition def,
id_type  id_ofs = 0 
)
inlineexplicit

Creates a variable using the passed definition structure.

Parameters
defDefinition structure.
id_ofsoffset for the 'id'.

◆ ~Variable()

sf::Variable::~Variable ( )
override

Virtual destructor.

◆ Variable() [6/6]

sf::Variable::Variable ( bool  global)
explicitprotected

Creates global or local variable instance depending on the value passed.

Parameters
globalTrue when global, false when local.

Member Function Documentation

◆ applyTemporary()

bool sf::Variable::applyTemporary ( bool  skip_self = true) const

Applies the temporary value of this instance. Used mainly in dialogs to apply the changed value to become the actual current one. The 'skip_self' flag is set to true by default because an event was already sent using setCur().

Parameters
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when the value was actually a change.

◆ clipRound()

void sf::Variable::clipRound ( Value value) const

Clips the passed value between min and max values.

Parameters
valueValue to be clipped.

◆ convert()

Value sf::Variable::convert ( const Value value,
bool  to_org = false 
) const

Gets the passed value converted to new units or back again.

Parameters
valueValue to be converted.
to_orgDirection of conversion.
Returns
Converted value.

◆ create()

static bool sf::Variable::create ( std::istream &  is,
PtrVector list = null_refPtrVector >(),
bool  global = true,
int &  err_line = null_ref< int >() 
)
static

Reads multiple variable setup strings from stream separated by newline characters. Gets true when no error occurred during the process. On error returns false and line returns the error line in the stream. If 'list' is other than a NULL_REF the created variables are added to that list.

Parameters
is
list
global
err_line
Returns
True when no errors occurred while reading/creating.

◆ emitEvent()

size_type sf::Variable::emitEvent ( EEvent  event,
bool  skip_self = false 
)

Initiate event for all instances of this variable depending on the event value. Returns the amount of effected variables by this call.

Parameters
event
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
Amount of events emitted.

◆ filterString()

static std::string sf::Variable::filterString ( const std::string &  str,
EStringType  type,
size_t  max_len 
)
static

Filters the passed string according the given type.

Parameters
strString to filter.
typeString type.
max_lenMaximum length of the string when non-zero.
Returns
Filtered string.

◆ getConvertHandler()

static VariableHandler * sf::Variable::getConvertHandler ( )
static

Gets the link to the global conversion handler.

◆ getConvertOption()

std::string sf::Variable::getConvertOption ( ) const

Gets the conversion option string. This string determines how the value is to be converted when exporting.

Returns
Option string.

◆ getCount()

static size_type sf::Variable::getCount ( )
static

Gets the amount of variables having different ID's in the system.

Returns
Amount of instances.

◆ getCur() [1/2]

const Value & sf::Variable::getCur ( ) const

Gets the variable current value. Is converted when converted flag is true.

Returns
Temporary value when it is used.

◆ getCur() [2/2]

const Value & sf::Variable::getCur ( bool  converted) const

Gets the current value converted or not converted independent of the conversion flag.

Parameters
convertedTrue when getting the converted value.
Returns
Does not return the temporary value when it is used.

◆ getCurFlags()

flags_type sf::Variable::getCurFlags ( ) const

Gets the current flags for this instance.

Returns
Set of EFlag bits.

◆ getCurFlagsString()

std::string sf::Variable::getCurFlagsString ( ) const

Gets the current flags in a std::string form.

Returns
Flags as a string.

◆ getCurString()

std::string sf::Variable::getCurString ( bool  use_states = true) const

Gets current converted value in default formatted string or state. When a temporary value is used that value is returned.

Parameters
use_statesDetermines if a state string name is to be used.
Returns
String of the value.

◆ getData()

template<typename T >
T sf::Variable::getData ( ) const

Gets the data for this instance for user purposes Set with setData().

Template Parameters
TType of the data being retrieved.
Returns
Could be a pointer cast value.

◆ getDef() [1/2]

const Value & sf::Variable::getDef ( ) const

Gets the variable default value. Is converted when converted flag is true.

Returns

◆ getDef() [2/2]

const Value & sf::Variable::getDef ( bool  converted) const

Gets the default value converted or not Is converted independent of the conversion flag.

Parameters
convertedTrue when getting the converted value.

◆ getDefinition()

static Definition sf::Variable::getDefinition ( const std::string &  str)
static

Fills a definition structure from a string. On failure the _valid field is set to false.

Parameters
strDefinition string
Returns
Definition structure

◆ getDescription()

std::string sf::Variable::getDescription ( ) const

Gets the purpose description of the attached variable.

Returns
Description string.

◆ getDesiredId()

Variable::id_type sf::Variable::getDesiredId ( ) const
inline

Gets the desired id of this instance.

Returns
Desired id.

◆ getEventName()

static std::string_view sf::Variable::getEventName ( EEvent  event)
static

Gets the event name to make debugging easier.

Parameters
eventThe event enumerate/number.
Returns
Event name.

◆ getFieldName()

static std::string sf::Variable::getFieldName ( int  field)
static

Gets the name of the passed field enumerate EField.

Returns
Field string.

◆ getFlags()

flags_type sf::Variable::getFlags ( ) const

Gets the flags at the time the instance was created.

Returns
Set of EFlag bits.

◆ getFlagsString() [1/2]

std::string sf::Variable::getFlagsString ( ) const

Gets the flags at setup in a std::string form.

Returns
Flags as a string.

◆ getFlagsString() [2/2]

static std::string sf::Variable::getFlagsString ( flags_type  flags)
static

Gets the passed flags in a std::string form.

Parameters
flags
Returns

◆ getHandler()

VariableHandler * sf::Variable::getHandler ( ) const
inline

Gets the link set by setHandler().

Returns
Link instance pointer

◆ getId()

id_type sf::Variable::getId ( ) const

Gets the current attached ID.

Returns
The id of the current attached variable.

◆ getInstanceById() [1/3]

static const Variable & sf::Variable::getInstanceById ( id_type  id)
static

Gets variable with the given id. When not found it returns the zero variable.

Parameters
idVariable id to seek.
Returns
When not found always zero variable.

◆ getInstanceById() [2/3]

const Variable & sf::Variable::getInstanceById ( id_type  id,
const PtrVector list 
)
inlinestatic

Gets variable with the given id. When not found it returns the zero variable.

Parameters
idVariable id to seek.
listVector to use for lookup.
Returns
When not found always zero variable.

◆ getInstanceById() [3/3]

static Variable & sf::Variable::getInstanceById ( id_type  id,
PtrVector list 
)
static

Gets variable with the given id. When not found it returns the zero variable.

Parameters
idVariable id to seek.
listVector to use for lookup.
Returns
When not found always zero variable.

◆ getInstanceCount()

static size_type sf::Variable::getInstanceCount ( bool  global_only = true)
static

Gets the total amount of variable instances in the system.

Parameters
global_onlyWhen true, count only the global ones.
Returns
Amount of instances.

◆ getList()

static PtrVector sf::Variable::getList ( )
static

Retrieves a list of instances available (global + exported). Useful in populating a selection dialog.

Returns
Vector of instance pointers.

◆ getMax() [1/2]

const Value & sf::Variable::getMax ( ) const

Gets the variable Maximum value. Is converted when converted flag is true.

◆ getMax() [2/2]

const Value & sf::Variable::getMax ( bool  converted) const

Gets the Maximum value converted or not converted independent of the conversion flag.

Parameters
convertedTrue when getting the converted value.
Returns

◆ getMin() [1/2]

const Value & sf::Variable::getMin ( ) const

Gets the variable Minimum value. Is converted when converted flag is true.

◆ getMin() [2/2]

const Value & sf::Variable::getMin ( bool  converted) const

Gets the Minimum value converted or not converted independent of the conversion flag.

Parameters
convertedTrue when getting the converted value.

◆ getName()

std::string sf::Variable::getName ( int  levels = 0) const

Gets the name or a part of the name of the attached variable. Returns the variable name which is default (level 0) the full variable path name. When levels is 'n' and larger than zero the last 'n' levels are returned. When levels is 'n' and smaller than zero the first 'n' levels are omitted.

Parameters
levelsAmount of required levels.
Returns
Full or part of name depending on level.

◆ getNameLevelCount()

int sf::Variable::getNameLevelCount ( ) const

Gets the amount of levels of the full name path.

Returns
Total name levels available.

◆ getOwner()

Variable & sf::Variable::getOwner ( ) const

Gets a reference to the owner/server instance of this variable.

Returns
Owner reference.

◆ getRequiredDigits()

int sf::Variable::getRequiredDigits ( ) const

Gets the required digits for this instance based on round, min and max values. Converted or not the value is the same. This method is useful for drawing a scale using numberString()

Returns
Amount of digits.

◆ getRnd() [1/2]

const Value & sf::Variable::getRnd ( ) const

Gets the variable Rounding value. Converted when converted flag is true.

◆ getRnd() [2/2]

const Value & sf::Variable::getRnd ( bool  converted) const

Gets the Rounding value converted or not converted independent of the conversion flag.

Parameters
convertedTrue when getting the converted value.
Returns

◆ getSetupString()

std::string sf::Variable::getSetupString ( ) const

Gets the setup std::string for this variable.

◆ getSigDigits() [1/2]

int sf::Variable::getSigDigits ( ) const

Gets the normalized decimal point location for this instance.

Returns
Amount of digits.

◆ getSigDigits() [2/2]

int sf::Variable::getSigDigits ( bool  converted) const

Gets the normalized decimal point location for this instance converted or not converted.

Parameters
convertedTrue when needing the converted amount.
Returns
Amount of digits.

◆ getState()

size_type sf::Variable::getState ( const Value v) const

Gets the state index of passed value when it exists.

Parameters
vValue to lookup.
Returns
Valid index and when it does not exist it returns npos.

◆ getStateCount()

size_type sf::Variable::getStateCount ( ) const

Gets the state count.

Returns
Amount of states.

◆ getStateName()

std::string sf::Variable::getStateName ( size_type  state) const

Gets the display name of the passed state's index.

Parameters
stateIndex of the state.
Returns
Display name.

◆ getStates()

const State::Vector & sf::Variable::getStates ( ) const

Gets the complete state vector as a reference.

◆ getStateValue()

const Value & sf::Variable::getStateValue ( size_type  state) const

Gets the value of the passed state index.

Parameters
stateIndex of the state.
Returns
Value of the passed state index.

◆ getStringType() [1/3]

EStringType sf::Variable::getStringType ( ) const

Gets the string type which is determined by the character(s) in the unit field. The maximum length is determined by the round value in the setup string.

Returns
Enumerate value of EStringType

◆ getStringType() [2/3]

static EStringType sf::Variable::getStringType ( const std::string &  flags)
static

Gets the string type value of the passed string.

Parameters
flagsString containing flag(s)
Returns
The enumerate type of the string.

◆ getStringType() [3/3]

static std::string_view sf::Variable::getStringType ( EStringType  type)
static

Gets the description string for passed string type.

Parameters
typeEnumerate value.
Returns
Name of the string type.

◆ getType() [1/3]

Value::EType sf::Variable::getType ( ) const

Gets current type enumerate of this variable instance.

Returns
Enumerate type value.

◆ getType() [2/3]

Value::EType sf::Variable::getType ( std::string_view  type)
inlinestatic

Gets enumerate value of the passed string.

Parameters
typeString representing the type.
Returns
Enumerate type value.

◆ getType() [3/3]

std::string sf::Variable::getType ( Value::EType  type)
inlinestatic

Gets type string of given enumerate value.

Parameters
typeEnumerate type.
Returns
String of the type.

◆ getUnit() [1/2]

std::string sf::Variable::getUnit ( ) const

Gets the variable unit.

Returns
Unit string.

◆ getUnit() [2/2]

std::string sf::Variable::getUnit ( bool  converted) const

Gets variable unit of converted or non-converted value.

Parameters
convertedTrue when getting the converted value.
Returns
Unit string.

◆ getUsageCount()

size_type sf::Variable::getUsageCount ( ) const

Gets the usage count of this variable reference.

Returns

◆ increase()

bool sf::Variable::increase ( int  steps,
bool  skip_self = false 
)

Increase current variable value by step increments also negative values. Emits event veValueChange when a change is flags occurred.

Parameters
stepsAmount of increments (>0) or decrements (<0)
skip_selfSkip event on this instance.
Returns
True if this function made a difference.

◆ initialize()

static void sf::Variable::initialize ( )
static

Must be called to initialize the statics which this class depends on.

◆ isConverted()

bool sf::Variable::isConverted ( ) const

Checks if the current instance is converting floating point values.

Returns
True when converting.

◆ isExported()

bool sf::Variable::isExported ( ) const

Checks if the variable is an exported local variable.

Returns
True if exported.

◆ isFlag()

bool sf::Variable::isFlag ( int  flag) const

Gets if a flag or flags has been set currently.

Parameters
flagSingle value or a multiple of EFlag values.
Returns
True when the flag(s) were set.

◆ isGlobal()

bool sf::Variable::isGlobal ( ) const
inline

Check if this instance is a global variable or not.

Returns
True when global.

◆ isNumber()

bool sf::Variable::isNumber ( ) const

Checks if the value is a number or not. Result is true when the value type is either Value::vitFloat or Value::vitInteger.

Returns
True if the current variable value is a number.

◆ isOwner()

bool sf::Variable::isOwner ( ) const

Checks if this instance is the owner of this variable.

Returns
True when owner.

◆ isReadOnly()

bool sf::Variable::isReadOnly ( ) const

Checks if variable is allowed to change its value.

Returns
True when readonly.

◆ isTemporary()

bool sf::Variable::isTemporary ( ) const

Checks if a temporary is used instead of current actual value.

Returns
True when temporary is enabled.

◆ isTemporaryDifferent()

bool sf::Variable::isTemporaryDifferent ( ) const

Check if the temporary value differs from the actual value. Used mainly in dialogs to enable an apply button.

Returns
True when different.

◆ isValid()

bool sf::Variable::isValid ( ) const

Checks validity of the attached reference and used after a setup call.

Returns
True if the variable is valid.

◆ loadCur()

bool sf::Variable::loadCur ( const Value value) const

Used in settings loading routines which use the owner to Set a new value. Checks if clients have write access and is global before applying the new value.

Parameters
value
Returns
True on success of making a change.

◆ makeOwner()

void sf::Variable::makeOwner ( )

Makes this instance owner of this variable instance and emits the appropriate events. When the owner really changes instances the new owner handler receives a veGetOwner event and the previous one veLostOwner.

◆ operator delete()

void sf::Variable::operator delete ( void *  )

During events no instances should be deleted. The destructor will be called but the data still exist.

◆ operator=()

Variable & sf::Variable::operator= ( const Variable v)
inline

Assignment operator that attaches this instance to the same VariableReference as 'v'.

◆ operator==()

int sf::Variable::operator== ( const Variable v) const
inline

Comparison operator.

◆ read()

static bool sf::Variable::read ( std::istream &  is,
bool  skip_self = false,
PtrVector list = null_refPtrVector >() 
)
static

load single current values from stream. If 'list' is other than a NULL_REF that list is used to seek the according variable instead of the global list.

Parameters
is
skip_selfWhen 'true' this instance is skipped in emission of events.
list
Returns

◆ readUpdate()

static bool sf::Variable::readUpdate ( std::istream &  is,
bool  skip_self = false,
PtrVector list = null_refPtrVector >() 
)
static

load single current value and flags from stream. If 'list' is other than the default that list is used to seek the according variable instead of the global list.

Parameters
is
skip_selfWhen 'true' this instance is skipped in emission of events.
list
Returns

◆ setConvert()

bool sf::Variable::setConvert ( bool  enable)

Enables or disables conversion of floating point values. If a change was triggered a veConverted event was emitted.

Parameters
enableTo enable pass 'true'. to disable 'false'.
Returns
Value returned by isConverted().

◆ setConvertHandler()

static void sf::Variable::setConvertHandler ( VariableHandler handler)
static

Special handler for converting float variables globally. Sets an event handler for this variable, passing NULL wil disable the handler.

Parameters
handlerHandler from conversion interface.

◆ setConvertValues() [1/2]

bool sf::Variable::setConvertValues ( bool  convert = true) const

Enables or disables unit conversion. Only owners can make this call successfully.
Depending on the globally set handler using setConvertHandler() this function calls the handler with event veConvert which then should apply the conversion values using setConvertValues() on the 'call_var' passed.
When the global conversion handler has not been set the Makes a call to the unit conversion interface and tries to get conversion values from it.
When the global conversion handler not set it uses the locally available conversion values.

Parameters
convertWhen true conversion is enabled and false disabled.
Returns
True on success of getting the values.

◆ setConvertValues() [2/2]

bool sf::Variable::setConvertValues ( const std::string &  unit,
const Value multiplier,
const Value offset,
int  digits = std::numeric_limits< int >::max() 
) const

Sets the global conversion values and signals the clients. Only with owners a call is successful and effective. The formula is: converted = (current * multiplier) + offset When successful event veConverted emitted.

Parameters
unitNew unit string.
multiplierMultiplier value.
offsetoffset value.
digitsSignificant digits for the new unit.
Returns

◆ setCur() [1/2]

bool sf::Variable::setCur ( const Value value,
bool  skip_self = false 
)

Both return true if there was a change and notify all variables of the same variable id through an event.

Parameters
valueSets a new current value.
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when the value was actually changed.

◆ setCur() [2/2]

bool sf::Variable::setCur ( const Value value,
bool  skip_self = false 
) const
inline

Same as setCur() but for const instances objects of this instance.

Parameters
valueSets a new current value.
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when the value was actually changed.

◆ setData()

template<typename T >
void sf::Variable::setData ( data)

Sets the data for this instance for user purposes.

Template Parameters
TType of the data being set.
Parameters
dataCould be a pointer cast value.

◆ setDesiredId() [1/2]

void sf::Variable::setDesiredId ( )

Sets the desired id member variable to the current attached reference id.

◆ setDesiredId() [2/2]

void sf::Variable::setDesiredId ( id_type  id)

Sets the desired id member variable to the passed id. If the passed 'id' is zero the automatic attachment mechanism is disabled.

◆ setExport()

bool sf::Variable::setExport ( bool  global)

Makes an owning local variable appear globally. Useful when reading/creating instances from stored files. First as local instances and then making them global.

Parameters
globalTrue to export as global and False to revert it.
Returns
True on success.

◆ setFlag()

bool sf::Variable::setFlag ( flags_type  flag,
bool  skip_self = false 
) const

Sets a flag or multiple flags on the reference. Only for an owner can call this function successful. Emits event veFlagsChange when a change in flags occurred.

Parameters
flagSingle or multiple values of EFlag.
skip_selfSkip event on this instance.
Returns
True when a change was made.

◆ setGlobal()

bool sf::Variable::setGlobal ( bool  global)

Sets the variable to be global. This can only happen if it attached to Zero Variable so when the id is zero.

Parameters
globalTrue when global and False when local.
Returns
True on success.

◆ setHandler()

void sf::Variable::setHandler ( VariableHandler handler)

Only one link is available at a time. Sets an event handler for this variable, passing NULL wil disable the link.

Parameters
handler

◆ setId()

bool sf::Variable::setId ( id_type  id,
bool  skip_self = false 
) const

Only for local non exported owning variables to set the id after setup is called using a string. The id can not be zero and attached local variables are notify with a veNewId event.

Parameters
idVariable identifier
skip_selfWhen false the event to its own handler is skipped to be emitted.
Returns
True on success.

◆ setTemporary()

void sf::Variable::setTemporary ( bool  on_off)

When true is passed a local temporary value is used instead of current.

Parameters
on_off

◆ setup() [1/4]

bool sf::Variable::setup ( const Definition definition,
id_type  id_ofs = 0 
)

Creates a variable using the definition structure.

Parameters
definitionDefinition structure.
id_ofsoffset for the 'id'.
Returns
True on success.

◆ setup() [2/4]

bool sf::Variable::setup ( const std::string &  definition,
id_type  id_ofs = 0 
)
inline

Creates a variable according to the definition std::string passed to it. The passed identifier offset 'id_ofs' is added to the id in the string. This used when instances are created from resource strings for multiple instances of the same module.

Parameters
definitionComma separated definition string.
id_ofsoffset for the 'id'.
Returns
True on success.

◆ setup() [3/4]

bool sf::Variable::setup ( const Variable v)
inline

Sets reference to other variable. This is the only way for local variables.

Parameters
v
Returns

◆ setup() [4/4]

bool sf::Variable::setup ( id_type  id,
bool  set_did = false 
)
inline

Sets reference to other by id. The global list of references is searched for the passed id and referenced when found. When found event veIdChanged is emitted. When the desired id was set and changed the veDesiredId event is emitted. Cannot be used for local variables.

Parameters
idIdentifier.
set_didWhen true the desired id is set to the passed 'id'.
Returns
True when found and referenced.

◆ toFlags()

static flags_type sf::Variable::toFlags ( const std::string &  flags)
static

Converts a std::string with flag characters to an integer.

Parameters
flags
Returns

◆ uninitialize()

static void sf::Variable::uninitialize ( )
static

Called when terminating the application.

◆ unsetFlag()

bool sf::Variable::unsetFlag ( flags_type  flag,
bool  skip_self = false 
) const

Unsets a flag or multiple flags of the attached VariableReference. Emits event veValueChange when a change in flags occurred.

Parameters
flagSingle or multiple values of EFlag.
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when a change was made.

◆ updateFlags()

bool sf::Variable::updateFlags ( flags_type  flags,
bool  skip_self = false 
) const

Replaces all flags with the passed flags. Only for an owner can call this function successful. Emits event veFlagsChange when a change in flags occurred.

Parameters
flagsSingle or multiple values of EFlag.
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when a change was made.

◆ updateTemporary()

bool sf::Variable::updateTemporary ( bool  skip_self = false)

Updates the temporary value with the real value.

Used mainly in dialogs to update the temporary value with real/actual value.

Parameters
skip_selfWhen 'true' this instance is skipped in emission of events.
Returns
True when a change was caused.

◆ write()

bool sf::Variable::write ( std::ostream &  os) const

Writes id and current value to the stream.

Parameters
os
Returns

◆ writeUpdate()

bool sf::Variable::writeUpdate ( std::ostream &  os) const

Writes id and current value and flags to the stream.

Friends And Related Symbol Documentation

◆ VariableHandler

friend class VariableHandler
friend

◆ VariableReference

friend class VariableReference
friend

◆ VariableStatic

friend class VariableStatic
friend

The documentation for this class was generated from the following file: