12#ifndef CPL_JSON_H_INCLUDED
13#define CPL_JSON_H_INCLUDED
15#include "cpl_progress.h"
29typedef void *JSONObjectH;
95 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
100 void Add(
const std::string &osName,
const std::string &osValue);
101 void Add(
const std::string &osName,
const char *pszValue);
102 void Add(
const std::string &osName,
double dfValue);
103 void Add(
const std::string &osName,
int nValue);
104 void Add(
const std::string &osName,
GInt64 nValue);
105 void Add(
const std::string &osName, uint64_t nValue);
106 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
107 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
108 void AddNoSplitName(
const std::string &osName,
const CPLJSONObject &oValue);
109 void Add(
const std::string &osName,
bool bValue);
110 void AddNull(
const std::string &osName);
112 void Set(
const std::string &osName,
const std::string &osValue);
113 void Set(
const std::string &osName,
const char *pszValue);
114 void Set(
const std::string &osName,
double dfValue);
115 void Set(
const std::string &osName,
int nValue);
116 void Set(
const std::string &osName,
GInt64 nValue);
117 void Set(
const std::string &osName, uint64_t nValue);
118 void Set(
const std::string &osName,
bool bValue);
119 void SetNull(
const std::string &osName);
122 JSONObjectH GetInternalHandle()
const
124 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;
153 std::string GetName()
const
160 std::vector<CPLJSONObject> GetChildren()
const;
161 bool IsValid()
const;
167 std::string &osName)
const;
171 JSONObjectH m_poJsonObject =
nullptr;
172 std::string m_osKey{};
190 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
192 class CPL_DLL ConstIterator
200 : m_oSelf(oSelf), m_nIdx(bStart ? 0 : oSelf.
Size())
204 ~ConstIterator() =
default;
208 m_oObj = m_oSelf[m_nIdx];
212 ConstIterator &operator++()
218 bool operator==(
const ConstIterator &it)
const
220 return m_nIdx == it.m_nIdx;
223 bool operator!=(
const ConstIterator &it)
const
225 return m_nIdx != it.m_nIdx;
234 void Add(
const std::string &osValue);
235 void Add(
const char *pszValue);
236 void Add(
double dfValue);
237 void Add(
int nValue);
239 void Add(uint64_t nValue);
240 void Add(
bool bValue);
247 return ConstIterator(*
this,
true);
253 return ConstIterator(*
this,
false);
272 bool Save(
const std::string &osPath)
const;
273 std::string SaveAsString()
const;
278 bool Load(
const std::string &osPath);
279 bool LoadMemory(
const std::string &osStr);
280 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
281 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
282 GDALProgressFunc pfnProgress =
nullptr,
283 void *pProgressArg =
nullptr);
284 bool LoadUrl(
const std::string &osUrl,
const char *
const *papszOptions,
285 GDALProgressFunc pfnProgress =
nullptr,
286 void *pProgressArg =
nullptr);
289 mutable JSONObjectH m_poRootJsonObject;
294#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
The JSONArray class JSON array from JSONDocument.
Definition cpl_json.h:179
int Size() const
Get array size.
Definition cpl_json.cpp:1439
ConstIterator begin() const
Iterator to first element.
Definition cpl_json.h:245
ConstIterator end() const
Iterator to after last element.
Definition cpl_json.h:251
The CPLJSONDocument class Wrapper class around json-c library.
Definition cpl_json.h:261
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition cpl_json.h:41
Type
Json object types.
Definition cpl_json.h:50
PrettyFormat
Json object format to string options.
Definition cpl_json.h:66
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:436
CPLStringList CPLParseKeyValueJson(const char *pszJson)
Return a string list of key/value pairs extracted from a JSON doc.
Definition cpl_json.cpp:1616
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:283
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:220
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:169
Various convenience functions for working with strings and string lists.