SectionPairRow.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2023-02-10
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
  10. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  11. #include <ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
  12. #include <ls-std/io/section-pair/SectionPairRow.hpp>
  13. #include <ls-std/io/section-pair/SectionPairRowSingleValue.hpp>
  14. ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key, const ls::std::io::SectionPairRowEnumType &_type) : ls::std::core::Class("SectionPairRow")
  15. {
  16. this->_setKey(_key);
  17. this->_initValue(_type);
  18. }
  19. ls::std::io::SectionPairRow::~SectionPairRow() = default;
  20. ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
  21. {
  22. return this->key;
  23. }
  24. bool ls::std::io::SectionPairRow::isList()
  25. {
  26. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST;
  27. }
  28. bool ls::std::io::SectionPairRow::isSingleValue()
  29. {
  30. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
  31. }
  32. void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
  33. {
  34. switch (_type)
  35. {
  36. case SECTION_PAIR_ROW_NOT_IMPLEMENTED:
  37. {
  38. throw ls::std::core::IllegalArgumentException{"default row enum type can not be set!"};
  39. }
  40. case SECTION_PAIR_ROW_LIST:
  41. {
  42. }
  43. break;
  44. case SECTION_PAIR_ROW_SINGLE_VALUE:
  45. {
  46. this->value = ::std::make_shared<ls::std::io::SectionPairRowSingleValue>("empty");
  47. }
  48. break;
  49. }
  50. }
  51. void ls::std::io::SectionPairRow::_setKey(const ls::std::io::section_pair_identifier &_key)
  52. {
  53. ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
  54. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  55. this->key = _key;
  56. }