XMLReader.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-10
  6. * Changed: 2020-10-10
  7. *
  8. * */
  9. #include "XMLReader.hpp"
  10. #include "../../exception/IllegalArgumentException.hpp"
  11. #include "../FileReader.hpp"
  12. ls_std::XMLReader::XMLReader(const std::shared_ptr<ls_std::XMLDocument>& _document, const std::string& _absolutePath) :
  13. Class("XMLReader"),
  14. xmlFile(ls_std::File {_absolutePath}),
  15. document(_document)
  16. {
  17. XMLReader::_checkDocumentExistence(_document);
  18. XMLReader::_checkFileExistence(this->xmlFile);
  19. }
  20. ls_std::byte_field ls_std::XMLReader::read()
  21. {
  22. ls_std::byte_field data = ls_std::FileReader {this->xmlFile}.read();
  23. this->_read(data);
  24. return data;
  25. }
  26. std::shared_ptr<ls_std::XMLDocument> ls_std::XMLReader::getDocument()
  27. {
  28. return this->document;
  29. }
  30. void ls_std::XMLReader::setFile(const ls_std::File &_xmlFile)
  31. {
  32. XMLReader::_checkFileExistence(_xmlFile);
  33. this->xmlFile = _xmlFile;
  34. }
  35. void ls_std::XMLReader::_checkDocumentExistence(const std::shared_ptr<ls_std::XMLDocument>& _document)
  36. {
  37. if(_document == nullptr) {
  38. throw ls_std::IllegalArgumentException {};
  39. }
  40. }
  41. void ls_std::XMLReader::_checkFileExistence(ls_std::File _xmlFile)
  42. {
  43. if(!_xmlFile.exists()) {
  44. throw ls_std::IllegalArgumentException {};
  45. }
  46. }
  47. void ls_std::XMLReader::_read(const ls_std::byte_field &_data)
  48. {
  49. uint8_t mode {};
  50. for(std::string::size_type i = 0 ; i < _data.size() ; i++) {
  51. switch(mode)
  52. {
  53. case 1: // xml declaration
  54. {
  55. } break;
  56. case 2: // xml opening tag
  57. {
  58. } break;
  59. case 3: // xml closing tag
  60. {
  61. } break;
  62. case 4: // xml attribute
  63. {
  64. } break;
  65. }
  66. }
  67. }