1
1

jsonObject.cpp 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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).second;
  10. }
  11. }
  12. void JSonObject::push(const std::string &key, JSonElement *child)
  13. {
  14. (*this)[key] = child;
  15. }
  16. bool JSonObject::contains(const std::string &key) const
  17. {
  18. return find(key) != end();
  19. }
  20. const JSonElement *JSonObject::get(const std::string &key) const
  21. {
  22. const_iterator item = find(key);
  23. return item == cend() ? nullptr : (*item).second;
  24. }
  25. unsigned int JSonObject::size() const
  26. {
  27. return std::map<std::string, JSonElement *>::size();
  28. }
  29. JSonElement *JSonObject::firstChild()
  30. {
  31. if (begin() == end())
  32. return nullptr;
  33. return (*begin()).second;
  34. }
  35. const JSonElement *JSonObject::firstChild() const
  36. {
  37. if (cbegin() == cend())
  38. return nullptr;
  39. return (*cbegin()).second;
  40. }
  41. std::string JSonObject::stringify() const
  42. {
  43. return "{ }";
  44. }