StateVariables make up the persistent state of Component objects. More...
#include <StateVariable.h>
Public Types | |
enum | Type { String = 0, Bool, Double, UInt8, UInt16, UInt32, UInt64, SInt8, SInt16, SInt32, SInt64, Custom } |
An enumeration of the possible types of a StateVariable. More... | |
Public Member Functions | |
StateVariable (const string &name, string *ptrToString) | |
Constructor for a String StateVariable. More... | |
StateVariable (const string &name, bool *ptrToVar) | |
Constructor for a Bool StateVariable. More... | |
StateVariable (const string &name, double *ptrToVar) | |
Constructor for a Double StateVariable. More... | |
StateVariable (const string &name, uint8_t *ptrToVar) | |
Constructor for a UInt8 StateVariable. More... | |
StateVariable (const string &name, uint16_t *ptrToVar) | |
Constructor for a UInt16 StateVariable. More... | |
StateVariable (const string &name, uint32_t *ptrToVar) | |
Constructor for a UInt32 StateVariable. More... | |
StateVariable (const string &name, uint64_t *ptrToVar) | |
Constructor for a UInt64 StateVariable. More... | |
StateVariable (const string &name, int8_t *ptrToVar) | |
Constructor for a SInt8 StateVariable. More... | |
StateVariable (const string &name, int16_t *ptrToVar) | |
Constructor for a SInt16 StateVariable. More... | |
StateVariable (const string &name, int32_t *ptrToVar) | |
Constructor for a SInt32 StateVariable. More... | |
StateVariable (const string &name, int64_t *ptrToVar) | |
Constructor for a SInt64 StateVariable. More... | |
StateVariable (const string &name, CustomStateVariableHandler *ptrToHandler) | |
Constructor for a custom StateVariable. More... | |
const string & | GetName () const |
Gets the name of the variable. More... | |
enum Type | GetType () const |
Gets the type of the variable. More... | |
void | SerializeValue (ostream &ss) const |
Serializes the variable value into a string. More... | |
void | Serialize (ostream &ss, SerializationContext &context) const |
Serializes the variable into a string. More... | |
bool | CopyValueFrom (const StateVariable &otherVariable) |
Copy the value from another variable into this variable. More... | |
string | ToString () const |
Returns the variable as a readable string. More... | |
uint64_t | ToInteger () const |
Returns the variable as an unsignedinteger value. More... | |
double | ToDouble () const |
Returns the variable as a double value. More... | |
bool | SetValue (const string &expression) |
Set the variable's value, using a string expression. More... | |
bool | SetValue (uint64_t value) |
Set the variable's value to an integer. More... | |
Static Public Member Functions | |
static void | RunUnitTests (int &nSucceeded, int &nFailures) |
![]() | |
static void | RunUnitTests (int &nSucceeded, int &nFailures) |
Runs unit test cases. More... | |
StateVariables make up the persistent state of Component objects.
A StateVariable has a name, and a value.
Definition at line 67 of file StateVariable.h.
enum StateVariable::Type |
An enumeration of the possible types of a StateVariable.
Enumerator | |
---|---|
String | |
Bool | |
Double | |
UInt8 | |
UInt16 | |
UInt32 | |
UInt64 | |
SInt8 | |
SInt16 | |
SInt32 | |
SInt64 | |
Custom |
Definition at line 74 of file StateVariable.h.
StateVariable::StateVariable | ( | const string & | name, |
string * | ptrToString | ||
) |
Constructor for a String StateVariable.
name | The variable's name. |
ptrToString | A pointer to the string which this variable refers to. |
Definition at line 36 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
bool * | ptrToVar | ||
) |
Constructor for a Bool StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 44 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
double * | ptrToVar | ||
) |
Constructor for a Double StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 52 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
uint8_t * | ptrToVar | ||
) |
Constructor for a UInt8 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 60 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
uint16_t * | ptrToVar | ||
) |
Constructor for a UInt16 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 68 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
uint32_t * | ptrToVar | ||
) |
Constructor for a UInt32 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 76 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
uint64_t * | ptrToVar | ||
) |
Constructor for a UInt64 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 84 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
int8_t * | ptrToVar | ||
) |
Constructor for a SInt8 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 92 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
int16_t * | ptrToVar | ||
) |
Constructor for a SInt16 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 100 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
int32_t * | ptrToVar | ||
) |
Constructor for a SInt32 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 108 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
int64_t * | ptrToVar | ||
) |
Constructor for a SInt64 StateVariable.
name | The variable's name. |
ptrToVar | A pointer to the variable. |
Definition at line 116 of file StateVariable.cc.
StateVariable::StateVariable | ( | const string & | name, |
CustomStateVariableHandler * | ptrToHandler | ||
) |
Constructor for a custom StateVariable.
name | The variable's name. |
ptrToHandler | A pointer to the custom handler. |
Definition at line 124 of file StateVariable.cc.
bool StateVariable::CopyValueFrom | ( | const StateVariable & | otherVariable | ) |
Copy the value from another variable into this variable.
otherVariable | The variable to copy from. |
Definition at line 177 of file StateVariable.cc.
References Bool, Custom, Double, pbool, pdouble, phandler, psint16, psint32, psint64, psint8, pstr, puint16, puint32, puint64, puint8, SInt16, SInt32, SInt64, SInt8, String, UInt16, UInt32, UInt64, and UInt8.
const string & StateVariable::GetName | ( | ) | const |
Gets the name of the variable.
Definition at line 138 of file StateVariable.cc.
Referenced by RootComponent::CheckVariableWrite(), and Component::CheckVariableWrite().
enum StateVariable::Type StateVariable::GetType | ( | ) | const |
Gets the type of the variable.
Definition at line 124 of file StateVariable.cc.
|
static |
void StateVariable::Serialize | ( | ostream & | ss, |
SerializationContext & | context | ||
) | const |
Serializes the variable into a string.
ss | A stream where the variable (type, name, and value) will be appended. |
context | Serialization context (tab indentation, etc). |
Definition at line 383 of file StateVariable.cc.
References SerializeValue(), and SerializationContext::Tabs().
void StateVariable::SerializeValue | ( | ostream & | ss | ) | const |
Serializes the variable value into a string.
Strings are serialized as quoted strings; most other types without quoting.
ss | A stream where the variable value will be appended. |
Definition at line 362 of file StateVariable.cc.
References Custom, EscapedString::Generate(), String, and ToString().
Referenced by Serialize(), and Component::SetVariableValue().
bool StateVariable::SetValue | ( | const string & | expression | ) |
Set the variable's value, using a string expression.
Note that the expression may be a single value (e.g. 42
), or something more complex (e.g. 123 + cpu0.pc * 4
).
When setting string values, the expression should be a C-style escaped string, e.g.: "This is a string with a \" inside it."
expression | The new value. |
Definition at line 412 of file StateVariable.cc.
References Bool, Custom, EscapedString::Decode(), Double, StringHelper::ParseNumber(), SInt16, SInt32, SInt64, SInt8, String, UInt16, UInt32, UInt64, and UInt8.
Referenced by Component::SetVariableValue().
bool StateVariable::SetValue | ( | uint64_t | value | ) |
double StateVariable::ToDouble | ( | ) | const |
uint64_t StateVariable::ToInteger | ( | ) | const |
Returns the variable as an unsignedinteger value.
Definition at line 280 of file StateVariable.cc.
References Bool, Custom, Double, SInt16, SInt32, SInt64, SInt8, String, UInt16, UInt32, UInt64, and UInt8.
Referenced by Component::CheckVariableWrite(), BackwardStepCommand::Execute(), MemoryMappedComponent::GenerateDetails(), Component::GenerateDetails(), GXemul::GetStep(), and FileLoader_aout::LoadIntoComponent().
string StateVariable::ToString | ( | ) | const |
Returns the variable as a readable string.
Definition at line 229 of file StateVariable.cc.
References Bool, Custom, Double, SInt16, SInt32, SInt64, SInt8, String, UInt16, UInt32, UInt64, and UInt8.
Referenced by Component::AddChild(), RootComponent::CheckVariableWrite(), Component::DetectChanges(), Component::GenerateDetails(), Component::GeneratePath(), Component::GenerateTreeDump(), and SerializeValue().
bool* StateVariable::pbool |
Definition at line 317 of file StateVariable.h.
Referenced by CopyValueFrom().
double* StateVariable::pdouble |
Definition at line 318 of file StateVariable.h.
Referenced by CopyValueFrom().
CustomStateVariableHandler* StateVariable::phandler |
Definition at line 327 of file StateVariable.h.
Referenced by CopyValueFrom().
int16_t* StateVariable::psint16 |
Definition at line 324 of file StateVariable.h.
Referenced by CopyValueFrom().
int32_t* StateVariable::psint32 |
Definition at line 325 of file StateVariable.h.
Referenced by CopyValueFrom().
int64_t* StateVariable::psint64 |
Definition at line 326 of file StateVariable.h.
Referenced by CopyValueFrom().
int8_t* StateVariable::psint8 |
Definition at line 323 of file StateVariable.h.
Referenced by CopyValueFrom().
string* StateVariable::pstr |
Definition at line 316 of file StateVariable.h.
Referenced by CopyValueFrom().
uint16_t* StateVariable::puint16 |
Definition at line 320 of file StateVariable.h.
Referenced by CopyValueFrom().
uint32_t* StateVariable::puint32 |
Definition at line 321 of file StateVariable.h.
Referenced by CopyValueFrom().
uint64_t* StateVariable::puint64 |
Definition at line 322 of file StateVariable.h.
Referenced by CopyValueFrom().
uint8_t* StateVariable::puint8 |
Definition at line 319 of file StateVariable.h.
Referenced by CopyValueFrom().