Alexandria  2.27.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsciiReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2022 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_ASCIIREADER_H
26 #define _TABLE_ASCIIREADER_H
27 
29 #include "Table/TableReader.h"
30 
31 namespace Euclid {
32 namespace Table {
33 
87 class AsciiReader : public TableReader {
88 
89 public:
115  template <typename StreamType, typename... Args>
116  static AsciiReader create(Args&&... args);
117 
119  explicit AsciiReader(std::istream& stream);
120 
122  explicit AsciiReader(const std::string& filename);
123 
124  AsciiReader(AsciiReader&&) = default;
125  AsciiReader& operator=(AsciiReader&&) = default;
126 
127  AsciiReader(const AsciiReader&) = delete;
128  AsciiReader& operator=(const AsciiReader&) = delete;
129 
133  virtual ~AsciiReader() = default;
134 
144  AsciiReader& setCommentIndicator(const std::string& indicator);
145 
161 
173 
175 
189  const ColumnInfo& getInfo() override;
190 
194  std::string getComment() override;
195 
197  void skip(long rows) override;
198 
200  bool hasMoreRows() override;
201 
203  std::size_t rowsLeft() override;
204 
205 protected:
222  Table readImpl(long rows) override;
223 
224 private:
226 
227  void readColumnInfo();
228 
230  bool m_reading_started = false;
235 
236 }; /* End of AsciiReader class */
237 
238 } /* namespace Table */
239 } /* namespace Euclid */
240 
241 #include "_impl/AsciiReader.icpp"
242 
243 #endif
Interface for classes reading tables.
Definition: TableReader.h:48
AsciiReader & setCommentIndicator(const std::string &indicator)
Set the comment indicator.
Definition: AsciiReader.cpp:60
std::shared_ptr< ColumnInfo > m_column_info
Definition: AsciiReader.h:234
STL class.
AsciiReader & operator=(AsciiReader &&)=default
const ColumnInfo & getInfo() override
Returns the column information of the table.
STL class.
std::vector< std::pair< std::type_index, std::size_t > > m_column_types
Definition: AsciiReader.h:232
std::size_t rowsLeft() override
Implements the TableReader::rowsLeft() contract.
std::unique_ptr< InstOrRefHolder< std::istream > > m_stream_holder
Definition: AsciiReader.h:229
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.
Definition: AsciiReader.cpp:53
TableReader implementation for reading ASCII tables from streams.
Definition: AsciiReader.h:87
Represents a table.
Definition: Table.h:49
void skip(long rows) override
Implements the TableReader::skip() contract.
Provides information about the columns of a Table.
Definition: ColumnInfo.h:52
STL class.
AsciiReader & fixColumnTypes(std::vector< std::type_index > column_types)
Overrides the automatically detected column types.
std::vector< std::string > m_column_names
Definition: AsciiReader.h:233
std::string getComment() override
bool hasMoreRows() override
Implements the TableReader::hasMoreRows() contract.
virtual ~AsciiReader()=default
Destructor.
static AsciiReader create(Args &&...args)
Constructs an AsciiReader which contains an object of type StreamType.
AsciiReader & fixColumnNames(std::vector< std::string > column_names)
Overrides the automatically detected column names.
Definition: AsciiReader.cpp:72