|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
Grid class with CSV file capabilities. More...
#include <CsvGridMain.h>
Public Types | |
| using | row_type = TRow< C, T > |
| typedef for row type | |
| using | container_type = C< row_type, std::allocator< row_type > > |
| typedef for container type | |
Public Member Functions | |
| TCsvGrid ()=default | |
| Default constructor. | |
| TCsvGrid (const TCsvGrid &)=default | |
| Copy constructor. | |
| TCsvGrid (TCsvGrid &&)=default | |
| Move constructor. | |
| TCsvGrid (size_t rows, size_t cols) | |
| Initializing constructor. More... | |
| TCsvGrid (const std::string &filename, eCellFormatOptions options) | |
| Initializing constructor. More... | |
| TCsvGrid (std::initializer_list< row_type > rows) | |
| Initializer list constructor. More... | |
| ~TCsvGrid ()=default | |
| Ddestructor. | |
| TCsvGrid & | operator= (const TCsvGrid &)=default |
| Copy assignment operator. | |
| TCsvGrid & | operator= (TCsvGrid &&)=default |
| Move assignment operator. | |
| row_type & | operator[] (size_t row) |
| Subscript operator. More... | |
| const row_type & | operator[] (size_t row) const |
| Const subscript operator. More... | |
| bool | Empty () const |
| Get empty state of grid. More... | |
| size_t | GetRowCount () const |
| Get the number of rows. More... | |
| size_t | GetColCount (size_t row) const |
| Get the number of columns for a given row. More... | |
| void | SetRowCount (size_t rows, size_t defaultCols=0) |
| Resize the grid. More... | |
| void | AddRow (size_t cols=0) |
| Add a new row. More... | |
| void | AddColumnToAllRows () |
| Add a column to each row. More... | |
| void | InsertRow (size_t row, size_t defaultCols=0) |
| Insert a new row. More... | |
| void | InsertColumnInAllRows (size_t col) |
| Insert a new column in all rows. More... | |
| void | ClearCells () |
| Clear the contents of all cells. More... | |
| void | ResetGrid () |
| Clear the entire grid. More... | |
| void | LoadFromCSVFile (const std::string &filename, eCellFormatOptions options, size_t firstRowToLoad=0, size_t maxNumRowsToLoad=std::numeric_limits< size_t >::max()) |
| Load a csv file into the grid. More... | |
| void | SaveToCsvFile (const std::string &filename, eSaveToFileOptions option=eSaveToFileOptions::truncate) const |
| Save the grid to a CSV file. More... | |
Private Member Functions | |
| void | OutputCsvGridToStream (std::ostream &os) const |
| Output the grid to a stream object. More... | |
Static Private Member Functions | |
| static bool | ContainsEndOfRow (const std::string &row) |
| Check if row string contains the actual end of the CSV row. More... | |
Private Attributes | |
| container_type | m_grid {} |
| The grid row data. | |
Grid class with CSV file capabilities.
This class provides an implemtnation of an easy-to-use managed grid that can contain strings, integers or floating point data in any combination. Although in its standard setup data is internally stored as a std::string due to the implict text-based nature of a CSV file.
The grid can optionally be initialised by loading data from a CSV file. The grid is able to save its contents to CSV file. It can also be streamed to any compatible stream object using the << operator.
The grid class handles both rectangular and jagged data and CSV fles. Jagged data contains different number of columns for different rows.
The default behaviour is to be able to handle CSV files that may have their cells contained in double quotes. There is a slight performance overhead associated with this because extra parsing is required to tokenize each line. If it is known that the CSV file contains simple data, e.g. no cells in the CSV file are in double quotes, then the user can disable double quote handling, which gives a slight performance increase. With large data sets the performance increase can be significant.
|
inline |
Initializing constructor.
| [in] | rows | - The number of rows. |
| [in] | cols | - The number of columns. |
Create the rectangular grid object with a non-zero number of rows and columns. If rows or columns are 0 then std::out_of_range exception is thrown.
|
inline |
Initializing constructor.
| [in] | filename | - The full path name of the CSV file to load. |
| [in] | options | - Cell formatting options. |
Create a grid object from a CSV file. If cells are wrapped in double quotes in the CSV file then set options = doubleQuotedCells else set options = simpleCells. Throw a std::runtime_error exception if the file cannot be loaded.
|
inline |
Initializer list constructor.
| [in] | rows | - The initial list of rows. |
Create the CsvGrid from the given list of rows.
|
inline |
Add a column to each row.
Resize the grid, adding a new column to each row.
|
inline |
Add a new row.
| [in] | cols | - The default number of cells for the new row. |
Resize the grid, adding a new row with the given number of cells.
|
inline |
Clear the contents of all cells.
The contents of each cell in the grid is cleared but the row and column counts remain unchanged.
|
inlinestaticprivate |
Check if row string contains the actual end of the CSV row.
| [in] | row | - The row string object. |
If row contains an odd number of " chars then there must be a new line within a cell on the real row i nthe CSV file. If there are 0 or an even number of " chars in row then it must represent a complete row from the CSV file.
|
inline |
Get empty state of grid.
|
inline |
Get the number of columns for a given row.
| [in] | row | - A 0-based row index. |
|
inline |
Get the number of rows.
|
inline |
Insert a new column in all rows.
| [in] | col | - The column index at which the new column is to be inserted. |
The column is only inserted if the column index is within range of the row in the grid otherwise a column is not added to the row.
|
inline |
Insert a new row.
| [in] | row | - The row index at which the new row is to be inserted. |
| [in] | defaultCols | - The default number of columns for the new row. |
Insert a new row at a given row index in the grid. If the row index is out of range a std::out_of_range exception is thrown.
|
inline |
Load a csv file into the grid.
| [in] | filename | - The full path name of the CSV file to load. |
| [in] | options | - Cell formating options. |
| [in] | firstRowToLoad | - (Optional) First row to load into the grid (zero-based). |
| [in] | maxNumRowsToLoad | - (Optional) Limit number of rows read in to grid. |
Create a grid object from a CSV file. If cells are wrapped in double quotes in the CSV file then set options = doubleQuotedCells else set options = simpleCells. If the file stream cannot be created or opened the a std::runtime_error exception is thrown.
|
inline |
Subscript operator.
| [in] | row | - A 0-based row index. |
Retrieve the row at a given row index within a grid.
|
inline |
Const subscript operator.
| [in] | row | - A 0-based row index. |
Retrieve the row at a given row index within a grid.
|
inlineprivate |
Output the grid to a stream object.
| [in] | os | - The stream object. |
Write the grid in CSV format to a stream object.
|
inline |
Clear the entire grid.
All rows are removed from the grid leaving a row count of 0 afterwards.
|
inline |
Save the grid to a CSV file.
| [in] | filename | - The full path name of the CSV file to load. |
| [in] | option | - (Optional) Save to file options: append to or overwrite existing file. |
Create a CSV file from a grid object. If the file stream cannot be created or opened the a std::runtime_error exception is thrown.
|
inline |
Resize the grid.
| [in] | rows | - The number of rows. |
| [in] | defaultCols | - The number of columns for newly created rows. |
Resize the grid, adding or dropping rows as necessary.