30 #include <initializer_list> 35 #ifdef USE_EXPLICIT_MOVE_ 38 #include <boost/tokenizer.hpp> 39 #include <boost/algorithm/string/trim.hpp> 40 #include <boost/throw_exception.hpp> 120 container.reserve(size);
127 template <
template <
class,
class>
class C,
class T>
class TCsvGrid;
136 template <
template <
class,
class>
class C,
class T =
Cell>
class TRow final
149 #ifdef USE_EXPLICIT_MOVE_ 153 *
this = std::move(row);
179 LoadRowFromCsvFileLine(line, options);
188 TRow(std::initializer_list<T> cells)
195 TRow& operator=(
const TRow&) =
default;
196 #ifdef USE_EXPLICIT_MOVE_ 200 std::swap(m_cells, row.m_cells);
220 if (col >= GetSize())
222 BOOST_THROW_EXCEPTION(std::out_of_range(
"col out of range"));
225 return *std::next(m_cells.begin(), col);
240 if (col >= GetSize())
242 BOOST_THROW_EXCEPTION(std::out_of_range(
"col out of range"));
245 return *std::next(m_cells.begin(), col);
253 return m_cells.empty();
261 return std::distance(m_cells.begin(), m_cells.end());
273 m_cells.resize(cols);
284 m_cells.emplace_back(value);
294 m_cells.emplace_back();
310 if (col >= GetSize())
312 BOOST_THROW_EXCEPTION(std::out_of_range(
"col out of range"));
315 m_cells.emplace(std::next(m_cells.begin(), col), value);
330 if (col >= GetSize())
332 BOOST_THROW_EXCEPTION(std::out_of_range(
"col out of range"));
335 m_cells.emplace(std::next(m_cells.begin(), col));
345 std::fill(m_cells.begin(), m_cells.end(),
Cell());
371 TokenizeLineQuoted(line);
390 for (
const auto& cellItem : m_cells)
393 std::string cell{
static_cast<std::string
>(cellItem)};
397 size_t pos{cell.find(
'"')};
399 while (pos < cell.length())
401 cell.insert(pos,
"\"");
402 pos = cell.find(
'"', pos + 2);
406 if (cell.find_first_of(
",\r\n") != std::string::npos)
408 std::string temp =
"\"";
418 if (col++ < GetSize() - 1)
433 using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
434 Tokenizer tokzr{line};
435 Tokenizer::const_iterator tokIter{tokzr.begin()};
437 while (tokIter != tokzr.end())
440 std::string tok{*tokIter++};
442 m_cells.emplace_back(tok);
455 std::stringstream line_ss{line};
458 while (std::getline(line_ss, tok,
','))
462 m_cells.emplace_back(tok);
void InsertColumn(size_t col, V value)
Insert a new cell.
Definition: CsvGridRow.h:308
Grid class with CSV file capabilities.
Definition: CsvGridMain.h:81
void ClearCells()
Clear the cells' contents.
Definition: CsvGridRow.h:343
Class defining a row of the grid.
Definition: CsvGridRow.h:136
The std namespace.
Definition: DebugLog.h:81
void operator()(container_type &container, size_t size) const
Function operator.
Definition: CsvGridRow.h:118
TRow(const std::string &line, eCellFormatOptions options)
Initializing constructor.
Definition: CsvGridRow.h:177
TRow(std::initializer_list< T > cells)
Initializer list constructor.
Definition: CsvGridRow.h:188
void AddColumn()
Add a column with default value.
Definition: CsvGridRow.h:292
size_t GetSize() const
Get the number of columns.
Definition: CsvGridRow.h:259
void InsertColumn(size_t col)
Insert a new cell.
Definition: CsvGridRow.h:328
TRow(size_t numCols)
Initializing constructor.
Definition: CsvGridRow.h:165
void TokenizeLine(const std::string &line)
Tokenize a row with simple cells.
Definition: CsvGridRow.h:453
File containing declarations relating the CellDouble class.
void SetSize(size_t cols)
Set the number of columns in the row.
Definition: CsvGridRow.h:271
void operator()(container_type &container, size_t size) const
Function operator.
Definition: CsvGridRow.h:95
void AddColumn(V value)
Add a column with the given value.
Definition: CsvGridRow.h:282
std::vector< T > container_type
Typedef to container type.
Definition: CsvGridRow.h:109
The core_lib namespace.
Definition: AsioDefines.h:59
Class defining a single cell within a row of the grid.
Definition: CsvGridCell.h:49
All cells are simple and not wrapped in double quotes, e.g. x1,x2,x3. This format is faster than usin...
void TokenizeLineQuoted(const std::string &line)
Tokenize a row with double quoted cells.
Definition: CsvGridRow.h:431
bool Empty() const
Get empty state of row.
Definition: CsvGridRow.h:251
C< T, std::allocator< T > > container_type
typedef for container type
Definition: CsvGridRow.h:140
File containing declarations relating various string utilities.
Cells may contain special, escaped, characters and are in double qoutes, e.g. "x1","x2","x3". This format is slower than simple formatting as care has to be taken with parsing special characters.
const cell_type & operator[](size_t col) const
Const subscript operator.
Definition: CsvGridRow.h:238
C< T, std::allocator< T > > container_type
Typedef to container type.
Definition: CsvGridRow.h:85
File containing declaration of DLL import/export control defines.
void CORE_LIBRARY_DLL_SHARED_API PackStdString(std::string &line)
Tidy a string obtained from getline function.
Definition: StringUtils.cpp:47
void OutputRowToStream(std::ostream &os) const
Write the row's contents to a stream object.
Definition: CsvGridRow.h:385
cell_type & operator[](size_t col)
Subscript operator.
Definition: CsvGridRow.h:218
void ResetRow()
Clear the entire row.
Definition: CsvGridRow.h:353
void LoadRowFromCsvFileLine(const std::string &line, eCellFormatOptions options)
Load a row from a line in a CSV file.
Definition: CsvGridRow.h:367
eCellFormatOptions
Cell format options enumeration.
Definition: CsvGridRow.h:61
T cell_type
typedef for container type
Definition: CsvGridRow.h:142
File containing declarations relating the Cell class.
Default container reserver functor.
Definition: CsvGridRow.h:81