SectionPairRow.cpp 2.1 KB

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