Alexandria
2.18
Please provide a description of the project.
|
Go to the documentation of this file.
31 #include <boost/regex.hpp>
33 using boost::regex_match;
34 #include <boost/algorithm/string.hpp>
36 #if BOOST_VERSION < 107300
37 #include <boost/io/detail/quoted_manip.hpp>
39 #include <boost/io/quoted.hpp>
56 : m_stream_holder(
std::move(stream_holder)) {}
61 <<
"has started is not allowed";
63 if (indicator.
empty()) {
73 <<
"has started is not allowed";
79 regex vertical_whitespace{
".*\\v.*"};
84 if (regex_match(name, vertical_whitespace)) {
86 <<
"vertical whitespace characters";
88 if (!set.insert(name).second) {
102 <<
"has started is not allowed";
124 throw Elements::Exception() <<
"Columns number in stream (" << columns_number <<
") does not match the column names number ("
128 throw Elements::Exception() <<
"Columns number in stream (" << columns_number <<
") does not match the column types number ("
139 for (
size_t i = 0; i < columns_number; ++i) {
145 auto info = auto_desc.
find(auto_names[i]);
146 if (info != auto_desc.end()) {
148 types.emplace_back(info->second.type);
152 units.emplace_back(info->second.unit);
153 descriptions.emplace_back(info->second.description);
160 units.emplace_back(
"");
161 descriptions.emplace_back(
"");
174 auto pos = in.
tellg();
190 comment << line <<
'\n';
193 auto full_comment = comment.
str();
194 boost::trim(full_comment);
203 while (in && rows != 0) {
207 if (comment_pos != std::string::npos) {
208 line = line.
substr(0, comment_pos);
217 line_stream >> token;
218 while (line_stream) {
230 if (row_list.
empty()) {
240 while (in && rows != 0) {
244 if (comment_pos != std::string::npos) {
245 line = line.
substr(0, comment_pos);
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.
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)
bool hasMoreRows() override
Implements the TableReader::hasMoreRows() contract.
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
AsciiReader & fixColumnNames(std::vector< std::string > column_names)
Overrides the automatically detected column names.
AsciiReader & setCommentIndicator(const std::string &indicator)
Set the comment indicator.
std::vector< std::type_index > m_column_types
AsciiReader(std::istream &stream)
Constructs an AsciiReader which reads from the given stream.
std::unique_ptr< InstOrRefHolder< std::istream > > m_stream_holder
Provides information about the columns of a Table.
bool hasNextRow(std::istream &in, const std::string &comment)
std::shared_ptr< ColumnInfo > m_column_info
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::string getComment() override
std::string quoted(const std::string &str)
std::size_t rowsLeft() override
Implements the TableReader::rowsLeft() contract.
void skip(long rows) override
Implements the TableReader::skip() contract.
const ColumnInfo & getInfo() override
Returns the column information of the table.
TableReader implementation for reading ASCII tables from streams.
T emplace_back(T... args)
Table readImpl(long rows) override
Reads the next rows into a Table.
size_t countColumns(std::istream &in, const std::string &comment)
Returns the number of whitespace separated tokens of the first non commented line.
Represents one row of a Table.
std::vector< std::string > m_column_names
static std::string _peekLine(std::istream &in)
AsciiReader & fixColumnTypes(std::vector< std::type_index > column_types)
Overrides the automatically detected column types.