| IGLib 1.4 The IGLib base library for development of numerical, technical and business applications.

- Main Page
- Namespaces
- Classes
- Files
- Directories

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | Properties

# IG::Lib::StringTable Class Reference

2D tables of data represented by strings. Maps to CSV files. More...

Inheritance diagram for IG::Lib::StringTable:
[legend]
Collaboration diagram for IG::Lib::StringTable:
[legend]

List of all members.

## Public Member Functions
| StringTable (bool readOnly)
| Constructs a new string table, a data structure compatible with CSV file format.
| StringTable ()
| Constructs a new string table, a data structure compatible with CSV file format.
bool | IsDefined (int rowNumber, int columnNumber)
| 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.
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.
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.
string | GetElementOrNull (int rowNumber, int columnNumber)
| 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.
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.
int | FirstNonemptyRow ()
| Returns index of the first non-empty row of the table, or -1 if there is no such row.
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.
int | FirstNonemptyColumn (int rowNum)
| Returns number of the first non-empty cell in the specified row.
void | Clear ()
| Clears the data table.
void | AddRow ()
| Adds a new row at the end of the data table.
void | AddElement (int rowNum, string value)
| Adds a new element at the end of the specified row of te data table.
void | AddElements (int rowNum, params string[] values)
| Adds the specified elements at the end of the specified row of te data table.
void | SetNumRows (int numRows)
| Change the number of rows in the data table to the specified number.
void | SetNumColumns (int rowNum, int numColumns)
| Changes the number of columns of the specified row to the specified number.
void | ClearRow (int rowNum)
| Clears the specified row in the data table.
int | NumColumns (int rowNum)
| Returns the number of elements (columns) of the specified row.
bool | IsInt (int rowNumber, int columnNumber)
| 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.
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.
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.
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.
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). If the element does not exist then false is returned.
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.
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.
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.
void | LoadCsv (string filePath, string separator)
| Loads the specified CSV file. Reads contents of the file into the data table of the current object.
void | LoadCsv (string filePath)
| 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.
void | SaveCsv (string filePath, string separator, bool append)
| Saves the data of the current object to the specified CSV file.
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.
void | SaveCsv (string filePath, bool append)
| Saves the data of the current object into a CSV file. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.
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 UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.
## Static Public Member Functions
static void | ExampleWriteCsv (string filePath)
| Creates a simple string table and saves it to a CSV file.
## Public Attributes
const string | DefaultCsvSeparator = ","
| The default separator in the CSV files - comma (",").
## Static Public Attributes
static int | DefaultOutputLevel = 0
| Dafault output level for object of the StringTable and derived classes.
## 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.
int | OutputLevel`[get, set]`
| Output level, specifies the level of descriptive output on console during the operation.
List< List< string > > | Data`[get]`
| Data behind the table - list of lists of strings.
bool | IsReadOnly`[get, set]`
| Whether or not data table is read only.
bool | IsAutoExtend`[get, set]`
| Whether or not data storage automatically extends when a value is set on the position that is out of range.
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. 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.
string[][] | Table`[get, set]`
| Gets or sets copy of the data table in form of 2D jagged array.
int | NumRows`[get]`
| Gets number of rows in the data table.
int | MaxNumColumns`[get]`
| Returns the maximal number of columns in any row.
bool | IsRectangular`[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.
string | CsvSeparator`[get, set]`
| 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.

## Detailed Description

2D tables of data represented by strings. Maps to CSV files.

Data access operations are thread safe. $A Igor xx;

## Constructor & Destructor Documentation

IG::Lib::StringTable::StringTable | ( | bool | readOnly | ) | `[inline]`

Constructs a new string table, a data structure compatible with CSV file format.

Parameters:

  readOnly | Whether the created object is read only or not.

IG::Lib::StringTable::StringTable | ( |  | ) | `[inline]`

Constructs a new string table, a data structure compatible with CSV file format.

## Member Function Documentation

bool IG::Lib::StringTable::IsDefined | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the element checked.
  columnNumber | Column number of the element checked.

bool IG::Lib::StringTable::IsNotNullOrEmpty | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the element checked.
  columnNumber | Column number of the element checked.

string IG::Lib::StringTable::GetElementOrNull | ( | int | rowNumber,
|  | int | columnNumber,
|  | out bool | isDefined
| ) |  | `[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.

Parameters:

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

string IG::Lib::StringTable::GetElementOrNull | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the element checked.
  columnNumber | Column number of the element checked.

int IG::Lib::StringTable::FirstNonemptyRow | ( | int | startRow | ) | `[inline]`

Returns index of the first non-empty row from the specified row on (inclusively), or -1 if there is no such row.

Parameters:

  startRow | Row where search starts.

int IG::Lib::StringTable::FirstNonemptyRow | ( |  | ) | `[inline]`

Returns index of the first non-empty row of the table, or -1 if there is no such row.

int IG::Lib::StringTable::FirstNonemptyColumn | ( | int | rowNum,
|  | int | startColumn
| ) |  | `[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.

Parameters:

  rowNum | Index of row in which nonemnty cell is searched for.
  startColumn | Starting column from which on (inclusively) a nonempty cell is searched.

int IG::Lib::StringTable::FirstNonemptyColumn | ( | int | rowNum | ) | `[inline]`

Returns number of the first non-empty cell in the specified row.

Parameters:

  rowNum | Index of row in which nonemnty cell is searched for.

void IG::Lib::StringTable::Clear | ( |  | ) | `[inline]`

Clears the data table.

void IG::Lib::StringTable::AddRow | ( |  | ) | `[inline]`

Adds a new row at the end of the data table.

Throws exception if the data table is read only.

void IG::Lib::StringTable::AddElement | ( | int | rowNum,
|  | string | value
| ) |  | `[inline]`

Adds a new element at the end of the specified row of te data table.

Parameters:

  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.

void IG::Lib::StringTable::AddElements | ( | int | rowNum,
|  | params string[] | values
| ) |  | `[inline]`

Adds the specified elements at the end of the specified row of te data table.

Parameters:

  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.

void IG::Lib::StringTable::SetNumRows | ( | int | numRows | ) | `[inline]`

Change the number of rows in the data table to the specified number.

Parameters:

  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.

void IG::Lib::StringTable::SetNumColumns | ( | int | rowNum,
|  | int | numColumns
| ) |  | `[inline]`

Changes the number of columns of the specified row to the specified number.

Parameters:

  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.

void IG::Lib::StringTable::ClearRow | ( | int | rowNum | ) | `[inline]`

Clears the specified row in the data table.

Parameters:

  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.

int IG::Lib::StringTable::NumColumns | ( | int | rowNum | ) | `[inline]`

Returns the number of elements (columns) of the specified row.

Parameters:

  rowNum | Specifies for which row number of columns is returned.

bool IG::Lib::StringTable::IsInt | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the data table element.
  columnNumber | Column number of the data table element.

int IG::Lib::StringTable::GetInt | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[inline]`

Returns an integer value of the element at the specified position of the data table, if it is defined, or throws an exception.

Parameters:

  rowNumber | Row number of the data table element.
  columnNumber | Column number of the data table element.

Returns:
  Integer value of the specified element, if the element exists and can be converted to an integer (otherwise, an exception is thrown).

bool IG::Lib::StringTable::TryGetInt | ( | int | rowNumber,
|  | int | columnNumber,
|  | out int | value
| ) |  | `[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.

Parameters:

  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.

Returns:
  Flag indicating whether the elemet at the specified position actually represents an integer.

void IG::Lib::StringTable::GetIntSafe | ( | int | rowNumber,
|  | int | columnNumber,
|  | out int | value,
|  | out bool | isElementDefined,
|  | out bool | isElementNotNullOrEmpty,
|  | out bool | isInt
| ) |  | `[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.

Parameters:

  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.

bool IG::Lib::StringTable::IsDouble | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the data table element.
  columnNumber | Column number of the data table element.

double IG::Lib::StringTable::GetDouble | ( | int | rowNumber,
|  | int | columnNumber
| ) |  | `[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.

Parameters:

  rowNumber | Row number of the data table element.
  columnNumber | Column number of the data table element.

Returns:
  Double value of the specified element, if the element exists and can be converted to an double (otherwise, an exception is thrown).

bool IG::Lib::StringTable::TryGetDouble | ( | int | rowNumber,
|  | int | columnNumber,
|  | out double | value
| ) |  | `[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.

Parameters:

  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.

Returns:
  Flag indicating whether the elemet at the specified position actually represents a double.

void IG::Lib::StringTable::GetDoubleSafe | ( | int | rowNumber,
|  | int | columnNumber,
|  | out double | value,
|  | out bool | isElementDefined,
|  | out bool | isElementNotNullOrEmpty,
|  | out bool | isDouble
| ) |  | `[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.

Parameters:

  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.

void IG::Lib::StringTable::LoadCsv | ( | string | filePath,
|  | string | separator
| ) |  | `[inline]`

Loads the specified CSV file. Reads contents of the file into the data table of the current object.

Parameters:

  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 UtilStr.DefaultCsvSeparator is assumed.

void IG::Lib::StringTable::LoadCsv | ( | string | filePath | ) | `[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.

Parameters:

  filePath | Path to the CSV file that is read and parsed.

void IG::Lib::StringTable::SaveCsv | ( | string | filePath,
|  | string | separator,
|  | bool | append
| ) |  | `[inline]`

Saves the data of the current object to the specified CSV file.

Parameters:

  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.

void IG::Lib::StringTable::SaveCsv | ( | string | filePath,
|  | string | separator
| ) |  | `[inline]`

Saves the data of the current object into a CSV file. If the file already exists then its contents are overwritten.

Parameters:

  filePath | Path to the file into which contents is written.
  separator | Separator that is used in CSV format.

void IG::Lib::StringTable::SaveCsv | ( | string | filePath,
|  | bool | append
| ) |  | `[inline]`

Saves the data of the current object into a CSV file. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters:

  filePath | Path to the file into which contents is written.
  values | A 2D jagged array of string cell values. Each outer element contains one row of values in CSV.

void IG::Lib::StringTable::SaveCsv | ( | string | filePath | ) | `[inline]`

Saves the data of the current object values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters:

  filePath | Path to the file into which contents is written.
  values | A 2D jagged array of string cell values. Each outer element contains one row of values in CSV.

static void IG::Lib::StringTable::ExampleWriteCsv | ( | string | filePath | ) | `[inline, static]`

Creates a simple string table and saves it to a CSV file.

Parameters:

  filePath | Path to the file where CSV is stored.

## Member Data Documentation

readonly object IG::Lib::StringTable::_lock = new object()`[protected]`

int IG::Lib::StringTable::DefaultOutputLevel = 0`[static]`

Dafault output level for object of the StringTable and derived classes.

int IG::Lib::StringTable::_outputLevel = DefaultOutputLevel`[protected]`

List<List<string> > IG::Lib::StringTable::_data = new List<List<string>>()`[protected]`

bool IG::Lib::StringTable::_isReadOnly = false`[protected]`

bool IG::Lib::StringTable::_isAutoExtend = true`[protected]`

const string IG::Lib::StringTable::DefaultCsvSeparator = ","

The default separator in the CSV files - comma (",").

string IG::Lib::StringTable::_csvSeparator = UtilCsv.CsvSeparator`[protected]`

## Property Documentation

object IG::Lib::StringTable::Lock`[get]`

Object used for thread locking.

Implements IG::Lib::ILockable.

int IG::Lib::StringTable::OutputLevel`[get, set]`

Output level, specifies the level of descriptive output on console during the operation.

List<List<string> > IG::Lib::StringTable::Data`[get, protected]`

Data behind the table - list of lists of strings.

bool IG::Lib::StringTable::IsReadOnly`[get, set]`

Whether or not data table is read only.

bool IG::Lib::StringTable::IsAutoExtend`[get, set]`

Whether or not data storage automatically extends when a value is set on the position that is out of range.

string IG::Lib::StringTable::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. 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.

Parameters:

  rowNumber | Row number of the element (zero-based).
  columnNumber | Column number of the element (zero-based).

string [][] IG::Lib::StringTable::Table`[get, set]`

Gets or sets copy of the data table in form of 2D jagged array.

int IG::Lib::StringTable::NumRows`[get]`

Gets number of rows in the data table.

int IG::Lib::StringTable::MaxNumColumns`[get]`

Returns the maximal number of columns in any row.

bool IG::Lib::StringTable::IsRectangular`[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.

string IG::Lib::StringTable::CsvSeparator`[get, set]`

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.

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

- StringTable.cs

All Classes Namespaces Files Functions Variables Enumerations Properties Events