SectionPairRow.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
  11. #include <ls-std/io/section-pair/SectionPairRow.hpp>
  12. #include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
  13. ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key) : ls::std::core::Class("SectionPairRow")
  14. {
  15. ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
  16. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  17. this->key = _key;
  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. ::std::string ls::std::io::SectionPairRow::getValue()
  25. {
  26. return this->values.empty() ? "" : this->values.front();
  27. }
  28. bool ls::std::io::SectionPairRow::isKeyValue()
  29. {
  30. return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_KEY_VALUE;
  31. }
  32. bool ls::std::io::SectionPairRow::isList()
  33. {
  34. return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST;
  35. }
  36. void ls::std::io::SectionPairRow::setValue(const ls::std::io::section_pair_row_value &_value)
  37. {
  38. ls::std::core::EmptyStringArgumentEvaluator{_value, "passed value for section pair row is empty!"}.evaluate();
  39. ls::std::io::SectionPairRowValueArgumentEvaluator{_value, "passed value for section pair row \"" + _value + "\" contains invalid characters!"}.evaluate();
  40. this->_setType(ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_KEY_VALUE);
  41. this->_setValue(_value);
  42. }
  43. void ls::std::io::SectionPairRow::_setType(const ls::std::io::SectionPairRowEnumType &_type)
  44. {
  45. if (_type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_NOT_IMPLEMENTED)
  46. {
  47. this->type = _type;
  48. }
  49. }
  50. void ls::std::io::SectionPairRow::_setValue(const ls::std::io::section_pair_row_value &_value)
  51. {
  52. if (!this->values.empty())
  53. {
  54. this->values.pop_front();
  55. }
  56. this->values.push_back(_value);
  57. }