SectionPairRow.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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-11
  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/evaluator/SectionPairIdentifierArgumentEvaluator.hpp>
  12. #include <ls-std/io/section-pair/model/SectionPairRow.hpp>
  13. #include <ls-std/io/section-pair/model/SectionPairRowListValue.hpp>
  14. #include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
  15. ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key, const ls::std::io::SectionPairRowEnumType &_type) : ls::std::core::Class("SectionPairRow")
  16. {
  17. this->_setKey(_key);
  18. this->_initValue(_type);
  19. }
  20. ls::std::io::SectionPairRow::~SectionPairRow() = default;
  21. ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
  22. {
  23. return this->key;
  24. }
  25. ::std::shared_ptr<ls::std::io::SectionPairRowValue> ls::std::io::SectionPairRow::getValue()
  26. {
  27. return this->value;
  28. }
  29. bool ls::std::io::SectionPairRow::isList()
  30. {
  31. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE;
  32. }
  33. bool ls::std::io::SectionPairRow::isSingleValue()
  34. {
  35. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
  36. }
  37. void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
  38. {
  39. switch (_type)
  40. {
  41. case SECTION_PAIR_ROW_NOT_IMPLEMENTED:
  42. {
  43. throw ls::std::core::IllegalArgumentException{"default row enum type can not be set!"};
  44. }
  45. case SECTION_PAIR_ROW_LIST_VALUE:
  46. {
  47. this->value = ::std::make_shared<ls::std::io::SectionPairRowListValue>();
  48. }
  49. break;
  50. case SECTION_PAIR_ROW_SINGLE_VALUE:
  51. {
  52. this->value = ::std::make_shared<ls::std::io::SectionPairRowSingleValue>("empty");
  53. }
  54. break;
  55. }
  56. }
  57. void ls::std::io::SectionPairRow::_setKey(const ls::std::io::section_pair_identifier &_key)
  58. {
  59. ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
  60. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  61. this->key = _key;
  62. }