StorableFile.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-19
  6. * Changed: 2022-05-12
  7. *
  8. * */
  9. #include <ls_std/io/StorableFile.hpp>
  10. #include <ls_std/io/FileReader.hpp>
  11. #include <ls_std/io/FileWriter.hpp>
  12. ls::std::io::StorableFile::StorableFile(const ::std::string &_path)
  13. {
  14. this->_init(_path);
  15. }
  16. std::shared_ptr<ls::std::io::File> ls::std::io::StorableFile::getFile()
  17. {
  18. return this->file;
  19. }
  20. ls::std::core::type::byte_field ls::std::io::StorableFile::load()
  21. {
  22. ls::std::io::FileReader reader{*this->file};
  23. return reader.read();
  24. }
  25. void ls::std::io::StorableFile::reset(const ::std::string &_path)
  26. {
  27. this->_init(_path);
  28. }
  29. void ls::std::io::StorableFile::save(const ls::std::core::type::byte_field &_data)
  30. {
  31. ls::std::io::FileWriter writer{*this->file};
  32. writer.write(_data);
  33. }
  34. void ls::std::io::StorableFile::_init(const ::std::string &_path)
  35. {
  36. if (this->file == nullptr)
  37. {
  38. this->file = ::std::make_shared<ls::std::io::File>(_path);
  39. }
  40. else
  41. {
  42. this->file->reset(_path);
  43. }
  44. }