31 #include <boost/regex.hpp> 33 using boost::regex_match;
34 #include <boost/algorithm/string.hpp> 52 : m_stream_holder(
std::move(stream_holder)) {
58 <<
"has started is not allowed";
60 if (indicator.
empty()) {
70 <<
"has started is not allowed";
76 regex whitespace {
".*\\s.*"};
81 if (regex_match(name, whitespace)) {
83 <<
"whitespace characters";
85 if (!set.insert(name).second) {
100 <<
"has started is not allowed";
124 <<
") does not match the column names number (" 129 <<
") does not match the column types number (" 140 for (
size_t i=0; i<columns_number; ++i) {
146 auto info = auto_desc.
find(auto_names[i]);
147 if (info != auto_desc.end()) {
149 types.emplace_back(info->second.type);
153 units.emplace_back(info->second.unit);
154 descriptions.emplace_back(info->second.description);
161 units.emplace_back(
"");
162 descriptions.emplace_back(
"");
177 auto pos = in.
tellg();
193 comment << line <<
'\n';
196 auto full_comment = comment.
str();
197 boost::trim(full_comment);
206 regex column_separator {
"\\s+"};
207 while(in && rows != 0) {
211 if (comment_pos != std::string::npos) {
212 line = line.
substr(0, comment_pos);
217 boost::sregex_token_iterator i (line.
begin(), line.
end(), column_separator, -1);
218 boost::sregex_token_iterator j;
233 if (row_list.
empty()) {
243 while(in && rows != 0) {
247 if (comment_pos != std::string::npos) {
248 line = line.
substr(0, comment_pos);
std::vector< std::type_index > m_column_types
std::size_t countRemainingRows(std::istream &in, const std::string &comment)
AsciiReader & setCommentIndicator(const std::string &indicator)
Set the comment indicator.
std::shared_ptr< ColumnInfo > createColumnInfo(const std::vector< std::string > &names, const std::vector< std::type_index > &types, const std::vector< std::string > &units, const std::vector< std::string > &descriptions)
Creates a ColumnInfo object from the given names and types.
std::shared_ptr< ColumnInfo > m_column_info
Row::cell_type convertToCellType(const std::string &value, std::type_index type)
Converts the given value to a Row::cell_type of the given type.
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
Table readImpl(long rows) override
Reads the next rows into a Table.
AsciiReader(std::istream &stream)
Constructs an AsciiReader which reads from the given stream.
TableReader implementation for reading ASCII tables from streams.
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
Represents one row of a Table.
bool hasNextRow(std::istream &in, const std::string &comment)
void skip(long rows) override
Implements the TableReader::skip() contract.
Provides information about the columns of a Table.
AsciiReader & fixColumnTypes(std::vector< std::type_index > column_types)
Overrides the automatically detected column types.
std::vector< std::string > m_column_names
std::string getComment() override
static std::string _peekLine(std::istream &in)
bool hasMoreRows() override
Implements the TableReader::hasMoreRows() contract.
size_t countColumns(std::istream &in, const std::string &comment)
Returns the number of whitespace separated tokens of the first non commented line.
AsciiReader & fixColumnNames(std::vector< std::string > column_names)
Overrides the automatically detected column names.
std::vector< std::string > autoDetectColumnNames(std::istream &in, const std::string &comment, size_t columns_number)
Reads the column names of the given stream.
T emplace_back(T... args)