FileWriter.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2023-05-16
  7. *
  8. * */
  9. #include <fstream>
  10. #include <ls-std/io/FileWriter.hpp>
  11. #include <ls-std/io/evaluator/FileExistenceEvaluator.hpp>
  12. using ls::std::core::Class;
  13. using ls::std::core::type::byte_field;
  14. using ls::std::io::File;
  15. using ls::std::io::FileExistenceEvaluator;
  16. using ls::std::io::FileWriter;
  17. using ::std::ofstream;
  18. FileWriter::FileWriter(const File &_file) : Class("FileWriter"), file(_file)
  19. {
  20. FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate();
  21. }
  22. FileWriter::~FileWriter() noexcept = default;
  23. void FileWriter::reset(const File &_file)
  24. {
  25. FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate();
  26. this->file = _file;
  27. }
  28. bool FileWriter::write(const byte_field &_data)
  29. {
  30. ofstream outputStream{};
  31. outputStream.open(this->file.getAbsoluteFilePath());
  32. outputStream << _data;
  33. return !outputStream.fail();
  34. }