jsonElement.hh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * jsonElement.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include <string>
  8. class JSonContainer;
  9. class SearchPattern;
  10. class JSonElement
  11. {
  12. public:
  13. JSonElement(JSonElement *parent);
  14. virtual ~JSonElement();
  15. /**
  16. * return string-representative of this JSonElement
  17. **/
  18. virtual std::string stringify() const =0;
  19. /**
  20. * get the number of col string will output
  21. **/
  22. virtual size_t strlen() const;
  23. virtual size_t lazystrlen();
  24. /**
  25. * return number of parents this item has
  26. **/
  27. unsigned int getLevel() const;
  28. /**
  29. * Get the parent element
  30. **/
  31. JSonElement *getParent();
  32. const JSonElement *getParent() const;
  33. /**
  34. * set parent.
  35. * Used for lazy-init
  36. **/
  37. void setParent(JSonElement *parent);
  38. /**
  39. * return previous child
  40. **/
  41. const JSonElement *findPrev() const;
  42. const JSonElement *findNext() const;
  43. /**
  44. * check if this element match SearchQuery
  45. **/
  46. virtual bool match(const SearchPattern &) const;
  47. virtual bool operator==(const JSonElement *other) const;
  48. private:
  49. JSonElement();
  50. /**
  51. * parent container
  52. * Not a JSonContainer because JSonObjectEntry can be a parent and isn't a JSonContainer either
  53. **/
  54. JSonElement *parent;
  55. size_t _strlen;
  56. };