FileOutputStream.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2020-08-20
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #ifndef LS_STD_FILE_OUTPUT_STREAM_HPP
  11. #define LS_STD_FILE_OUTPUT_STREAM_HPP
  12. #include "File.hpp"
  13. #include <fstream>
  14. #include <ls-std/core/Class.hpp>
  15. #include <ls-std/core/interface/IWriter.hpp>
  16. #include <ls-std/os/dynamic-goal.hpp>
  17. /*
  18. * @doc: class(name: 'FileOutputStream', package: 'io')
  19. * @doc: io.FileOutputStream.description('This class can be used for writing to a file stream.')
  20. * */
  21. namespace ls::standard::io
  22. {
  23. class LS_STD_DYNAMIC_GOAL FileOutputStream : public ls::standard::core::Class, public ls::standard::core::interface_type::IWriter
  24. {
  25. public:
  26. explicit FileOutputStream(const ls::standard::io::File &_file);
  27. explicit FileOutputStream(const ls::standard::io::File &_file, bool _append);
  28. ~FileOutputStream() noexcept override;
  29. void close();
  30. bool write(const ls::standard::core::type::byte_field &_data) override; // nodiscard is optional here
  31. private:
  32. bool append{};
  33. ls::standard::io::File file;
  34. ::std::ofstream outputStream{};
  35. void _close();
  36. void _init();
  37. };
  38. }
  39. #endif