IGLib
1.7.2
The IGLib base library for development of numerical, technical and business applications.
|
2D tables of data represented by strings. Maps to CSV files. More...
Public Member Functions | |
StringTable (bool readOnly) | |
Constructs a new string table, a data structure compatible with CSV file format. More... | |
StringTable () | |
Constructs a new string table, a data structure compatible with CSV file format. More... | |
void | SetElement (int rowNumber, int columnNumber, string element) |
Sets element at the specified position to the specified value. More... | |
void | SetElement< ElementType > (int rowNumber, int columnNumber, ElementType elementValue) |
Sets element at the specified position to the string representation of the specified value. More... | |
ElementType | GetElement< ElementType > (int rowNumber, int columnNumber) |
Returns the element of the specified type at the specified position. More... | |
bool | TryGetElement< ElementType > (int rowNumber, int columnNumber, ref ElementType elementValue) |
Tries to obtain a value of the specified type at the specified position, and returns a flag indicating whether parsing the value from a string was successful (and the element existed). More... | |
bool | IsDefined< ElementType > (int rowNumber, int columnNumber) |
Returns a flag indicating whether the specified position contains a valid string representation of a element of the specified type. More... | |
bool | IsDefined (int rowNumber, int columnNumber) |
Returns a flag telling whether the specified element is defined (it exists in the data table) or not. More... | |
bool | IsNotNullOrEmpty (int rowNumber, int columnNumber) |
Returns a flag telling whether the specified element is defined (it exists in the data table) and is at the same time not null or empty string. More... | |
string | GetElementOrNull (int rowNumber, int columnNumber, out bool isDefined) |
Returns the specified element on the data table or null if that element is not defined, and notifies the caller through isDefined whether the element is defined or not. More... | |
string | GetElementOrNull (int rowNumber, int columnNumber) |
Returns the specified element on the data table or null if that element is not defined. More... | |
int | FirstNonemptyRow (int startRow) |
Returns index of the first non-empty row from the specified row on (inclusively), or -1 if there is no such row. More... | |
int | FirstNonemptyRow () |
Returns index of the first non-empty row of the table, or -1 if there is no such row. More... | |
int | FirstNonemptyColumn (int rowNum, int startColumn) |
Returns number of the first non-empty cell in the specified row, from the specified starting column on (inclusively), or -1 if there is no suuch column. More... | |
int | FirstNonemptyColumn (int rowNum) |
Returns number of the first non-empty cell in the specified row. More... | |
void | Clear () |
Clears the data table. More... | |
void | AddRow () |
Adds a new row at the end of the data table. More... | |
void | AddRow (params string[] elements) |
Adds a new row at the end of the data table. More... | |
void | AddRow< ElementType > (params ElementType[] elements) |
Adds (appends) a new row with the specified elements at the end of the table. More... | |
void | AddElement (int rowNum, string value) |
Adds a new element at the end of the specified row of te data table. More... | |
void | AddElement (string value) |
Adds (appends) the speecified element at the end of the table, i.e. at the end of the last row. More... | |
void | AddElement< ElementType > (int rowNum, ElementType value) |
Adds string representation of a new element of the specified type at the end of the specified row of te data table. More... | |
void | AddElement< ElementType > (ElementType value) |
Adds (appends) string representatin of the speecified element at the end of the table, i.e. at the end of the last row. More... | |
void | AddElements (int rowNum, params string[] values) |
Adds the specified elements at the end of the specified row of te data table. More... | |
void | AddElements< ElementType > (int rowNum, params ElementType[] values) |
Adds string representations of the specified elements of the specified type at the end of the specified row of te data table. More... | |
void | AddElements (params string[] values) |
Adds (appends ) the specified elements at the end of the table, i.e. at the end of the last row. More... | |
void | AddElements< ElementType > (params ElementType[] values) |
Adds (appends ) string representations of the specified elements of the specified type at the end of the table, i.e. at the end of the last row. More... | |
void | SetNumRows (int numRows) |
Change the number of rows in the data table to the specified number. More... | |
void | SetNumColumns (int rowNum, int numColumns) |
Changes the number of columns of the specified row to the specified number. More... | |
void | ClearRow (int rowNum) |
Clears the specified row in the data table. More... | |
int | NumColumns (int rowNum) |
Returns the number of elements (columns) of the specified row. More... | |
bool | IsInt (int rowNumber, int columnNumber) |
Returns a flag specified whether the specified element of the data table exists and represents an integer. More... | |
int | GetInt (int rowNumber, int columnNumber) |
Returns an integer value of the element at the specified position of the data table, if it is defined, or throws an exception. More... | |
bool | TryGetInt (int rowNumber, int columnNumber, out int value) |
Safely gets the integer value at the specified position of the data table, if it is defined, and notifies the caller whether it is defined. More... | |
void | GetIntSafe (int rowNumber, int columnNumber, out int value, out bool isElementDefined, out bool isElementNotNullOrEmpty, out bool isInt) |
Safely gets the integer value at the specified position of the data table, if it is defined, and notifies the caller on the status. More... | |
bool | IsDouble (int rowNumber, int columnNumber) |
Returns a flag specified whether the specified element of the data table exists and represents a number (of type double). More... | |
double | GetDouble (int rowNumber, int columnNumber) |
Returns a double value of the element at the specified position of the data table, if such element is defined and represents a number, or throws an exception otherwise. More... | |
bool | TryGetDouble (int rowNumber, int columnNumber, out double value) |
Safely gets the double value at the specified position of the data table, if it is defined, and notifies the caller whether it is defined. More... | |
void | GetDoubleSafe (int rowNumber, int columnNumber, out double value, out bool isElementDefined, out bool isElementNotNullOrEmpty, out bool isDouble) |
Safely gets the numerical value (of type double) at the specified position of the data table, if it is defined, and notifies the caller about the status. More... | |
void | LoadCsv (string filePath, string separator) |
Loads the specified CSV file. Reads contents of the file into the data table of the current object. More... | |
void | LoadCsv (string filePath) |
Loads the specified CSV file. Reads contents of the file into the data table of the current object. More... | |
override string | ToString () |
Converts the current string table to a string in CSV form and returns the string. More... | |
void | SaveCsv (string filePath, string separator, bool append) |
Saves the data of the current object to the specified CSV file. More... | |
void | SaveCsv (string filePath, string separator) |
Saves the data of the current object into a CSV file. If the file already exists then its contents are overwritten. More... | |
void | SaveCsv (string filePath, bool append) |
Saves the data of the current object into a CSV file. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format. More... | |
void | SaveCsv (string filePath) |
Saves the data of the current object values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format. More... | |
Static Public Member Functions | |
static void | ExampleWriteCsv (string filePath) |
Creates a simple string table and saves it to a CSV file. More... | |
Public Attributes | |
const string | DefaultCsvSeparator = "," |
The default separator in the CSV files - comma (","). More... | |
Static Public Attributes | |
static int | DefaultOutputLevel = 0 |
Dafault output level for object of the StringTable and derived classes. More... | |
Protected Attributes | |
readonly object | _lock = new object() |
int | _outputLevel = DefaultOutputLevel |
List< List< string > > | _data = new List<List<string>>() |
bool | _isReadOnly = false |
bool | _isAutoExtend = true |
string | _csvSeparator = UtilCsv.CsvSeparator |
Properties | |
object | Lock [get] |
Object used for thread locking. More... | |
int | OutputLevel [get, set] |
Output level, specifies the level of descriptive output on console during the operation. More... | |
List< List< string > > | Data [get] |
Data behind the table - list of lists of strings. More... | |
bool | IsReadOnly [get, set] |
Whether or not data table is read only. More... | |
bool | IsAutoExtend [get, set] |
Whether or not data storage automatically extends when a value is set on the position that is out of range. More... | |
string | this[int rowNumber, int columnNumber] [get, set] |
Index operator, gets or sets the specific element of the data table specified by row and column number. More... | |
string[][] | Table [get, set] |
Gets or sets copy of the data table in form of 2D jagged array. More... | |
int | NumRows [get] |
Gets number of rows in the data table. More... | |
int | MaxNumColumns [get] |
Returns the maximal number of columns in any row. More... | |
bool | IsRectangular [get] |
Returns true if data table is rectangular (i.e. all rows have equal number of elements) or not. More... | |
string | CsvSeparator [get, set] |
Separator used in CSV files that this class loads data from or writes data to. More... | |
Properties inherited from IG.Lib.ILockable | |
object | Lock [get] |
2D tables of data represented by strings. Maps to CSV files.
Data access operations are thread safe.
$A Igor xx;
|
inline |
Constructs a new string table, a data structure compatible with CSV file format.
readOnly | Whether the created object is read only or not. |
|
inline |
Constructs a new string table, a data structure compatible with CSV file format.
|
inline |
Sets element at the specified position to the specified value.
rowNumber | Row index of the element to be set. |
columnNumber | Column index of the element to be set. |
element | Element to be set. |
|
inline |
Sets element at the specified position to the string representation of the specified value.
rowNumber | Row index of the element to be set. |
columnNumber | Column index of the element to be set. |
elementValue | Value whose string representation is to be set. |
|
inline |
Returns the element of the specified type at the specified position.
Element is parrsed from the string element. Exception is thrown if the element doed not exist or parsing fails.
ElementType | Type of the element to be returned. |
rowNumber | Row index of the element. |
columnNumber | Column index of the element. |
References IG.Lib.Util.Parse().
|
inline |
Tries to obtain a value of the specified type at the specified position, and returns a flag indicating whether parsing the value from a string was successful (and the element existed).
Value (of the specified type) of the specified element is returned through a ref parameter.
ElementType | Type of the element to be extracted. |
rowNumber | Row index of the element. |
columnNumber | Column index of the element. |
elementValue | Argument through which the value is returned. |
|
inline |
Returns a flag indicating whether the specified position contains a valid string representation of a element of the specified type.
ElementType | Element type. |
rowNumber | Row index of the element. |
columnNumber | Column index of the element. |
|
inline |
Returns a flag telling whether the specified element is defined (it exists in the data table) or not.
If the specified element is null, true is returned. Use IsNotNullOrEmpty method to check also if the element is not null or empty string.
rowNumber | Row number of the element checked. |
columnNumber | Column number of the element checked. |
|
inline |
Returns a flag telling whether the specified element is defined (it exists in the data table) and is at the same time not null or empty string.
rowNumber | Row number of the element checked. |
columnNumber | Column number of the element checked. |
|
inline |
Returns the specified element on the data table or null if that element is not defined, and notifies the caller through isDefined whether the element is defined or not.
rowNumber | Row number of the element checked. |
columnNumber | Column number of the element checked. |
isDefined | Specifies, on return, whether the specified element is defined (it exists in the data table). |
|
inline |
Returns the specified element on the data table or null if that element is not defined.
Use another overload to also notify the caller whether the element is defined or not.
rowNumber | Row number of the element checked. |
columnNumber | Column number of the element checked. |
|
inline |
Returns index of the first non-empty row from the specified row on (inclusively), or -1 if there is no such row.
startRow | Row where search starts. |
|
inline |
Returns index of the first non-empty row of the table, or -1 if there is no such row.
|
inline |
Returns number of the first non-empty cell in the specified row, from the specified starting column on (inclusively), or -1 if there is no suuch column.
rowNum | Index of row in which nonemnty cell is searched for. |
startColumn | Starting column from which on (inclusively) a nonempty cell is searched. |
|
inline |
Returns number of the first non-empty cell in the specified row.
rowNum | Index of row in which nonemnty cell is searched for. |
|
inline |
Clears the data table.
|
inline |
Adds a new row at the end of the data table.
Throws exception if the data table is read only.
Referenced by IG.Lib.StringTable.ExampleWriteCsv(), and IG.Script.LoadableScriptShellNeuralBase.SaveSensitivityCSV().
|
inline |
Adds a new row at the end of the data table.
Throws exception if the data table is read only.
|
inline |
Adds (appends) a new row with the specified elements at the end of the table.
ElementType | Type of elements to be added to the newly created row. |
elements | Elements to ne added to the new row. |
Throws exception if the data table is read only.
|
inline |
Adds a new element at the end of the specified row of te data table.
rowNum | Sequential number of the row to which the element is added. |
value | Value of the element that is added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
|
inline |
Adds (appends) the speecified element at the end of the table, i.e. at the end of the last row.
value | Value to be added to the table. |
|
inline |
Adds string representation of a new element of the specified type at the end of the specified row of te data table.
rowNum | Sequential number of the row to which the element is added. |
value | Value of the element that is added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
|
inline |
Adds (appends) string representatin of the speecified element at the end of the table, i.e. at the end of the last row.
value | Value to be added to the table. |
|
inline |
Adds the specified elements at the end of the specified row of te data table.
rowNum | Sequential number of the row to which the elements are added. |
values | Array of values of the elements that are added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
Referenced by IG.Lib.StringTable.ExampleWriteCsv().
|
inline |
Adds string representations of the specified elements of the specified type at the end of the specified row of te data table.
ElementType | Type of elements to be added. |
rowNum | Sequential number of the row to which the elements are added. |
values | Array of values of the elements that are added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
|
inline |
Adds (appends ) the specified elements at the end of the table, i.e. at the end of the last row.
values | Array of values of the elements that are added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
|
inline |
Adds (appends ) string representations of the specified elements of the specified type at the end of the table, i.e. at the end of the last row.
values | Array of values of the elements that are added. |
Throws exception if the data table is read only, or if the specified row does not exist and the data table is not extensible.
|
inline |
Change the number of rows in the data table to the specified number.
numRows | New number of rows. |
Throws exception if the data table is read only.
If the current number of rows is smaller than the one specified, then new empty (but allocated) rows are added. If the number is greater then the redundant rows are removed.
|
inline |
Changes the number of columns of the specified row to the specified number.
rowNum | Row number where number of columns is changed. |
numColumns | New numbef of columns in the specified row. |
Throws exception if the data table is read only.
If the current number of rows is smaller than the specified row number, then new empty (but allocated) rows are added. Cells that are eventually added are set to null.
|
inline |
Clears the specified row in the data table.
rowNum | Number of the row to be cleared. |
Throws exception if the data table is read only, or if the row number is out of range and the data table is not automatically extendable.
|
inline |
Returns the number of elements (columns) of the specified row.
rowNum | Specifies for which row number of columns is returned. |
|
inline |
Returns a flag specified whether the specified element of the data table exists and represents an integer.
If the element does not exist then false is returned.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
|
inline |
Returns an integer value of the element at the specified position of the data table, if it is defined, or throws an exception.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
|
inline |
Safely gets the integer value at the specified position of the data table, if it is defined, and notifies the caller whether it is defined.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
value | Holds on return the corresponding integer value of the specified element, if defined, or default integer value (i.e. 0) otherwise. |
|
inline |
Safely gets the integer value at the specified position of the data table, if it is defined, and notifies the caller on the status.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
value | Holds on return the corresponding integer value of the specified element, if defined, or default integer value (i.e. 0) otherwise. |
isElementDefined | Notifies whether the specified element is defined or not. |
isElementNotNullOrEmpty | Notifies whether the element at the specified position is not null or empty string. |
isInt | Notifies whether the elemet at the specified position actually represents an integer. |
|
inline |
Returns a flag specified whether the specified element of the data table exists and represents a number (of type double).
If the element does not exist then false is returned.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
|
inline |
Returns a double value of the element at the specified position of the data table, if such element is defined and represents a number, or throws an exception otherwise.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
|
inline |
Safely gets the double value at the specified position of the data table, if it is defined, and notifies the caller whether it is defined.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
value | Holds on return the corresponding double value of the specified element, if defined, or default double value (i.e. 0) otherwise. |
|
inline |
Safely gets the numerical value (of type double) at the specified position of the data table, if it is defined, and notifies the caller about the status.
rowNumber | Row number of the data table element. |
columnNumber | Column number of the data table element. |
value | Holds on return the corresponding double value of the specified element, if defined, or default double value (i.e. 0.0) otherwise. |
isElementDefined | Notifies whether the specified element is defined or not. |
isElementNotNullOrEmpty | Notifies whether the element at the specified position is not null or empty string. |
isDouble | Notifies whether the elemet at the specified position actually represents a number of type double. |
|
inline |
Loads the specified CSV file. Reads contents of the file into the data table of the current object.
filePath | Path to the CSV file that is read and parsed. |
separator | Separator that is used in the CSV file. If not specified (null or empty string) then Constant UtilCsv.DefaultCsvSeparator is assumed. |
References IG.Lib.UtilCsv.LoadCsv().
|
inline |
Loads the specified CSV file. Reads contents of the file into the data table of the current object.
The value of the CsvSeparator property is used as separator.
filePath | Path to the CSV file that is read and parsed. |
|
inline |
Converts the current string table to a string in CSV form and returns the string.
References IG.Lib.UtilCsv.ToCsvString().
|
inline |
Saves the data of the current object to the specified CSV file.
filePath | Path to the file into which data is written. |
separator | Separator that is used in CSV format. |
append | If true then the CSV string is appended to the existent file if the file already exists. Otherwise, existend files are overwritten. |
References IG.Lib.UtilCsv.SaveCsv().
Referenced by IG.Lib.StringTable.ExampleWriteCsv(), and IG.Script.LoadableScriptShellNeuralBase.SaveSensitivityCSV().
|
inline |
Saves the data of the current object into a CSV file. If the file already exists then its contents are overwritten.
filePath | Path to the file into which contents is written. |
separator | Separator that is used in CSV format. |
|
inline |
Saves the data of the current object into a CSV file. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format.
filePath | Path to the file into which contents is written. |
append | If true then the CSV string is appended to the existent file if the file already exists. Otherwise, existend files are overwritten. |
|
inline |
Saves the data of the current object values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format.
filePath | Path to the file into which contents is written. |
|
inlinestatic |
Creates a simple string table and saves it to a CSV file.
filePath | Path to the file where CSV is stored. |
References IG.Lib.StringTable.AddElements(), IG.Lib.StringTable.AddRow(), IG.Num.RandomGenerator.Global, IG.Num.IRandomGenerator.NextDouble(), and IG.Lib.StringTable.SaveCsv().
|
protected |
|
static |
Dafault output level for object of the StringTable and derived classes.
|
protected |
|
protected |
|
protected |
|
protected |
const string IG.Lib.StringTable.DefaultCsvSeparator = "," |
The default separator in the CSV files - comma (",").
|
protected |
|
get |
Object used for thread locking.
|
getset |
Output level, specifies the level of descriptive output on console during the operation.
Referenced by IG.Script.ScriptAppBase.DataStructuresFunctionTestCsvReadDefinitionAndData(), and IG.Script.ScriptAppBase.DataStructuresFunctionTestCsvWriteDefinitionAndData().
|
getprotected |
Data behind the table - list of lists of strings.
|
getset |
Whether or not data table is read only.
|
getset |
Whether or not data storage automatically extends when a value is set on the position that is out of range.
|
getset |
Index operator, gets or sets the specific element of the data table specified by row and column number.
Handling situation when row or column number is out of range:
If IsAutoExtend then getter returns null and setter extends the table as needed.
Otherwise, IndexOutOfRangeException exception is thrown.
rowNumber | Row number of the element (zero-based). |
columnNumber | Column number of the element (zero-based). |
|
getset |
Gets or sets copy of the data table in form of 2D jagged array.
|
get |
Gets number of rows in the data table.
|
get |
Returns the maximal number of columns in any row.
|
get |
Returns true if data table is rectangular (i.e. all rows have equal number of elements) or not.
Table without rows or with one row is considered rectangular.
Table with all rows empty or null is considered rectangular.
|
getset |
Separator used in CSV files that this class loads data from or writes data to.
Property is used by ethods that deal with CSV files and do not have separator as.