jsonElement.hh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. virtual bool operator==(const JSonElement *other) const;
  49. private:
  50. JSonElement();
  51. /**
  52. * parent container
  53. * Not a JSonContainer because JSonObjectEntry can be a parent and isn't a JSonContainer either
  54. **/
  55. JSonElement *parent;
  56. size_t _strlen;
  57. };