AbstractElement.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "AbstractElement.h"
  2. using namespace Framework;
  3. ElementPath::ElementPath(RCArray<Text>* path)
  4. : ReferenceCounter(),
  5. path(path),
  6. index(0)
  7. {}
  8. ElementPath::~ElementPath() {}
  9. bool Framework::ElementPath::isValid() const
  10. {
  11. return index < path->getEintragAnzahl();
  12. }
  13. bool Framework::ElementPath::hasNext() const
  14. {
  15. return index < path->getEintragAnzahl() - 1;
  16. }
  17. void Framework::ElementPath::next()
  18. {
  19. index++;
  20. }
  21. bool Framework::ElementPath::isObjectAttribute() const
  22. {
  23. return path->z(index)->hatAt(0, ".");
  24. }
  25. bool Framework::ElementPath::isArrayElement() const
  26. {
  27. return path->z(index)->hatAt(0, "[");
  28. }
  29. int Framework::ElementPath::getArrayIndex() const
  30. {
  31. Text result = path->z(index)->getText() + 1;
  32. return (int)result;
  33. }
  34. Text Framework::ElementPath::getObjectAttribute() const
  35. {
  36. return path->z(index)->getText() + 1;
  37. }
  38. Text Framework::ElementPath::toString() const
  39. {
  40. Text result = "value";
  41. for (Text* txt : *path)
  42. {
  43. result += *txt;
  44. }
  45. return result;
  46. }
  47. int Framework::ElementPath::getCurrentPathElementIndex() const
  48. {
  49. return index;
  50. }
  51. void Framework::ElementPath::setCurrentPathElementIndex(int index)
  52. {
  53. this->index = index;
  54. }
  55. ElementPathBuilder::ElementPathBuilder()
  56. : path(new RCArray<Text>())
  57. {}
  58. Framework::ElementPathBuilder::ElementPathBuilder(
  59. const ElementPathBuilder& other)
  60. : path(dynamic_cast<RCArray<Text>*>(path->getThis()))
  61. {}
  62. ElementPathBuilder::~ElementPathBuilder()
  63. {
  64. path->release();
  65. }
  66. ElementPathBuilder& ElementPathBuilder::appendArrayElement(int index)
  67. {
  68. path->add(new Text(Text("[") + Text(index) + "]"));
  69. return *this;
  70. }
  71. ElementPathBuilder& ElementPathBuilder::appendObjectElement(Text key)
  72. {
  73. path->add(new Text(Text(".") + key));
  74. return *this;
  75. }
  76. ElementPathBuilder& ElementPathBuilder::prependArrayElement(int index)
  77. {
  78. path->add(new Text(Text("[") + Text(index) + "]"), 0);
  79. return *this;
  80. }
  81. ElementPathBuilder& ElementPathBuilder::prependObjectElement(Text key)
  82. {
  83. path->add(new Text(Text(".") + key), 0);
  84. return *this;
  85. }
  86. ElementPath* ElementPathBuilder::build()
  87. {
  88. return new ElementPath(dynamic_cast<RCArray<Text>*>(path->getThis()));
  89. }
  90. ElementPathBuilder& Framework::ElementPathBuilder::operator=(
  91. const ElementPathBuilder& other)
  92. {
  93. if (path) path->release();
  94. path = dynamic_cast<RCArray<Text>*>(other.path->getThis());
  95. return *this;
  96. }