AbstractElement.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "Array.h"
  3. #include "Text.h"
  4. namespace Framework
  5. {
  6. enum class AbstractType
  7. {
  8. NULL_,
  9. BOOLEAN,
  10. NUMBER,
  11. STRING,
  12. ARRAY,
  13. OBJECT
  14. };
  15. class AbstractBool;
  16. class AbstractNumber;
  17. class AbstractString;
  18. class AbstractArray;
  19. class AbstractObject;
  20. class AbstractElement : public virtual ReferenceCounter
  21. {
  22. public:
  23. virtual AbstractType getType() const = 0;
  24. virtual const AbstractBool* asAbstractBool() const = 0;
  25. virtual const AbstractNumber* asAbstractNumber() const = 0;
  26. virtual const AbstractString* asAbstractString() const = 0;
  27. virtual const AbstractArray* asAbstractArray() const = 0;
  28. virtual const AbstractObject* asAbstractObject() const = 0;
  29. virtual Text toString() const = 0;
  30. };
  31. class AbstractBool : public virtual AbstractElement
  32. {
  33. public:
  34. virtual bool getBool() const = 0;
  35. };
  36. class AbstractNumber : public virtual AbstractElement
  37. {
  38. public:
  39. virtual double getNumber() const = 0;
  40. };
  41. class AbstractString : public virtual AbstractElement
  42. {
  43. public:
  44. virtual Text getString() const = 0;
  45. };
  46. class AbstractArray : public virtual AbstractElement
  47. {
  48. public:
  49. virtual AbstractElement* zAbstractValue(int i) const = 0;
  50. virtual int getLength() const = 0;
  51. };
  52. class AbstractObject : public virtual AbstractElement
  53. {
  54. public:
  55. virtual AbstractElement* zAbstractValue(Text field) const = 0;
  56. virtual int getFieldCount() const = 0;
  57. virtual Text getFieldKey(int i) const = 0;
  58. virtual AbstractElement* zAbstractValue(int i) const = 0;
  59. virtual bool hasValue(Text field) const = 0;
  60. };
  61. class ElementPathBuilder;
  62. class ElementPath : public virtual ReferenceCounter
  63. {
  64. private:
  65. RCArray<Text>* path;
  66. int index;
  67. __declspec(dllexport) ElementPath(RCArray<Text>* path);
  68. public:
  69. __declspec(dllexport) ~ElementPath();
  70. __declspec(dllexport) bool isValid() const;
  71. __declspec(dllexport) bool hasNext() const;
  72. __declspec(dllexport) void next();
  73. __declspec(dllexport) bool isObjectAttribute() const;
  74. __declspec(dllexport) bool isArrayElement() const;
  75. __declspec(dllexport) int getArrayIndex() const;
  76. __declspec(dllexport) Text getObjectAttribute() const;
  77. __declspec(dllexport) Text toString() const;
  78. __declspec(dllexport) int getCurrentPathElementIndex() const;
  79. __declspec(dllexport) void setCurrentPathElementIndex(int index);
  80. friend ElementPathBuilder;
  81. };
  82. class ElementPathBuilder
  83. {
  84. private:
  85. RCArray<Text>* path;
  86. public:
  87. __declspec(dllexport) ElementPathBuilder();
  88. __declspec(dllexport) ElementPathBuilder(
  89. const ElementPathBuilder& other);
  90. __declspec(dllexport) ~ElementPathBuilder();
  91. __declspec(dllexport) ElementPathBuilder& appendArrayElement(int index);
  92. __declspec(dllexport) ElementPathBuilder& appendObjectElement(Text key);
  93. __declspec(dllexport) ElementPathBuilder& prependArrayElement(
  94. int index);
  95. __declspec(dllexport) ElementPathBuilder& prependObjectElement(
  96. Text key);
  97. __declspec(dllexport) ElementPath* build();
  98. __declspec(dllexport) ElementPathBuilder& operator=(
  99. const ElementPathBuilder& other);
  100. };
  101. } // namespace Framework