json_writer.hpp 890 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <fstream>
  2. #include "../lib/nlohmann/json.hpp"
  3. #include "colors.hpp"
  4. #ifndef _JSON_WRITER_HPP_
  5. #define _JSON_WRITER_HPP_
  6. namespace alex
  7. {
  8. /**
  9. * @class JsonWriter
  10. *
  11. * @brief Simple json writer class which create file and write data in json format to file
  12. */
  13. class JsonWriter
  14. {
  15. public:
  16. JsonWriter() noexcept;
  17. JsonWriter(const std::string& filename) noexcept;
  18. JsonWriter(const JsonWriter&) = delete;
  19. JsonWriter& operator=(const JsonWriter&) = delete;
  20. ~JsonWriter() noexcept;
  21. inline void set_filename(const std::string& new_filename) noexcept
  22. { m_filename = new_filename; }
  23. void write(const nlohmann::json& json_format_text) noexcept;
  24. private:
  25. std::string m_filename;
  26. std::ofstream m_out_file_stream;
  27. };
  28. } // namespace alex
  29. #endif // _JSON_WRITER_HPP_