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>
50 : m_stream_holder(
std::move(stream_holder)) {}
55 <<
"has started is not allowed";
57 if (indicator.
empty()) {
67 <<
"has started is not allowed";
73 static const regex::regex vertical_whitespace{
".*[\\n\\v\\f\\r].*"};
78 if (regex_match(name, vertical_whitespace)) {
80 <<
"vertical whitespace characters";
82 if (!set.insert(name).second) {
96 <<
"has started is not allowed";
133 for (
size_t i = 0; i < columns_number; ++i) {
139 auto info = auto_desc.
find(auto_names[i]);
140 if (info != auto_desc.end()) {
142 types.emplace_back(info->second.type);
146 units.emplace_back(info->second.unit);
147 descriptions.emplace_back(info->second.description);
154 units.emplace_back(
"");
155 descriptions.emplace_back(
"");
168 auto pos = in.
tellg();
184 comment << line <<
'\n';
187 auto full_comment = comment.
str();
188 boost::trim(full_comment);
197 while (in && rows != 0) {
201 if (comment_pos != std::string::npos) {
202 line = line.
substr(0, comment_pos);
211 line_stream >> token;
212 while (line_stream) {
224 if (row_list.
empty()) {
234 while (in && rows != 0) {
238 if (comment_pos != std::string::npos) {
239 line = line.
substr(0, comment_pos);
TableReader implementation for reading ASCII tables from streams.
void skip(long rows) override
Implements the TableReader::skip() contract.
std::vector< std::type_index > m_column_types
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.
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)
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.
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.
std::size_t countRemainingRows(std::istream &in, const std::string &comment)
std::string quoted(const std::string &str)
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.