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.
 
 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.
 
bool setup (const Definition &definition, Variable::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.
 
bool setId (id_type id, bool skip_self=false)
 Only for local non exported owning variables to set the id after setup is called using a string.
 
bool isValid () const
 Checks validity of the attached reference and used after a setup call.
 
bool isConverted () const
 Returns true is the current instance is converting floating point values.
 
bool setConvert (bool enable)
 Enables or disables conversion of floating point values.
 
bool isNumber () const
 Returns whether the value is a number or not.
 
void makeOwner ()
 Makes this instance owner of this variable instance and emits the appropriate events.
 
VariablegetOwner ()
 Gets a reference to the owner/server instance of this variable.
 
bool isOwner () const
 Returns if this is the owner of this variable.
 
bool isGlobal () const
 Returns true if this instance is a global variable or not.
 
bool setGlobal (bool global)
 Sets the variable to be global.
 
bool setExport (bool global)
 Makes an owning local variable appear globally.
 
bool isExported () const
 Checks if the variable is an exported local variable.
 
bool isTemporary ()
 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)
 Applies the temporary value of this instance.
 
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.
 
void setHandler (VariableHandler *handler)
 Only one link is available at a time.
 
VariableHandlergetHandler () const
 Returns the link Set by setHandler().
 
VariableHandlergetConvertHandler () const
 Returns the link to the global conversion handler.
 
Variable::size_type emitEvent (EEvent event, bool skip_self=false)
 Initiate event for all instances of this variable depending on the event value.
 
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.
 
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.
 
bool increase (int steps, bool skip_self=false)
 Increase current variable value by step increments also negative values.
 
bool unsetFlag (flags_type flag, bool skip_self=false)
 Unsets a flag or multiple flags of the attached VariableReference.
 
bool setFlag (flags_type flag, bool skip_self=false)
 Sets a flag or multiple flags on the reference.
 
bool updateFlags (flags_type flags, bool skip_self=false)
 Replaces all flags with the passed flags.
 
flags_type getFlags () const
 Returns the flags at the time the instance was created.
 
flags_type getCurFlags () const
 Returns 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())
 Sets the global conversion values and signals the clients.
 
bool setConvertValues (bool convert=true)
 Enables or disables unit conversion.
 
id_type getId () const
 Returns the current attached ID.
 
id_type getDesiredId () const
 Returns 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.
 
int getNameLevelCount () const
 Returns the amount of levels of the full name path.
 
std::string getUnit () const
 Returns variable unit.
 
std::string getUnit (bool converted) const
 Returns variable unit of converted or non-converted value.
 
std::string getConvertOption () const
 Returns the conversion option string.
 
EStringType getStringType () const
 The type is determined by the character in the unit field of the setup string.
 
std::string getDescription () const
 Gets the purpose description of the attached variable.
 
bool isFlag (int flag) const
 Returns if a flag or flags has been set.
 
std::string getCurFlagsString () const
 Returns the current flags in a std::string form.
 
std::string getFlagsString () const
 
bool isReadOnly () const
 Returns 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
 Return the variable default value.
 
const ValuegetMin () const
 Return the variable Minimum value.
 
const ValuegetMax () const
 Return the variable Maximum value.
 
const ValuegetRnd () const
 Return the variable Rounding value.
 
const ValuegetCur () const
 Return the variable current value.
 
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
 Returns the complete state vector as a reference.
 
size_type getUsageCount () const
 Returns the usage count of this variable reference.
 
size_type getStateCount () const
 Returns the state count.
 
size_type getState (const Value &v) const
 Returns the state index of passed value when it exists.
 
std::string getStateName (size_type state) const
 Return the display name of the passed state's index.
 
const ValuegetStateValue (size_type state) const
 Return the value of the passed state index.
 
Value::EType getType () const
 Returns 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 states=true) const
 Returns current converted value in default formatted string or state.
 
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
 Returns 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
 
void operator delete (void *)
 
- Public Member Functions inherited from sf::InformationBase
virtual ~InformationBase ()=default
 Virtual destructor so derived classes can be destroyed by a pointer of this 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.
 
static const char * getStringType (EStringType type)
 Gets the name for passed string type.
 
static Value::EType getType (const char *type)
 Returns enumerate value of the passed string.
 
static const char * getType (Value::EType type)
 Returns 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).
 
static std::string getFieldName (int field)
 Gets the name of the passed field enumerate EField.
 
static const VariablegetInstanceById (id_type id)
 Returns variable with the given id.
 
static VariablegetInstanceById (id_type id, PtrVector &list)
 Returns variable with the given id.
 
static const VariablegetInstanceById (id_type id, const PtrVector &list)
 Returns variable with the given id.
 
static bool readUpdate (std::istream &is, bool skip_self=false, PtrVector &list=null_ref< PtrVector >())
 load single current value and flags from stream.
 
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 >())
 
static Variable::flags_type toFlags (const std::string &flags)
 
static std::string getFlagsString (flags_type flags)
 
static const char * getEventName (EEvent event)
 

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
}
 
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
}
 
enum  EStringType : int {
  stNoString = -1 , stNormal = 0 , stMulti , stPath ,
  stDirectory , stFilename , stSubdirectory
}
 
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)

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

Returns 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. Returns 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

◆ emitEvent()

Variable::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.

◆ getConvertHandler()

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

Returns the link to the global conversion handler.

◆ getConvertOption()

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

Returns the conversion option string.

Deprecated:

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

Return 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

Returns the current flags for this instance.

Returns
Set of EFlag bits.

◆ getCurFlagsString()

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

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

Returns
Flags as a string.

◆ getCurString()

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

Returns current converted value in default formatted string or state.

When a temporary value is used that value is returned.

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

◆ getData()

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

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

Returns
Could be a pointer cast value.

◆ getDef() [1/2]

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

Return 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

Returns the desired id of this instance.

Returns
Desired id.

◆ getEventName()

static const char * sf::Variable::getEventName ( EEvent  event)
static

Returns the event name to make debugging easier.

◆ getFieldName()

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

Gets the name of the passed field enumerate EField.

◆ getFlags()

flags_type sf::Variable::getFlags ( ) const

Returns the flags at the time the instance was created.

Returns
Set of EFlag bits.

◆ getFlagsString() [1/2]

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

Returns 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

Returns the passed flags in a std::string form

Parameters
flags
Returns

◆ getHandler()

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

Returns the link Set by setHandler().

Returns
Link instance pointer

◆ getId()

id_type sf::Variable::getId ( ) const

Returns 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

Returns 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

Returns 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

Returns 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

Return 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

Return 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

Returns the amount of levels of the full name path.

Returns
Total name levels available.

◆ getOwner()

Variable & sf::Variable::getOwner ( )

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

Return 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

Returns 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

Returns the state count.

Returns
Amount of states.

◆ getStateName()

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

Return 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

Returns the complete state vector as a reference.

◆ getStateValue()

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

Return the value of the passed state index.

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

◆ getStringType() [1/2]

EStringType sf::Variable::getStringType ( ) const

The type is determined by the character in the unit field of the setup string.

Returns
Enumerate value of EStringType

◆ getStringType() [2/2]

static const char * sf::Variable::getStringType ( EStringType  type)
static

Gets the name for passed string type.

Parameters
typeEnumerate value.
Returns
Name of the string type.

◆ getType() [1/3]

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

Returns type enumerate of this variable instance.

◆ getType() [2/3]

Value::EType sf::Variable::getType ( const char *  type)
inlinestatic

Returns enumerate value of the passed string.

Parameters
type
Returns

◆ getType() [3/3]

const char * sf::Variable::getType ( Value::EType  type)
inlinestatic

Returns type string of given enumerate value.

Parameters
type
Returns

◆ getUnit() [1/2]

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

Returns variable unit.

Returns
unit string.

◆ getUnit() [2/2]

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

Returns 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

Returns 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

Returns true is 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

Returns if a flag or flags has been set.

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

◆ isGlobal()

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

Returns true if this instance is a global variable or not.

Returns
True when global.

◆ isNumber()

bool sf::Variable::isNumber ( ) const

Returns whether 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

Returns if this is the owner of this variable.

Returns
True when owner.

◆ isReadOnly()

bool sf::Variable::isReadOnly ( ) const

Returns if variable is allowed to change its value.

Returns
True when readonly.

◆ isTemporary()

bool sf::Variable::isTemporary ( )

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)

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() 
)

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)
inline

Sets the data for this instance for user purposes.

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 
)

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 
)

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,
Variable::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 Variable::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 
)

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 
)

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: