FileWriter.cpp 975 B

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