31 #include <boost/regex.hpp> 33 using boost::regex_match;
34 #include <boost/algorithm/string.hpp> 35 #include <boost/io/detail/quoted_manip.hpp> 53 : m_stream_holder(
std::move(stream_holder)) {
59 <<
"has started is not allowed";
61 if (indicator.empty()) {
71 <<
"has started is not allowed";
76 std::set<std::string>
set {};
77 regex vertical_whitespace {
".*\\v.*"};
82 if (regex_match(name, vertical_whitespace)) {
84 <<
"vertical whitespace characters";
86 if (!
set.insert(name).
second) {
101 <<
"has started is not allowed";
125 <<
") does not match the column names number (" 130 <<
") does not match the column types number (" 137 std::vector<std::string> names {};
138 std::vector<std::type_index> types {};
139 std::vector<std::string> units {};
140 std::vector<std::string> descriptions {};
141 for (
size_t i=0; i<columns_number; ++i) {
143 names.emplace_back(auto_names[i]);
147 auto info = auto_desc.find(auto_names[i]);
148 if (info != auto_desc.end()) {
150 types.emplace_back(info->second.type);
154 units.emplace_back(info->second.unit);
155 descriptions.emplace_back(info->second.description);
158 types.emplace_back(
typeid(std::string));
162 units.emplace_back(
"");
163 descriptions.emplace_back(
"");
178 auto pos = in.tellg();
185 std::ostringstream comment;
194 comment << line <<
'\n';
197 auto full_comment = comment.str();
198 boost::trim(full_comment);
206 std::vector<Row> row_list;
207 while(in && rows != 0) {
210 size_t comment_pos = line.find(
m_comment);
211 if (comment_pos != std::string::npos) {
212 line = line.substr(0, comment_pos);
217 std::stringstream line_stream(line);
219 std::vector<Row::cell_type> values {};
221 line_stream >> token;
222 while (line_stream) {
234 if (row_list.empty()) {
237 return Table{std::move(row_list)};
244 while(in && rows != 0) {
247 size_t comment_pos = line.find(
m_comment);
248 if (comment_pos != std::string::npos) {
249 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)
std::string quoted(const std::string &str)
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.