0.2.0
Loading...
Searching...
No Matches
FileReader.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <string>
17#include <vector>
18#include <fstream>
19#include <filesystem>
20
22
23#include <fmt/ostream.h>
24#include <nlohmann/json.hpp>
25using json = nlohmann::json;
26
27namespace NAV
28{
31{
32 public:
35 {
39 };
40
42 virtual ~FileReader() = default;
44 FileReader(const FileReader&) = delete;
48 FileReader& operator=(const FileReader&) = delete;
51
59
60 protected:
62 FileReader() = default;
63
70 GuiResult guiConfig(const char* vFilters, const std::vector<std::string>& extensions, size_t id, const std::string& nameId);
71
73 std::filesystem::path getFilepath();
74
76 [[nodiscard]] json save() const;
77
80 void restore(const json& j);
81
83 bool initialize();
84
87
90
93 [[nodiscard]] virtual FileType determineFileType();
94
99 virtual void readHeader();
100
103 auto& getline(std::string& str)
104 {
105 _lineCnt++;
106 return std::getline(_filestream, str);
107 }
108
113 auto readsome(char* s, std::streamsize count) { return _filestream.readsome(s, count); }
114
120 auto& read(char* __s, std::streamsize __n) { return _filestream.read(__s, __n); }
121
126 auto& ignore(std::streamsize count, int delim) { return _filestream.ignore(count, delim); }
127
133 auto& seekg(std::streamoff pos, std::ios_base::seekdir dir) { return _filestream.seekg(pos, dir); }
134
138 [[nodiscard]] std::streampos tellg() { return _filestream.tellg(); }
139
141 [[nodiscard]] auto eof() const { return _filestream.eof(); }
142
145 [[nodiscard]] bool good() const { return _filestream.good(); }
146
149 [[nodiscard]] auto peek() { return _filestream.peek(); }
150
152 [[nodiscard]] size_t getCurrentLineNumber() const { return _lineCnt; }
153
155 std::string _path;
158
160 std::vector<std::string> _headerColumns;
161
162 private:
164 std::ifstream _filestream;
166 std::streampos _dataStart = 0;
168 size_t _lineCnt = 0;
170 size_t _lineCntDataStart = 0;
171};
172
173} // namespace NAV
174
175#ifndef DOXYGEN_IGNORE
176
177template<>
178struct fmt::formatter<NAV::FileReader::FileType> : ostream_formatter
179{};
180
181#endif
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
The class is responsible for all time-related tasks.
Abstract File Reader class.
Definition FileReader.hpp:31
bool initialize()
Initialize the file reader.
void restore(const json &j)
Restores the node from a json object.
auto peek()
Looking ahead in the stream.
Definition FileReader.hpp:149
bool good() const
Fast error checking.
Definition FileReader.hpp:145
std::string _path
Path to the file.
Definition FileReader.hpp:155
auto & ignore(std::streamsize count, int delim)
Extracts and discards characters from the input stream until and including delim.
Definition FileReader.hpp:126
FileReader & operator=(FileReader &&)=delete
Move assignment operator.
FileType _fileType
File Type.
Definition FileReader.hpp:157
virtual FileType determineFileType()
Virtual Function to determine the File Type.
virtual ~FileReader()=default
Destructor.
GuiResult guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
auto eof() const
Check whether the end of file is reached.
Definition FileReader.hpp:141
FileReader & operator=(const FileReader &)=delete
Copy assignment operator.
auto & read(char *__s, std::streamsize __n)
Extraction without delimiters.
Definition FileReader.hpp:120
std::filesystem::path getFilepath()
Returns the path of the file.
std::vector< std::string > _headerColumns
Header Columns of a CSV file.
Definition FileReader.hpp:160
std::streampos tellg()
Getting the current read position.
Definition FileReader.hpp:138
FileReader(const FileReader &)=delete
Copy constructor.
void resetReader()
Moves the read cursor to the start.
virtual void readHeader()
Virtual Function to read the Header of a file.
auto & getline(std::string &str)
Reads a line from the filestream.
Definition FileReader.hpp:103
auto readsome(char *s, std::streamsize count)
Extracts up to count immediately available characters from the input stream. The extracted characters...
Definition FileReader.hpp:113
json save() const
Saves the node into a json object.
FileReader()=default
Default constructor.
auto & seekg(std::streamoff pos, std::ios_base::seekdir dir)
Changing the current read position.
Definition FileReader.hpp:133
size_t getCurrentLineNumber() const
Get the current line number.
Definition FileReader.hpp:152
FileReader(FileReader &&)=delete
Move constructor.
void deinitialize()
Deinitialize the file reader.
FileType
File Type Enumeration.
Definition FileReader.hpp:35
@ ASCII
Ascii text data.
Definition FileReader.hpp:38
@ BINARY
Binary data.
Definition FileReader.hpp:37
@ NONE
Not specified.
Definition FileReader.hpp:36
GuiResult
Results enum for the gui config.
Definition FileReader.hpp:54
@ PATH_UNCHANGED
No changes made.
Definition FileReader.hpp:55
@ PATH_CHANGED
The path changed and exists.
Definition FileReader.hpp:56
@ PATH_CHANGED_INVALID
The path changed but does not exist or is invalid.
Definition FileReader.hpp:57