JSONFile.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Resource/Resource.h"
  5. #include "../Resource/JSONValue.h"
  6. namespace Urho3D
  7. {
  8. /// JSON document resource.
  9. class URHO3D_API JSONFile : public Resource
  10. {
  11. URHO3D_OBJECT(JSONFile, Resource);
  12. public:
  13. /// Construct.
  14. explicit JSONFile(Context* context);
  15. /// Destruct.
  16. ~JSONFile() override;
  17. /// Register object factory.
  18. /// @nobind
  19. static void RegisterObject(Context* context);
  20. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  21. bool BeginLoad(Deserializer& source) override;
  22. /// Save resource with default indentation (one tab). Return true if successful.
  23. bool Save(Serializer& dest) const override;
  24. /// Save resource with user-defined indentation, only the first character (if any) of the string is used and the length of the string defines the character count. Return true if successful.
  25. bool Save(Serializer& dest, const String& indendation) const;
  26. /// Deserialize from a string. Return true if successful.
  27. bool FromString(const String& source);
  28. /// Save to a string.
  29. String ToString(const String& indendation = "\t") const;
  30. /// Return root value.
  31. /// @property
  32. JSONValue& GetRoot() { return root_; }
  33. /// Return root value.
  34. const JSONValue& GetRoot() const { return root_; }
  35. private:
  36. /// JSON root value.
  37. JSONValue root_;
  38. };
  39. }