jsonObject.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "jsonObject.hh"
  2. #include "jsonPrimitive.hh"
  3. JSonObject::JSonObject(JSonContainer *p): JSonContainer(p)
  4. { }
  5. JSonObject::~JSonObject()
  6. {
  7. for (iterator i = begin(); i != end(); ++i)
  8. {
  9. delete (*i);
  10. }
  11. }
  12. void JSonObject::push(const std::string &key, JSonElement *child)
  13. {
  14. this->push_back(new JSonObjectEntry(this, key, child));
  15. }
  16. JSonObject::const_iterator JSonObject::find(const std::string &key) const
  17. {
  18. JSonObject::const_iterator it = cbegin();
  19. while (it != cend())
  20. {
  21. if ((const JSonObjectEntry &)(**it) == key)
  22. return it;
  23. ++it;
  24. }
  25. return it;
  26. }
  27. bool JSonObject::contains(const std::string &key) const
  28. {
  29. return find(key) != this->cend();
  30. }
  31. const JSonElement *JSonObject::get(const std::string &key) const
  32. {
  33. const_iterator item = find(key);
  34. if (item == cend())
  35. return nullptr;
  36. return *(const JSonObjectEntry &)(**item);
  37. }
  38. JSonElement *JSonObject::firstChild()
  39. {
  40. if (begin() == end())
  41. return nullptr;
  42. return *begin();
  43. }
  44. const JSonElement *JSonObject::firstChild() const
  45. {
  46. if (cbegin() == cend())
  47. return nullptr;
  48. return *cbegin();
  49. }
  50. std::string JSonObject::stringify() const
  51. {
  52. return "{ }";
  53. }