1
1

jsonElement.hh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. virtual float diff(const JSonElement &) const;
  20. /**
  21. * get the number of col string will output
  22. **/
  23. virtual size_t strlen() const;
  24. virtual size_t lazystrlen();
  25. /**
  26. * return number of parents this item has
  27. **/
  28. unsigned int getLevel() const;
  29. /**
  30. * Get the parent element
  31. **/
  32. JSonElement *getParent();
  33. const JSonElement *getParent() const;
  34. /**
  35. * set parent.
  36. * Used for lazy-init
  37. **/
  38. void setParent(JSonElement *parent);
  39. /**
  40. * return previous child
  41. **/
  42. const JSonElement *findPrev() const;
  43. const JSonElement *findNext() const;
  44. /**
  45. * check if this element match SearchQuery
  46. **/
  47. virtual bool match(const SearchPattern &) 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. };