Go to the documentation of this file.
28 #ifndef CPL_JSON_H_INCLUDED
29 #define CPL_JSON_H_INCLUDED
31 #include "cpl_progress.h"
44 typedef void *JSONObjectH;
98 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
103 void Add(
const std::string &osName,
const std::string &osValue);
104 void Add(
const std::string &osName,
const char *pszValue);
105 void Add(
const std::string &osName,
double dfValue);
106 void Add(
const std::string &osName,
int nValue);
107 void Add(
const std::string &osName,
GInt64 nValue);
108 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
109 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
110 void AddNoSplitName(
const std::string &osName,
const CPLJSONObject &oValue);
111 void Add(
const std::string &osName,
bool bValue);
112 void AddNull(
const std::string &osName);
114 void Set(
const std::string &osName,
const std::string &osValue);
115 void Set(
const std::string &osName,
const char *pszValue);
116 void Set(
const std::string &osName,
double dfValue);
117 void Set(
const std::string &osName,
int nValue);
118 void Set(
const std::string &osName,
GInt64 nValue);
119 void Set(
const std::string &osName,
bool bValue);
120 void SetNull(
const std::string &osName);
123 JSONObjectH GetInternalHandle()
const
125 return m_poJsonObject;
130 std::string GetString(
const std::string &osName,
131 const std::string &osDefault =
"")
const;
132 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
133 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
134 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
135 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
136 std::string ToString(
const std::string &osDefault =
"")
const;
137 double ToDouble(
double dfDefault = 0.0)
const;
138 int ToInteger(
int nDefault = 0)
const;
140 bool ToBool(
bool bDefault =
false)
const;
142 std::string Format(PrettyFormat eFormat)
const;
145 void Delete(
const std::string &osName);
146 void DeleteNoSplitName(
const std::string &osName);
150 Type GetType()
const;
152 std::string GetName()
const
158 std::vector<CPLJSONObject> GetChildren()
const;
159 bool IsValid()
const;
165 std::string &osName)
const;
169 JSONObjectH m_poJsonObject =
nullptr;
170 std::string m_osKey{};
188 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
190 class CPL_DLL ConstIterator
198 : m_oSelf(oSelf), m_nIdx(bStart ? 0 : oSelf.
Size())
201 ~ConstIterator() =
default;
204 m_oObj = m_oSelf[m_nIdx];
207 ConstIterator &operator++()
212 bool operator==(
const ConstIterator &it)
const
214 return m_nIdx == it.m_nIdx;
216 bool operator!=(
const ConstIterator &it)
const
218 return m_nIdx != it.m_nIdx;
226 void Add(
const std::string &osValue);
227 void Add(
const char *pszValue);
228 void Add(
double dfValue);
229 void Add(
int nValue);
231 void Add(
bool bValue);
238 return ConstIterator(*
this,
true);
243 return ConstIterator(*
this,
false);
262 bool Save(
const std::string &osPath)
const;
263 std::string SaveAsString()
const;
268 bool Load(
const std::string &osPath);
269 bool LoadMemory(
const std::string &osStr);
270 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
271 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
272 GDALProgressFunc pfnProgress =
nullptr,
273 void *pProgressArg =
nullptr);
274 bool LoadUrl(
const std::string &osUrl,
const char *
const *papszOptions,
275 GDALProgressFunc pfnProgress =
nullptr,
276 void *pProgressArg =
nullptr);
279 mutable JSONObjectH m_poRootJsonObject;
284 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
291 #endif // CPL_JSON_H_INCLUDED
The JSONArray class JSON array from JSONDocument.
Definition: cpl_json.h:176
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:205
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:437
CPLStringList CPLParseKeyValueJson(const char *pszJson)
Return a string list of key/value pairs extracted from a JSON doc.
Definition: cpl_json.cpp:1488
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:256
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:315
PrettyFormat
Json object format to string options.
Definition: cpl_json.h:79
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:54
ConstIterator end() const
Iterator to after last element.
Definition: cpl_json.h:241
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:319
Type
Json object types.
Definition: cpl_json.h:63
int Size() const
Get array size.
Definition: cpl_json.cpp:1337
ConstIterator begin() const
Iterator to first element.
Definition: cpl_json.h:236
The CPLJSONDocument class Wrapper class around json-c library.
Definition: cpl_json.h:250