KVReader.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2020-12-25
  7. *
  8. * */
  9. #include <ls_std/io/kv/KVReader.hpp>
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. #include <ls_std/io/FileReader.hpp>
  12. #include <ls_std/io/kv/KVParser.hpp>
  13. ls_std::KVReader::KVReader(const std::shared_ptr<ls_std::KVDocument> &_document, const std::string &_absolutePath) : ls_std::Class("KVReader"),
  14. kvFile(ls_std::File {""})
  15. {
  16. this->_assignDocument(_document);
  17. this->_assignFile(ls_std::File {_absolutePath});
  18. }
  19. ls_std::byte_field ls_std::KVReader::read()
  20. {
  21. ls_std::byte_field data = ls_std::FileReader {this->kvFile}.read();
  22. ls_std::KVParser {this->document}.parse(data);
  23. return data;
  24. }
  25. std::shared_ptr<ls_std::KVDocument> ls_std::KVReader::getDocument()
  26. {
  27. return this->document;
  28. }
  29. void ls_std::KVReader::setDocument(const std::shared_ptr<ls_std::KVDocument> &_document)
  30. {
  31. this->_assignDocument(_document);
  32. }
  33. void ls_std::KVReader::setFile(const ls_std::File &_kvFile)
  34. {
  35. this->_assignFile(_kvFile);
  36. }
  37. void ls_std::KVReader::_assignDocument(const std::shared_ptr<ls_std::KVDocument> &_document)
  38. {
  39. if(_document == nullptr) {
  40. throw ls_std::IllegalArgumentException {};
  41. }
  42. this->document = _document;
  43. }
  44. void ls_std::KVReader::_assignFile(ls_std::File _kvFile)
  45. {
  46. if(!_kvFile.exists()) {
  47. throw ls_std::IllegalArgumentException {};
  48. }
  49. this->kvFile = _kvFile;
  50. }