IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
A lightweight system of string-valued variables, with some support to type conversion. More...
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... | |
![]() | |
object | Lock [get] |
Private Attributes | |
object | _mainLock = new object() |
bool | _setNullOnImport = false |
A lightweight system of string-valued variables, with some support to type conversion.
|
inline |
Constructs a new system of string variables.
|
inlinevirtual |
Returns value of the specified variable, or null if it is not defined.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
inlinevirtual |
Sets the specified variable to the specified value.
If variable does not exist then it is created, otherwise its value is overwritten.
varName | Name of the variable to be set. Must not be null or empty string. |
varValue | Value that is assigned to the variable. |
ArgumentException | When the specified variable name is null or empty string. |
Referenced by IG.Lib.StringVariableSystem.TestMisc().
|
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.
varName | Name of the variable to be added. Must not be null or empty string. |
varValue | Value that is assigned to the variable. |
ArgumentException | When the specified variable name is null or empty string, or when the variable with the specified name already exists. |
|
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.
varName | Name of the variable to be removed. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
inlinevirtual |
Removes all variables whose names are specified by the argument, and returns the number of variables that were actully been removed.
varNames | Names of variables to be removed. |
|
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.
varName | Name of the variable to be removed. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
inlinevirtual |
Returns true if the specified variable is defined, false otherwise.
varName | Name of the variable whose existence is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
inlinevirtual |
Returns array representation of variables that are currently defined on the system.
Referenced by IG.Lib.StringVariableSystemDtoBase< VariableSystemType >.CopyFromPlain().
|
inlinevirtual |
Imports variables defined in form of two dimensional array.
variables |
|
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.
varName | Name of the variable to be set. Must not be null or empty string. |
varValue | Value 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. |
ArgumentException | When the specified variable name is null or empty string. |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When 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. |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When 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. |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |
References IG.Lib.Util.TryParseBoolean().
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When 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().
|
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.
flagName | Name of the flag to be returned. |
ArgumentException | When the specified flag name is null or empty string. |
|
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.
flagName | Name of the flag to be set. |
flagValue | Value to be assigned to the flag of the specified name. |
|
inlinevirtual |
Saves (serializes) the specified variable system to the specified JSON file.
If the file already exists, contents overwrite the file.
filePath | Path to the file in variables and properties of the system are saved. |
Reimplemented in IG.Lib.StringSettings.
|
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.
filePath | Path to the file in variables and properties of the system are saved. |
append | Specifies 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().
|
inlinevirtual |
Imports variables from the specified variable system in JSON format.
filePath | File from which object is restored. |
Reimplemented in IG.Lib.StringSettings.
|
inlinestatic |
Saves (serializes) the specified variable system to the specified JSON file. File is owerwritten if it exists.
variableSystem | Object that is saved to a file. |
filePath | Path to the file in which object is is saved. |
|
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.
variableSystem | Object that is saved to a file. |
filePath | Path to the file into which object is saved. |
append | Specifies 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().
|
inlinestatic |
Restores (deserializes) a vector from the specified file in JSON format.
filePath | File from which object is restored. |
variableSystemRestored | Object that is restored by deserialization. |
References IG.Lib.SerializationDtoBase< Type, BaseType >.CopyTo().
|
inlinestatic |
Saves (serializes) the specified variable system DTO to the specified JSON file.
If the file already exists, contents overwrite the file.
settings | Variable system DTO that is saved to a file. |
filePath | Path to the file into which variables (and settings and other stuff) are saved. |
|
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.
variables | Variable system DTO that is saved to a file. |
filePath | Path to the file into which variables (and settings and other stuff) are saved. |
append | Specifies whether serialized data is appended at the end of the file in the case that the file already exists. |
|
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.
filePath | File from which object is restored. |
settings | Variable system DTO that is restored by deserialization. |
|
inline |
Prints all variables (with their values) defined on the current object.
Referenced by IG.Lib.StringVariableSystem.TestMisc().
|
inlinestatic |
Miscellaneous tests.
References IG.Lib.StringVariableSystem.PrintVariables(), and IG.Lib.StringVariableSystem.SetVariable().
|
private |
|
private |
|
protected |
|
get |
This object's central lock object to be used by other object.
|
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().
|
getprotected |
|
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.
varName | Name of the variable whose value is queried. Must not be null or empty string. |
ArgumentException | When the specified variable name is null or empty string. |