SectionPairRow.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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-12
  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::setKey(const ls::std::io::section_pair_identifier &_key)
  38. {
  39. this->_setKey(_key);
  40. }
  41. void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
  42. {
  43. switch (_type)
  44. {
  45. case SECTION_PAIR_ROW_NOT_IMPLEMENTED:
  46. {
  47. throw ls::std::core::IllegalArgumentException{"default row enum type can not be set!"};
  48. }
  49. case SECTION_PAIR_ROW_LIST_VALUE:
  50. {
  51. this->value = ::std::make_shared<ls::std::io::SectionPairRowListValue>();
  52. }
  53. break;
  54. case SECTION_PAIR_ROW_SINGLE_VALUE:
  55. {
  56. this->value = ::std::make_shared<ls::std::io::SectionPairRowSingleValue>("empty");
  57. }
  58. break;
  59. }
  60. }
  61. void ls::std::io::SectionPairRow::_setKey(const ls::std::io::section_pair_identifier &_key)
  62. {
  63. ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
  64. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  65. this->key = _key;
  66. }