28#ifndef CPL_JSON_H_INCLUDED
29#define CPL_JSON_H_INCLUDED
31#include "cpl_progress.h"
43typedef void *JSONObjectH;
97 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
102 void Add(
const std::string &osName,
const std::string &osValue);
103 void Add(
const std::string &osName,
const char *pszValue);
104 void Add(
const std::string &osName,
double dfValue);
105 void Add(
const std::string &osName,
int nValue);
106 void Add(
const std::string &osName,
GInt64 nValue);
107 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
108 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
109 void AddNoSplitName(
const std::string &osName,
const CPLJSONObject &oValue);
110 void Add(
const std::string &osName,
bool bValue);
111 void AddNull(
const std::string &osName);
113 void Set(
const std::string &osName,
const std::string &osValue);
114 void Set(
const std::string &osName,
const char *pszValue);
115 void Set(
const std::string &osName,
double dfValue);
116 void Set(
const std::string &osName,
int nValue);
117 void Set(
const std::string &osName,
GInt64 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;
129 std::string GetString(
const std::string &osName,
130 const std::string &osDefault =
"")
const;
131 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
132 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
133 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
134 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
135 std::string ToString(
const std::string &osDefault =
"")
const;
136 double ToDouble(
double dfDefault = 0.0)
const;
137 int ToInteger(
int nDefault = 0)
const;
139 bool ToBool(
bool bDefault =
false)
const;
141 std::string Format(PrettyFormat eFormat)
const;
144 void Delete(
const std::string &osName);
145 void DeleteNoSplitName(
const std::string &osName);
149 Type GetType()
const;
151 std::string GetName()
const
157 std::vector<CPLJSONObject> GetChildren()
const;
158 bool IsValid()
const;
164 std::string &osName)
const;
168 JSONObjectH m_poJsonObject =
nullptr;
169 std::string m_osKey{};
187 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
189 class CPL_DLL ConstIterator
197 : m_oSelf(oSelf), m_nIdx(bStart ? 0 : oSelf.
Size())
200 ~ConstIterator() =
default;
203 m_oObj = m_oSelf[m_nIdx];
206 ConstIterator &operator++()
211 bool operator==(
const ConstIterator &it)
const
213 return m_nIdx == it.m_nIdx;
215 bool operator!=(
const ConstIterator &it)
const
217 return m_nIdx != it.m_nIdx;
225 void Add(
const std::string &osValue);
226 void Add(
const char *pszValue);
227 void Add(
double dfValue);
228 void Add(
int nValue);
230 void Add(
bool bValue);
237 return ConstIterator(*
this,
true);
242 return ConstIterator(*
this,
false);
261 bool Save(
const std::string &osPath)
const;
262 std::string SaveAsString()
const;
267 bool Load(
const std::string &osPath);
268 bool LoadMemory(
const std::string &osStr);
269 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
270 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
271 GDALProgressFunc pfnProgress =
nullptr,
272 void *pProgressArg =
nullptr);
273 bool LoadUrl(
const std::string &osUrl,
const char *
const *papszOptions,
274 GDALProgressFunc pfnProgress =
nullptr,
275 void *pProgressArg =
nullptr);
278 mutable JSONObjectH m_poRootJsonObject;
The JSONArray class JSON array from JSONDocument.
Definition cpl_json.h:176
int Size() const
Get array size.
Definition cpl_json.cpp:1330
ConstIterator begin() const
Iterator to first element.
Definition cpl_json.h:235
ConstIterator end() const
Iterator to after last element.
Definition cpl_json.h:240
The CPLJSONDocument class Wrapper class around json-c library.
Definition cpl_json.h:250
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition cpl_json.h:54
Type
Json object types.
Definition cpl_json.h:63
PrettyFormat
Json object format to string options.
Definition cpl_json.h:79
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:317
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:313
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:254
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:205