jsonObject.cpp 1.2 KB

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