SectionPairRow.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/SectionPairRowListValue.hpp>
  14. #include <ls-std/io/section-pair/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. bool ls::std::io::SectionPairRow::isList()
  26. {
  27. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE;
  28. }
  29. bool ls::std::io::SectionPairRow::isSingleValue()
  30. {
  31. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
  32. }
  33. void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
  34. {
  35. switch (_type)
  36. {
  37. case SECTION_PAIR_ROW_NOT_IMPLEMENTED:
  38. {
  39. throw ls::std::core::IllegalArgumentException{"default row enum type can not be set!"};
  40. }
  41. case SECTION_PAIR_ROW_LIST_VALUE:
  42. {
  43. this->value = ::std::make_shared<ls::std::io::SectionPairRowListValue>();
  44. }
  45. break;
  46. case SECTION_PAIR_ROW_SINGLE_VALUE:
  47. {
  48. this->value = ::std::make_shared<ls::std::io::SectionPairRowSingleValue>("empty");
  49. }
  50. break;
  51. }
  52. }
  53. void ls::std::io::SectionPairRow::_setKey(const ls::std::io::section_pair_identifier &_key)
  54. {
  55. ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
  56. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  57. this->key = _key;
  58. }