| Line | Branch | Exec | Source |
|---|---|---|---|
| 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> | ||
| 21 | using json = nlohmann::json; ///< json namespace | ||
| 22 | |||
| 23 | namespace NAV | ||
| 24 | { | ||
| 25 | /// @brief Parent class for other data loggers which manages the output filestream | ||
| 26 | class FileWriter | ||
| 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 | 814 | ~FileWriter() = default; | |
| 44 | /// @brief Copy constructor | ||
| 45 | FileWriter(const FileWriter&) = delete; | ||
| 46 | /// @brief Move constructor | ||
| 47 | FileWriter(FileWriter&&) = delete; | ||
| 48 | /// @brief Copy assignment operator | ||
| 49 | FileWriter& operator=(const FileWriter&) = delete; | ||
| 50 | /// @brief Move assignment operator | ||
| 51 | FileWriter& operator=(FileWriter&&) = delete; | ||
| 52 | |||
| 53 | protected: | ||
| 54 | /// @brief Default constructor | ||
| 55 |
1/2✓ Branch 2 taken 814 times.
✗ Branch 3 not taken.
|
814 | 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 | ||
| 88 | FileType _fileType = FileType::NONE; | ||
| 89 | }; | ||
| 90 | |||
| 91 | } // namespace NAV | ||
| 92 |