0.4.1
Loading...
Searching...
No Matches
FileWriter.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
9/// @file FileWriter.hpp
10/// @brief File Writer class
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2020-03-16
13
14#pragma once
15
16#include <string>
17#include <fstream>
18#include <filesystem>
19
20#include <nlohmann/json.hpp>
21using json = nlohmann::json; ///< json namespace
22
23namespace NAV
24{
25/// @brief Parent class for other data loggers which manages the output filestream
27{
28 public:
29 /// File Type
30 enum class FileType : uint8_t
31 {
32 NONE, ///< Not specified
33 BINARY, ///< Binary data
34 ASCII, ///< Ascii text data
35 };
36
37 /// @brief Converts the provided type into string
38 /// @param[in] type FileType to convert
39 /// @return String representation of the type
40 static const char* to_string(FileType type);
41
42 /// @brief Destructor
43 ~FileWriter() = default;
44 /// @brief Copy constructor
45 FileWriter(const FileWriter&) = delete;
46 /// @brief Move constructor
48 /// @brief Copy assignment operator
49 FileWriter& operator=(const FileWriter&) = delete;
50 /// @brief Move assignment operator
52
53 protected:
54 /// @brief Default constructor
55 FileWriter() = default;
56
57 /// @brief ImGui config
58 /// @param[in] vFilters Filter to apply for file names
59 /// @param[in] extensions Extensions to filter
60 /// @param[in] id Unique id for creating the dialog uid
61 /// @param[in] nameId Name of the node triggering the window used for logging
62 /// @return True if changes occurred
63 bool guiConfig(const char* vFilters, const std::vector<std::string>& extensions, size_t id, const std::string& nameId);
64
65 /// @brief Returns the path of the file
66 std::filesystem::path getFilepath();
67
68 /// @brief Saves the node into a json object
69 [[nodiscard]] json save() const;
70
71 /// @brief Restores the node from a json object
72 /// @param[in] j Json object with the node state
73 void restore(const json& j);
74
75 /// @brief Initialize the file reader
76 bool initialize();
77
78 /// @brief Deinitialize the file reader
79 void deinitialize();
80
81 /// Path to the file
82 std::string _path;
83
84 /// File stream to write the file
85 std::ofstream _filestream;
86
87 /// File Type
89};
90
91} // namespace NAV
nlohmann::json json
json namespace
std::string _path
Path to the file.
FileType
File Type.
@ ASCII
Ascii text data.
FileWriter()=default
Default constructor.
FileWriter(const FileWriter &)=delete
Copy constructor.
FileType _fileType
File Type.
FileWriter & operator=(FileWriter &&)=delete
Move assignment operator.
static const char * to_string(FileType type)
Converts the provided type into string.
~FileWriter()=default
Destructor.
FileWriter(FileWriter &&)=delete
Move constructor.
void deinitialize()
Deinitialize the file reader.
FileWriter & operator=(const FileWriter &)=delete
Copy assignment operator.
bool guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
std::filesystem::path getFilepath()
Returns the path of the file.
void restore(const json &j)
Restores the node from a json object.
json save() const
Saves the node into a json object.
bool initialize()
Initialize the file reader.
std::ofstream _filestream
File stream to write the file.