AbstractElement.cpp 2.4 KB

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