GDAL

cpl_json_header.h
1/******************************************************************************
2 *
3 * Project: GDAL
4 * Purpose: Includes json-c header
5 * Author: Even Rouault <even dot rouault at spatialys dot com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2016, Even Rouault <even dot rouault at spatialys dot com>
9 *
10 * SPDX-License-Identifier: MIT
11 *****************************************************************************/
12
13#ifndef OGR_JSON_HEADER_H
14#define OGR_JSON_HEADER_H
15
16#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
17 !defined(_MSC_VER))
18#pragma GCC system_header
19#endif
20
21#ifdef _MSC_VER
22#pragma warning(push)
23// json_inttypes.h(18,1): warning C4005: 'PRId64': macro redefinition.
24#pragma warning(disable : 4005)
25#endif
26
27#include <json.h>
28
29#ifdef _MSC_VER
30#pragma warning(pop)
31#endif
32
33#undef json_object_object_foreachC
34#define json_object_object_foreachC(obj, iter) \
35 for (iter.entry = json_object_get_object(obj)->head; \
36 (iter.entry \
37 ? (iter.key = (char *)iter.entry->k, \
38 iter.val = (struct json_object *)iter.entry->v, iter.entry) \
39 : nullptr) != nullptr; \
40 iter.entry = iter.entry->next)
41
43#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
44
45 extern "C++"
46{
47#ifndef DOXYGEN_SKIP
48#include <memory>
49#endif
50
51 struct JsonObjectReleaser
52 {
53 void operator()(json_object *poObj) const
54 {
55 json_object_put(poObj);
56 }
57 };
58
59 using JsonObjectUniquePtr =
60 std::unique_ptr<json_object, JsonObjectReleaser>;
61
62} // extern "C++"
63
64#endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
67#endif /* OGR_JSON_HEADER_H */