25#include <boost/algorithm/string.hpp>
29#if BOOST_VERSION < 107300
30#include <boost/io/detail/quoted_manip.hpp>
32#include <boost/io/quoted.hpp>
47 auto pos = in.
tellg();
58 : m_stream_holder(
std::move(stream_holder)) {}
63 <<
"has started is not allowed";
65 if (indicator.
empty()) {
75 <<
"has started is not allowed";
81 static const regex::regex vertical_whitespace{
".*[\\n\\v\\f\\r].*"};
87 if (regex_match(name, vertical_whitespace)) {
89 <<
"vertical whitespace characters";
91 if (!set.insert(name).second) {
105 <<
"has started is not allowed";
109 [](
std::type_index type) { return std::make_pair(type, std::size_t(0)); });
121 <<
"has started is not allowed";
160 for (
size_t i = 0; i < columns_number; ++i) {
166 auto info = auto_desc.find(auto_names[i]);
167 if (info != auto_desc.end()) {
169 types.
emplace_back(info->second.type, info->second.size);
178 }
else if (i < first_line.size()) {
205 comment << line <<
'\n';
208 auto full_comment = comment.
str();
209 boost::trim(full_comment);
218 while (in && rows != 0) {
222 if (tokens.empty()) {
233 return convertToCellType(token, m_column_info->getDescription(index++).type);
238 if (row_list.
empty()) {
248 while (in && rows != 0) {
252 if (comment_pos != std::string::npos) {
253 line = line.
substr(0, comment_pos);
T back_inserter(T... args)
TableReader implementation for reading ASCII tables from streams.
void skip(long rows) override
Implements the TableReader::skip() contract.
std::string getComment() override
AsciiReader & fixColumnNames(std::vector< std::string > column_names)
Overrides the automatically detected column names.
std::vector< std::string > m_column_names
AsciiReader(std::istream &stream)
Constructs an AsciiReader which reads from the given stream.
AsciiReader & fixColumnTypes(std::vector< std::type_index > column_types)
Overrides the automatically detected column types.
Table readImpl(long rows) override
Reads the next rows into a Table.
std::vector< std::pair< std::type_index, std::size_t > > m_column_types
bool hasMoreRows() override
Implements the TableReader::hasMoreRows() contract.
std::shared_ptr< ColumnInfo > m_column_info
const ColumnInfo & getInfo() override
Returns the column information of the table.
std::size_t rowsLeft() override
Implements the TableReader::rowsLeft() contract.
std::unique_ptr< InstOrRefHolder< std::istream > > m_stream_holder
AsciiReader & setCommentIndicator(const std::string &indicator)
Set the comment indicator.
Provides information about the columns of a Table.
Represents one row of a Table.
T emplace_back(T... args)
std::vector< std::string > splitLine(std::string line, const std::string &comment)
bool hasNextRow(std::istream &in, const std::string &comment)
static std::string _peekLine(std::istream &in)
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
size_t countColumns(std::istream &in, const std::string &comment)
Returns the number of whitespace separated tokens of the first non commented line.
std::vector< std::string > autoDetectColumnNames(std::istream &in, const std::string &comment, size_t columns_number)
Reads the column names of the given stream.
std::pair< std::type_index, std::size_t > guessColumnType(const std::string &token)
std::vector< std::string > firstDataLine(std::istream &in, const std::string &comment)
std::shared_ptr< ColumnInfo > createColumnInfo(const std::vector< std::string > &names, const std::vector< std::pair< std::type_index, std::size_t > > &types, const std::vector< std::string > &units, const std::vector< std::string > &descriptions)
Creates a ColumnInfo object from the given names and types.
std::size_t countRemainingRows(std::istream &in, const std::string &comment)