IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Lib.StringVariableSystem Class Reference

A lightweight system of string-valued variables, with some support to type conversion. More...

+ Inheritance diagram for IG.Lib.StringVariableSystem:
+ Collaboration diagram for IG.Lib.StringVariableSystem:

Public Member Functions

 StringVariableSystem ()
 Constructs a new system of string variables. More...
 
virtual string GetVariable (string varName)
 Returns value of the specified variable, or null if it is not defined. More...
 
virtual void SetVariable (string varName, string varValue)
 Sets the specified variable to the specified value. More...
 
virtual void AddNewVariable (string varName, string varValue)
 Adds a new variable of the specified name and with the specified value (which can be null). More...
 
virtual bool RemoveVariable (string varName)
 Removes a variable with the specified name from the current variable system, and returns a flag indicating whether variable was actually removed. More...
 
virtual int RemoveVariables (params string[] varNames)
 Removes all variables whose names are specified by the argument, and returns the number of variables that were actully been removed. More...
 
virtual bool UnSetVariable (string varName)
 Unsets the variable with the specified name on the current variable system, and returns a flag indicating whether variable was defined. More...
 
virtual bool IsVariableDefined (string varName)
 Returns true if the specified variable is defined, false otherwise. More...
 
virtual string[][] ToArray ()
 Returns array representation of variables that are currently defined on the system. More...
 
virtual void ImportVariables (string[][] variables)
 Imports variables defined in form of two dimensional array. More...
 
virtual void SetVariable (string varName, object varValue)
 Sets the specified variable to the specified value. More...
 
bool TryGetIntegerVariable (string varName, out int varTypedValue)
 Obtains a value of an integer-typed variable of the specified name, if such a variable is defined and its value can be interpreted as an integer. More...
 
int GetIntegerVariable (string varName)
 Returns the value of an integer-valued variable of the specified name. More...
 
bool TryGetDoubleVariable (string varName, out double varTypedValue)
 Obtains a value of a double-typed variable of the specified name, if such a variable is defined and its value can be interpreted as a number of type double. More...
 
double GetDoubleVariable (string varName)
 Returns the value of a double-valued variable of the specified name. More...
 
bool TryGetBooleanVariable (string varName, out bool varTypedValue)
 Obtains a value of a boolean-typed variable of the specified name, if such a variable is defined and its value can be interpreted as a boolean value. More...
 
bool GetBooleanVariable (string varName)
 Returns the value of a boolean-valued variable of the specified name. More...
 
bool GetFlag (string flagName)
 Returns value of the flag with the specified name. More...
 
void SetFlag (string flagName, bool flagValue)
 Sets the flag of the specified name to the specified value. More...
 
virtual void Export (string filePath)
 Saves (serializes) the specified variable system to the specified JSON file. More...
 
virtual void Export (string filePath, bool append)
 Saves (serializes) the specified variable system to the specified JSON file. More...
 
virtual void Import (string filePath)
 Imports variables from the specified variable system in JSON format. More...
 
void PrintVariables ()
 Prints all variables (with their values) defined on the current object. More...
 

Static Public Member Functions

static void SaveJson (StringVariableSystem variableSystem, string filePath)
 Saves (serializes) the specified variable system to the specified JSON file. File is owerwritten if it exists. More...
 
static void SaveJson (StringVariableSystem variableSystem, string filePath, bool append)
 Saves (serializes) the specified variable system to the specified JSON file. If the file already exists, contents either overwrites the file or is appended at the end, dependent on the value of the append flag. More...
 
static void LoadJson (string filePath, ref StringVariableSystem variableSystemRestored)
 Restores (deserializes) a vector from the specified file in JSON format. More...
 
static void ExportDto (StringVariableSystemDto settings, string filePath)
 Saves (serializes) the specified variable system DTO to the specified JSON file. More...
 
static void ExportDto (StringVariableSystemDto variables, string filePath, bool append)
 Saves (serializes) the specified variable system DTO to the specified JSON file. More...
 
static void ImportDto (string filePath, ref StringVariableSystemDto settings)
 Restores (deserializes) variable system DTO from the specified file in JSON format. More...
 
static void TestMisc ()
 Miscellaneous tests. More...
 

Protected Attributes

SortedList< string, string > _variables = new SortedList<string, string>()
 

Properties

object Lock [get]
 This object's central lock object to be used by other object. More...
 
bool SetNullOnImport [get, set]
 Flag indicating whether null variable values are also set when importing variable values. If false then, if some imported variable has null value, this variable will not be set on the current system of variables. This means that the value of eventually existent variable will remain unchanged if variables are imported from another system where this variable is defined but has null value. More...
 
virtual SortedList< string,
string > 
Variables [get]
 
virtual string this[string varName] [get, set]
 Gets or sets value of the specified variable. More...
 
- Properties inherited from IG.Lib.ILockable
object Lock [get]
 

Private Attributes

object _mainLock = new object()
 
bool _setNullOnImport = false
 

Detailed Description

A lightweight system of string-valued variables, with some support to type conversion.

Constructor & Destructor Documentation

IG.Lib.StringVariableSystem.StringVariableSystem ( )
inline

Constructs a new system of string variables.

Member Function Documentation

virtual string IG.Lib.StringVariableSystem.GetVariable ( string  varName)
inlinevirtual

Returns value of the specified variable, or null if it is not defined.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
virtual void IG.Lib.StringVariableSystem.SetVariable ( string  varName,
string  varValue 
)
inlinevirtual

Sets the specified variable to the specified value.

If variable does not exist then it is created, otherwise its value is overwritten.

Parameters
varNameName of the variable to be set. Must not be null or empty string.
varValueValue that is assigned to the variable.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.

Referenced by IG.Lib.StringVariableSystem.TestMisc().

virtual void IG.Lib.StringVariableSystem.AddNewVariable ( string  varName,
string  varValue 
)
inlinevirtual

Adds a new variable of the specified name and with the specified value (which can be null).

If the variable with the specified name already exists then ArgumentException exception is thrown.

Parameters
varNameName of the variable to be added. Must not be null or empty string.
varValueValue that is assigned to the variable.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string, or when the variable with the specified name already exists.
virtual bool IG.Lib.StringVariableSystem.RemoveVariable ( string  varName)
inlinevirtual

Removes a variable with the specified name from the current variable system, and returns a flag indicating whether variable was actually removed.

False is returned but no exception is thrown if the specified variable is not defined.

Parameters
varNameName of the variable to be removed. Must not be null or empty string.
Returns
True if a variable has been removed, false it the specified variable was not defined.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
virtual int IG.Lib.StringVariableSystem.RemoveVariables ( params string[]  varNames)
inlinevirtual

Removes all variables whose names are specified by the argument, and returns the number of variables that were actully been removed.

Parameters
varNamesNames of variables to be removed.
Returns
Number of variables that were actually removed.
virtual bool IG.Lib.StringVariableSystem.UnSetVariable ( string  varName)
inlinevirtual

Unsets the variable with the specified name on the current variable system, and returns a flag indicating whether variable was defined.

If the variable is defined then it is jus tset to null and true is returned.

False is returned but no exception is thrown if the specified variable is not defined.

Parameters
varNameName of the variable to be removed. Must not be null or empty string.
Returns
True if a variable is defined (in which case it is set to null), false it the specified variable was not defined.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
virtual bool IG.Lib.StringVariableSystem.IsVariableDefined ( string  varName)
inlinevirtual

Returns true if the specified variable is defined, false otherwise.

Parameters
varNameName of the variable whose existence is queried. Must not be null or empty string.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
virtual string [][] IG.Lib.StringVariableSystem.ToArray ( )
inlinevirtual

Returns array representation of variables that are currently defined on the system.

Returns
Array whose elements are arrays of two strings, of which the 0-th element is variable name and the 1st element is its value.

Referenced by IG.Lib.StringVariableSystemDtoBase< VariableSystemType >.CopyFromPlain().

virtual void IG.Lib.StringVariableSystem.ImportVariables ( string  variables[][])
inlinevirtual

Imports variables defined in form of two dimensional array.

Parameters
variables
virtual void IG.Lib.StringVariableSystem.SetVariable ( string  varName,
object  varValue 
)
inlinevirtual

Sets the specified variable to the specified value.

If value is null then variable value is set to null, otherwise it is set to object's string representation that is obtained by calling its ToString() method.

If variable does not exist then it is created, otherwise its value is overwritten.

Parameters
varNameName of the variable to be set. Must not be null or empty string.
varValueValue that is assigned to the variable. If the object is null then null is assigned, otherwise string representation of the object obtained by the ToString() method is assigned.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
bool IG.Lib.StringVariableSystem.TryGetIntegerVariable ( string  varName,
out int  varTypedValue 
)
inline

Obtains a value of an integer-typed variable of the specified name, if such a variable is defined and its value can be interpreted as an integer.

Returns a flag indicating whether the value has been successfully obtained.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
True if the value has been successfully obtained, false if not.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
int IG.Lib.StringVariableSystem.GetIntegerVariable ( string  varName)
inline

Returns the value of an integer-valued variable of the specified name.

Exception is thrown if the specified variable does not exist or its string value can not be interpreted as integer.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
Integar value of the specified variable.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string or when a variable with the specified name does not exist or its string value does not represent an integer.
bool IG.Lib.StringVariableSystem.TryGetDoubleVariable ( string  varName,
out double  varTypedValue 
)
inline

Obtains a value of a double-typed variable of the specified name, if such a variable is defined and its value can be interpreted as a number of type double.

Returns a flag indicating whether the value has been successfully obtained.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
True if the value has been successfully obtained, false if not.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.
double IG.Lib.StringVariableSystem.GetDoubleVariable ( string  varName)
inline

Returns the value of a double-valued variable of the specified name.

Exception is thrown if the specified variable does not exist or its string value can not be interpreted as a number of type double.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
Double value of the specified variable.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string or when a variable with the specified name does not exist or its string value does not represent a number of type double.
bool IG.Lib.StringVariableSystem.TryGetBooleanVariable ( string  varName,
out bool  varTypedValue 
)
inline

Obtains a value of a boolean-typed variable of the specified name, if such a variable is defined and its value can be interpreted as a boolean value.

Returns a flag indicating whether the value has been successfully obtained.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
True if the value has been successfully obtained, false if not.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.

References IG.Lib.Util.TryParseBoolean().

bool IG.Lib.StringVariableSystem.GetBooleanVariable ( string  varName)
inline

Returns the value of a boolean-valued variable of the specified name.

Exception is thrown if the specified variable does not exist or its string value can not be interpreted as a boolean value.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Returns
Boolean value of the specified variable.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string or when a variable with the specified name does not exist or its string value does not represent a boolean value.

References IG.Lib.Util.TryParseBoolean().

bool IG.Lib.StringVariableSystem.GetFlag ( string  flagName)
inline

Returns value of the flag with the specified name.

Flag is considered to be false if the variable of the specified flag name is not defined or its string name does not represent a boolean value, or it is the value of the specified variable interpreted as boolean.

Parameters
flagNameName of the flag to be returned.
Returns
Value of the specified flag, i.e. value of the variable named flagName interpreted as boolean, or false if there is no such variable or its value can not be interpreted as boolean.
Exceptions
ArgumentExceptionWhen the specified flag name is null or empty string.
void IG.Lib.StringVariableSystem.SetFlag ( string  flagName,
bool  flagValue 
)
inline

Sets the flag of the specified name to the specified value.

Variable of the specified name is assigned string representation of the specified boolean value.

Parameters
flagNameName of the flag to be set.
flagValueValue to be assigned to the flag of the specified name.
virtual void IG.Lib.StringVariableSystem.Export ( string  filePath)
inlinevirtual

Saves (serializes) the specified variable system to the specified JSON file.

If the file already exists, contents overwrite the file.

Parameters
filePathPath to the file in variables and properties of the system are saved.

Reimplemented in IG.Lib.StringSettings.

virtual void IG.Lib.StringVariableSystem.Export ( string  filePath,
bool  append 
)
inlinevirtual

Saves (serializes) the specified variable system to the specified JSON file.

If the file already exists, contents either overwrite the file or are appended at the end, dependent on the value of the append flag.

Parameters
filePathPath to the file in variables and properties of the system are saved.
appendSpecifies whether serialized data is appended at the end of the file in the case that the file already exists.

Reimplemented in IG.Lib.StringSettings.

References IG.Lib.SerializationDtoBase< Type, BaseType >.CopyFrom().

virtual void IG.Lib.StringVariableSystem.Import ( string  filePath)
inlinevirtual

Imports variables from the specified variable system in JSON format.

Parameters
filePathFile from which object is restored.

Reimplemented in IG.Lib.StringSettings.

static void IG.Lib.StringVariableSystem.SaveJson ( StringVariableSystem  variableSystem,
string  filePath 
)
inlinestatic

Saves (serializes) the specified variable system to the specified JSON file. File is owerwritten if it exists.

Parameters
variableSystemObject that is saved to a file.
filePathPath to the file in which object is is saved.
static void IG.Lib.StringVariableSystem.SaveJson ( StringVariableSystem  variableSystem,
string  filePath,
bool  append 
)
inlinestatic

Saves (serializes) the specified variable system to the specified JSON file. If the file already exists, contents either overwrites the file or is appended at the end, dependent on the value of the append flag.

Parameters
variableSystemObject that is saved to a file.
filePathPath to the file into which object is saved.
appendSpecifies whether serialized data is appended at the end of the file in the case that the file already exists.

References IG.Lib.SerializationDtoBase< Type, BaseType >.CopyFrom().

static void IG.Lib.StringVariableSystem.LoadJson ( string  filePath,
ref StringVariableSystem  variableSystemRestored 
)
inlinestatic

Restores (deserializes) a vector from the specified file in JSON format.

Parameters
filePathFile from which object is restored.
variableSystemRestoredObject that is restored by deserialization.

References IG.Lib.SerializationDtoBase< Type, BaseType >.CopyTo().

static void IG.Lib.StringVariableSystem.ExportDto ( StringVariableSystemDto  settings,
string  filePath 
)
inlinestatic

Saves (serializes) the specified variable system DTO to the specified JSON file.

If the file already exists, contents overwrite the file.

Parameters
settingsVariable system DTO that is saved to a file.
filePathPath to the file into which variables (and settings and other stuff) are saved.
static void IG.Lib.StringVariableSystem.ExportDto ( StringVariableSystemDto  variables,
string  filePath,
bool  append 
)
inlinestatic

Saves (serializes) the specified variable system DTO to the specified JSON file.

If the file already exists, contents either overwrite the file or are appended at the end, dependent on the value of the append flag.

Parameters
variablesVariable system DTO that is saved to a file.
filePathPath to the file into which variables (and settings and other stuff) are saved.
appendSpecifies whether serialized data is appended at the end of the file in the case that the file already exists.
static void IG.Lib.StringVariableSystem.ImportDto ( string  filePath,
ref StringVariableSystemDto  settings 
)
inlinestatic

Restores (deserializes) variable system DTO from the specified file in JSON format.

The restored DTO can be used e.g. to import variables to a variable system.

Parameters
filePathFile from which object is restored.
settingsVariable system DTO that is restored by deserialization.
void IG.Lib.StringVariableSystem.PrintVariables ( )
inline

Prints all variables (with their values) defined on the current object.

Referenced by IG.Lib.StringVariableSystem.TestMisc().

static void IG.Lib.StringVariableSystem.TestMisc ( )
inlinestatic

Member Data Documentation

object IG.Lib.StringVariableSystem._mainLock = new object()
private
bool IG.Lib.StringVariableSystem._setNullOnImport = false
private
SortedList<string, string> IG.Lib.StringVariableSystem._variables = new SortedList<string, string>()
protected

Property Documentation

object IG.Lib.StringVariableSystem.Lock
get

This object's central lock object to be used by other object.

bool IG.Lib.StringVariableSystem.SetNullOnImport
getset

Flag indicating whether null variable values are also set when importing variable values. If false then, if some imported variable has null value, this variable will not be set on the current system of variables. This means that the value of eventually existent variable will remain unchanged if variables are imported from another system where this variable is defined but has null value.

Default value is false. This behavior can be useful e.g. when importing settings from a file. Many times we don't want to import variables with null value because somebody might have set values to null instead of completely removing those variables he or she didn't want to change. This might not be the preferred behavior when null-valued variables actually serve some purpose and it is important that we have possibility of defining null values for variables e.g. in a setting file.

Referenced by IG.Lib.StringVariableSystemDtoBase< VariableSystemType >.CopyFromPlain().

virtual SortedList<string, string> IG.Lib.StringVariableSystem.Variables
getprotected
virtual string IG.Lib.StringVariableSystem.this[string varName]
getset

Gets or sets value of the specified variable.

Getter returnd value of the variable or null if it is not defined.

Setter overwrites existing value or creates a variable if it is not yet defined.

Parameters
varNameName of the variable whose value is queried. Must not be null or empty string.
Exceptions
ArgumentExceptionWhen the specified variable name is null or empty string.

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