28 #ifndef CPL_JSON_H_INCLUDED
29 #define CPL_JSON_H_INCLUDED
31 #include "cpl_progress.h"
45 typedef void *JSONObjectH;
111 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
116 void Add(
const std::string &osName,
const std::string &osValue);
117 void Add(
const std::string &osName,
const char *pszValue);
118 void Add(
const std::string &osName,
double dfValue);
119 void Add(
const std::string &osName,
int nValue);
120 void Add(
const std::string &osName,
GInt64 nValue);
121 void Add(
const std::string &osName, uint64_t nValue);
122 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
123 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
124 void AddNoSplitName(
const std::string &osName,
const CPLJSONObject &oValue);
125 void Add(
const std::string &osName,
bool bValue);
126 void AddNull(
const std::string &osName);
128 void Set(
const std::string &osName,
const std::string &osValue);
129 void Set(
const std::string &osName,
const char *pszValue);
130 void Set(
const std::string &osName,
double dfValue);
131 void Set(
const std::string &osName,
int nValue);
132 void Set(
const std::string &osName,
GInt64 nValue);
133 void Set(
const std::string &osName, uint64_t nValue);
134 void Set(
const std::string &osName,
bool bValue);
135 void SetNull(
const std::string &osName);
138 JSONObjectH GetInternalHandle()
const
140 return m_poJsonObject;
146 std::string GetString(
const std::string &osName,
147 const std::string &osDefault =
"")
const;
148 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
149 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
150 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
151 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
152 std::string ToString(
const std::string &osDefault =
"")
const;
153 double ToDouble(
double dfDefault = 0.0)
const;
154 int ToInteger(
int nDefault = 0)
const;
156 bool ToBool(
bool bDefault =
false)
const;
158 std::string Format(PrettyFormat eFormat)
const;
161 void Delete(
const std::string &osName);
162 void DeleteNoSplitName(
const std::string &osName);
166 Type GetType()
const;
169 std::string GetName()
const
176 std::vector<CPLJSONObject> GetChildren()
const;
177 bool IsValid()
const;
183 std::string &osName)
const;
187 JSONObjectH m_poJsonObject =
nullptr;
188 std::string m_osKey{};
206 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
208 class CPL_DLL ConstIterator
216 : m_oSelf(oSelf), m_nIdx(bStart ? 0 : oSelf.
Size())
220 ~ConstIterator() =
default;
224 m_oObj = m_oSelf[m_nIdx];
228 ConstIterator &operator++()
234 bool operator==(
const ConstIterator &it)
const
236 return m_nIdx == it.m_nIdx;
239 bool operator!=(
const ConstIterator &it)
const
241 return m_nIdx != it.m_nIdx;
250 void Add(
const std::string &osValue);
251 void Add(
const char *pszValue);
252 void Add(
double dfValue);
253 void Add(
int nValue);
255 void Add(uint64_t nValue);
256 void Add(
bool bValue);
263 return ConstIterator(*
this,
true);
269 return ConstIterator(*
this,
false);
288 bool Save(
const std::string &osPath)
const;
289 std::string SaveAsString()
const;
294 bool Load(
const std::string &osPath);
295 bool LoadMemory(
const std::string &osStr);
296 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
297 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
298 GDALProgressFunc pfnProgress =
nullptr,
299 void *pProgressArg =
nullptr);
300 bool LoadUrl(
const std::string &osUrl,
const char *
const *papszOptions,
301 GDALProgressFunc pfnProgress =
nullptr,
302 void *pProgressArg =
nullptr);
305 mutable JSONObjectH m_poRootJsonObject;
310 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
The JSONArray class JSON array from JSONDocument.
Definition: cpl_json.h:195
int Size() const
Get array size.
Definition: cpl_json.cpp:1455
ConstIterator begin() const
Iterator to first element.
Definition: cpl_json.h:261
ConstIterator end() const
Iterator to after last element.
Definition: cpl_json.h:267
The CPLJSONDocument class Wrapper class around json-c library.
Definition: cpl_json.h:277
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:57
Type
Json object types.
Definition: cpl_json.h:66
PrettyFormat
Json object format to string options.
Definition: cpl_json.h:82
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:449
CPLStringList CPLParseKeyValueJson(const char *pszJson)
Return a string list of key/value pairs extracted from a JSON doc.
Definition: cpl_json.cpp:1632
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:299
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:295
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:236
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:185
Various convenience functions for working with strings and string lists.