28 #ifndef CPL_JSON_H_INCLUDED 29 #define CPL_JSON_H_INCLUDED 31 #include "cpl_progress.h" 43 typedef void *JSONObjectH;
91 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
96 void Add(
const std::string &osName,
const std::string &osValue);
97 void Add(
const std::string &osName,
const char *pszValue);
98 void Add(
const std::string &osName,
double dfValue);
99 void Add(
const std::string &osName,
int nValue);
100 void Add(
const std::string &osName,
GInt64 nValue);
101 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
102 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
103 void Add(
const std::string &osName,
bool bValue);
104 void AddNull(
const std::string &osName);
106 void Set(
const std::string &osName,
const std::string &osValue);
107 void Set(
const std::string &osName,
const char *pszValue);
108 void Set(
const std::string &osName,
double dfValue);
109 void Set(
const std::string &osName,
int nValue);
110 void Set(
const std::string &osName,
GInt64 nValue);
111 void Set(
const std::string &osName,
bool bValue);
112 void SetNull(
const std::string &osName);
115 JSONObjectH GetInternalHandle()
const {
return m_poJsonObject; }
119 std::string GetString(
const std::string &osName,
const std::string &osDefault =
"")
const;
120 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
121 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
122 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
123 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
124 std::string ToString(
const std::string &osDefault =
"")
const;
125 double ToDouble(
double dfDefault = 0.0)
const;
126 int ToInteger(
int nDefault = 0)
const;
128 bool ToBool(
bool bDefault =
false)
const;
133 void Delete(
const std::string &osName);
137 enum Type GetType()
const;
139 std::string GetName()
const {
return m_osKey; }
142 std::vector<CPLJSONObject> GetChildren()
const;
143 bool IsValid()
const;
148 CPLJSONObject GetObjectByPath(
const std::string &osPath, std::string &osName)
const;
152 JSONObjectH m_poJsonObject =
nullptr;
153 std::string m_osKey{};
170 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
175 void Add(
const std::string &osValue);
176 void Add(
const char* pszValue);
177 void Add(
double dfValue);
178 void Add(
int nValue);
180 void Add(
bool bValue);
198 bool Save(
const std::string &osPath);
199 std::string SaveAsString();
202 bool Load(
const std::string &osPath);
203 bool LoadMemory(
const std::string &osStr);
204 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
205 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
206 GDALProgressFunc pfnProgress =
nullptr,
207 void *pProgressArg =
nullptr);
208 bool LoadUrl(
const std::string &osUrl,
char **papszOptions,
209 GDALProgressFunc pfnProgress =
nullptr,
210 void *pProgressArg =
nullptr);
213 JSONObjectH m_poRootJsonObject;
218 #endif // CPL_JSON_H_INCLUDED void Add(const std::string &osName, const std::string &osValue)
Add new key - value pair to json object.
Definition: cpl_json.cpp:431
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:337
PrettyFormat
Json object format to string options.
Definition: cpl_json.h:76
No extra whitespace or formatting applied.
Definition: cpl_json.h:77
CPLJSONObject operator[](const std::string &osName) const
Get value by key.
Definition: cpl_json.cpp:770
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
Type
Json object types.
Definition: cpl_json.h:61
Minimal whitespace inserted.
Definition: cpl_json.h:78
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:53
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:339
The CPLJSONDocument class Wrapper class around json-c library.
Definition: cpl_json.h:188
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:267
The JSONArray class JSON array from JSONDocument.
Definition: cpl_json.h:159