Alexandria  2.16
Please provide a description of the project.
AsciiReaderHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef TABLE_ASCIIREADERHELPER_H
26 #define TABLE_ASCIIREADERHELPER_H
27 
28 #include <istream>
29 #include <string>
30 #include <typeindex>
31 #include <map>
32 
33 
34 #include "ElementsKernel/Export.h"
35 #include "Table/Row.h"
36 
37 namespace Euclid {
38 namespace Table {
39 
49 public:
50  explicit StreamRewinder(std::istream& stream) : m_stream(stream), m_state(stream.exceptions()), m_position(stream.tellg()) { }
52  m_stream.clear();
53  m_stream.seekg(m_position);
54  m_stream.setstate(m_state);
55  }
56 private:
57  std::istream& m_stream;
58  std::ios::iostate m_state;
60 };
61 
76 ELEMENTS_API size_t countColumns(std::istream& in, const std::string& comment);
77 
94 ELEMENTS_API std::map<std::string, ColumnDescription> autoDetectColumnDescriptions(
95  std::istream& in, const std::string& comment);
96 
112 ELEMENTS_API std::vector<std::string> autoDetectColumnNames(std::istream& in,
113  const std::string& comment,
114  size_t columns_number);
115 
129 ELEMENTS_API Row::cell_type convertToCellType(const std::string& value, std::type_index type);
130 
131 ELEMENTS_API bool hasNextRow(std::istream& in, const std::string& comment);
132 
133 ELEMENTS_API std::size_t countRemainingRows(std::istream& in, const std::string& comment);
134 
135 }
136 } // end of namespace Euclid
137 
138 #endif /* TABLE_ASCIIREADERHELPER_H */
std::size_t countRemainingRows(std::istream &in, const std::string &comment)
boost::variant< bool, int32_t, int64_t, float, double, std::string, std::vector< bool >, std::vector< int32_t >, std::vector< int64_t >, std::vector< float >, std::vector< double >, NdArray::NdArray< bool >, NdArray::NdArray< int32_t >, NdArray::NdArray< int64_t >, NdArray::NdArray< float >, NdArray::NdArray< double > > cell_type
The possible cell types.
Definition: Row.h:84
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.
#define ELEMENTS_API
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
This class gets a stream as argument during construction and when it is deleted it sets the position ...
bool hasNextRow(std::istream &in, const std::string &comment)
StreamRewinder(std::istream &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.