Skip to content

Commit 7be1cef

Browse files
authored
Merge branch 'master' into PVSandClangtidyModify
2 parents 0d0a0f0 + a0bd9ad commit 7be1cef

File tree

138 files changed

+871
-903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+871
-903
lines changed

.travis_scripts/meson_builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ _COMPILER_NAME=`basename ${CXX}`
6565
_BUILD_DIR_NAME="build-${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}"
6666

6767
./.travis_scripts/run-clang-format.sh
68-
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . "${_BUILD_DIR_NAME}"
68+
meson --fatal-meson-warnings --werror --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . "${_BUILD_DIR_NAME}"
6969
ninja -v -j 2 -C "${_BUILD_DIR_NAME}"
7070

7171
cd "${_BUILD_DIR_NAME}"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![badge](https://img.shields.io/badge/conan.io-jsoncpp%2F1.8.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC)](https://bintray.com/theirix/conan-repo/jsoncpp%3Atheirix)
44
[![badge](https://img.shields.io/badge/license-MIT-blue)](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE)
55
[![badge](https://img.shields.io/badge/document-doxygen-brightgreen)](http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html)
6+
[![Coverage Status](https://coveralls.io/repos/github/open-source-parsers/jsoncpp/badge.svg?branch=master)](https://coveralls.io/github/open-source-parsers/jsoncpp?branch=master)
67

78

89
[JSON][json-org] is a lightweight data-interchange format. It can represent

include/json/allocator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#ifndef CPPTL_JSON_ALLOCATOR_H_INCLUDED
7-
#define CPPTL_JSON_ALLOCATOR_H_INCLUDED
6+
#ifndef JSON_ALLOCATOR_H_INCLUDED
7+
#define JSON_ALLOCATOR_H_INCLUDED
88

99
#include <cstring>
1010
#include <memory>
@@ -86,4 +86,4 @@ bool operator!=(const SecureAllocator<T>&, const SecureAllocator<U>&) {
8686

8787
#pragma pack(pop)
8888

89-
#endif // CPPTL_JSON_ALLOCATOR_H_INCLUDED
89+
#endif // JSON_ALLOCATOR_H_INCLUDED

include/json/assertions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
7-
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
6+
#ifndef JSON_ASSERTIONS_H_INCLUDED
7+
#define JSON_ASSERTIONS_H_INCLUDED
88

99
#include <cstdlib>
1010
#include <sstream>
@@ -56,4 +56,4 @@
5656
JSON_FAIL_MESSAGE(message); \
5757
}
5858

59-
#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
59+
#endif // JSON_ASSERTIONS_H_INCLUDED

include/json/autolink.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

include/json/config.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
#include <string>
1515
#include <type_traits>
1616

17-
/// If defined, indicates that json library is embedded in CppTL library.
18-
//# define JSON_IN_CPPTL 1
19-
20-
/// If defined, indicates that json may leverage CppTL library
21-
//# define JSON_USE_CPPTL 1
22-
/// If defined, indicates that cpptl vector based map should be used instead of
23-
/// std::map
24-
/// as Value container.
25-
//# define JSON_USE_CPPTL_SMALLMAP 1
26-
2717
// If non-zero, the library uses exceptions to report bad input instead of C
2818
// assertion macros. The default is to use exceptions.
2919
#ifndef JSON_USE_EXCEPTION
@@ -40,28 +30,22 @@
4030
/// Remarks: it is automatically defined in the generated amalgamated header.
4131
// #define JSON_IS_AMALGAMATION
4232

43-
#ifdef JSON_IN_CPPTL
44-
#include <cpptl/config.h>
45-
#ifndef JSON_USE_CPPTL
46-
#define JSON_USE_CPPTL 1
47-
#endif
48-
#endif
49-
50-
#ifdef JSON_IN_CPPTL
51-
#define JSON_API CPPTL_API
52-
#elif defined(JSON_DLL_BUILD)
33+
// Export macros for DLL visibility
34+
#if defined(JSON_DLL_BUILD)
5335
#if defined(_MSC_VER) || defined(__MINGW32__)
5436
#define JSON_API __declspec(dllexport)
5537
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
5638
#elif defined(__GNUC__) || defined(__clang__)
5739
#define JSON_API __attribute__((visibility("default")))
5840
#endif // if defined(_MSC_VER)
41+
5942
#elif defined(JSON_DLL)
6043
#if defined(_MSC_VER) || defined(__MINGW32__)
6144
#define JSON_API __declspec(dllimport)
6245
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
6346
#endif // if defined(_MSC_VER)
64-
#endif // ifdef JSON_IN_CPPTL
47+
#endif // ifdef JSON_DLL_BUILD
48+
6549
#if !defined(JSON_API)
6650
#define JSON_API
6751
#endif

include/json/json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef JSON_JSON_H_INCLUDED
77
#define JSON_JSON_H_INCLUDED
88

9-
#include "autolink.h"
9+
#include "config.h"
1010
#include "json_features.h"
1111
#include "reader.h"
1212
#include "value.h"

include/json/json_features.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#ifndef CPPTL_JSON_FEATURES_H_INCLUDED
7-
#define CPPTL_JSON_FEATURES_H_INCLUDED
6+
#ifndef JSON_FEATURES_H_INCLUDED
7+
#define JSON_FEATURES_H_INCLUDED
88

99
#if !defined(JSON_IS_AMALGAMATION)
1010
#include "forwards.h"
@@ -23,6 +23,7 @@ class JSON_API Features {
2323
/** \brief A configuration that allows all features and assumes all strings
2424
* are UTF-8.
2525
* - C & C++ comments are allowed
26+
* - Trailing commas in objects and arrays are allowed.
2627
* - Root object can be any JSON value
2728
* - Assumes Value strings are encoded in UTF-8
2829
*/
@@ -31,6 +32,7 @@ class JSON_API Features {
3132
/** \brief A configuration that is strictly compatible with the JSON
3233
* specification.
3334
* - Comments are forbidden.
35+
* - Trailing commas in objects and arrays are forbidden.
3436
* - Root object must be either an array or an object value.
3537
* - Assumes Value strings are encoded in UTF-8
3638
*/
@@ -43,6 +45,10 @@ class JSON_API Features {
4345
/// \c true if comments are allowed. Default: \c true.
4446
bool allowComments_{true};
4547

48+
/// \c true if trailing commas in objects and arrays are allowed. Default \c
49+
/// true.
50+
bool allowTrailingCommas_{true};
51+
4652
/// \c true if root must be either an array or an object value. Default: \c
4753
/// false.
4854
bool strictRoot_{false};
@@ -58,4 +64,4 @@ class JSON_API Features {
5864

5965
#pragma pack(pop)
6066

61-
#endif // CPPTL_JSON_FEATURES_H_INCLUDED
67+
#endif // JSON_FEATURES_H_INCLUDED

include/json/reader.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#ifndef CPPTL_JSON_READER_H_INCLUDED
7-
#define CPPTL_JSON_READER_H_INCLUDED
6+
#ifndef JSON_READER_H_INCLUDED
7+
#define JSON_READER_H_INCLUDED
88

99
#if !defined(JSON_IS_AMALGAMATION)
1010
#include "json_features.h"
@@ -299,6 +299,8 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
299299
* if allowComments is false.
300300
* - `"allowComments": false or true`
301301
* - true if comments are allowed.
302+
* - `"allowTrailingCommas": false or true`
303+
* - true if trailing commas in objects and arrays are allowed.
302304
* - `"strictRoot": false or true`
303305
* - true if root must be either an array or an object value
304306
* - `"allowDroppedNullPlaceholders": false or true`
@@ -398,4 +400,4 @@ JSON_API IStream& operator>>(IStream&, Value&);
398400
#pragma warning(pop)
399401
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
400402

401-
#endif // CPPTL_JSON_READER_H_INCLUDED
403+
#endif // JSON_READER_H_INCLUDED

include/json/value.h

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#ifndef CPPTL_JSON_H_INCLUDED
7-
#define CPPTL_JSON_H_INCLUDED
6+
#ifndef JSON_H_INCLUDED
7+
#define JSON_H_INCLUDED
88

99
#if !defined(JSON_IS_AMALGAMATION)
1010
#include "forwards.h"
@@ -23,19 +23,11 @@
2323

2424
#include <array>
2525
#include <exception>
26+
#include <map>
2627
#include <memory>
2728
#include <string>
2829
#include <vector>
2930

30-
#ifndef JSON_USE_CPPTL_SMALLMAP
31-
#include <map>
32-
#else
33-
#include <cpptl/smallmap.h>
34-
#endif
35-
#ifdef JSON_USE_CPPTL
36-
#include <cpptl/forwards.h>
37-
#endif
38-
3931
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
4032
// be used by...
4133
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
@@ -120,11 +112,6 @@ enum PrecisionType {
120112
decimalPlaces ///< we set max number of digits after "." in string
121113
};
122114

123-
//# ifdef JSON_USE_CPPTL
124-
// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
125-
// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
126-
//# endif
127-
128115
/** \brief Lightweight wrapper to tag static string.
129116
*
130117
* Value constructor and objectValue member assignment takes advantage of the
@@ -287,11 +274,7 @@ class JSON_API Value {
287274
};
288275

289276
public:
290-
#ifndef JSON_USE_CPPTL_SMALLMAP
291-
using ObjectValues = std::map<CZString, Value>;
292-
#else
293-
using ObjectValues = CppTL::SmallMap<CZString, Value>;
294-
#endif // ifndef JSON_USE_CPPTL_SMALLMAP
277+
typedef std::map<CZString, Value> ObjectValues;
295278
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
296279

297280
public:
@@ -340,9 +323,6 @@ class JSON_API Value {
340323
*/
341324
Value(const StaticString& value);
342325
Value(const String& value);
343-
#ifdef JSON_USE_CPPTL
344-
Value(const CppTL::ConstString& value);
345-
#endif
346326
Value(bool value);
347327
Value(const Value& other);
348328
Value(Value&& other);
@@ -384,9 +364,6 @@ class JSON_API Value {
384364
* \return false if !string. (Seg-fault if str or end are NULL.)
385365
*/
386366
bool getString(char const** begin, char const** end) const;
387-
#ifdef JSON_USE_CPPTL
388-
CppTL::ConstString asConstString() const;
389-
#endif
390367
Int asInt() const;
391368
UInt asUInt() const;
392369
#if defined(JSON_HAS_INT64)
@@ -412,6 +389,10 @@ class JSON_API Value {
412389
bool isArray() const;
413390
bool isObject() const;
414391

392+
/// The `as<T>` and `is<T>` member function templates and specializations.
393+
template <typename T> T as() const = delete;
394+
template <typename T> bool is() const = delete;
395+
415396
bool isConvertibleTo(ValueType other) const;
416397

417398
/// Number of values in array or object
@@ -464,8 +445,10 @@ class JSON_API Value {
464445
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
465446
Value& append(const Value& value);
466447
Value& append(Value&& value);
448+
467449
/// \brief Insert value in array at specific index
468-
bool insert(ArrayIndex index, Value newValue);
450+
bool insert(ArrayIndex index, const Value& newValue);
451+
bool insert(ArrayIndex index, Value&& newValue);
469452

470453
/// Access an object value by name, create a null member if it does not exist.
471454
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
@@ -494,13 +477,6 @@ class JSON_API Value {
494477
* \endcode
495478
*/
496479
Value& operator[](const StaticString& key);
497-
#ifdef JSON_USE_CPPTL
498-
/// Access an object value by name, create a null member if it does not exist.
499-
Value& operator[](const CppTL::ConstString& key);
500-
/// Access an object value by name, returns null if there is no member with
501-
/// that name.
502-
const Value& operator[](const CppTL::ConstString& key) const;
503-
#endif
504480
/// Return the member named key if it exist, defaultValue otherwise.
505481
/// \note deep copy
506482
Value get(const char* key, const Value& defaultValue) const;
@@ -513,11 +489,6 @@ class JSON_API Value {
513489
/// \note deep copy
514490
/// \param key may contain embedded nulls.
515491
Value get(const String& key, const Value& defaultValue) const;
516-
#ifdef JSON_USE_CPPTL
517-
/// Return the member named key if it exist, defaultValue otherwise.
518-
/// \note deep copy
519-
Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
520-
#endif
521492
/// Most general and efficient version of isMember()const, get()const,
522493
/// and operator[]const
523494
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
@@ -563,10 +534,6 @@ class JSON_API Value {
563534
bool isMember(const String& key) const;
564535
/// Same as isMember(String const& key)const
565536
bool isMember(const char* begin, const char* end) const;
566-
#ifdef JSON_USE_CPPTL
567-
/// Return true if the object has a member named key.
568-
bool isMember(const CppTL::ConstString& key) const;
569-
#endif
570537

571538
/// \brief Return a list of the member names.
572539
///
@@ -575,11 +542,6 @@ class JSON_API Value {
575542
/// \post if type() was nullValue, it remains nullValue
576543
Members getMemberNames() const;
577544

578-
//# ifdef JSON_USE_CPPTL
579-
// EnumMemberNames enumMemberNames() const;
580-
// EnumValues enumValues() const;
581-
//# endif
582-
583545
/// \deprecated Always pass len.
584546
JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
585547
void setComment(const char* comment, CommentPlacement placement) {
@@ -673,6 +635,36 @@ class JSON_API Value {
673635
ptrdiff_t limit_;
674636
};
675637

638+
template <> inline bool Value::as<bool>() const { return asBool(); }
639+
template <> inline bool Value::is<bool>() const { return isBool(); }
640+
641+
template <> inline Int Value::as<Int>() const { return asInt(); }
642+
template <> inline bool Value::is<Int>() const { return isInt(); }
643+
644+
template <> inline UInt Value::as<UInt>() const { return asUInt(); }
645+
template <> inline bool Value::is<UInt>() const { return isUInt(); }
646+
647+
#if defined(JSON_HAS_INT64)
648+
template <> inline Int64 Value::as<Int64>() const { return asInt64(); }
649+
template <> inline bool Value::is<Int64>() const { return isInt64(); }
650+
651+
template <> inline UInt64 Value::as<UInt64>() const { return asUInt64(); }
652+
template <> inline bool Value::is<UInt64>() const { return isUInt64(); }
653+
#endif
654+
655+
template <> inline double Value::as<double>() const { return asDouble(); }
656+
template <> inline bool Value::is<double>() const { return isDouble(); }
657+
658+
template <> inline String Value::as<String>() const { return asString(); }
659+
template <> inline bool Value::is<String>() const { return isString(); }
660+
661+
/// These `as` specializations are type conversions, and do not have a
662+
/// corresponding `is`.
663+
template <> inline float Value::as<float>() const { return asFloat(); }
664+
template <> inline const char* Value::as<const char*>() const {
665+
return asCString();
666+
}
667+
676668
/** \brief Experimental and untested: represents an element of the "path" to
677669
* access a node.
678670
*/
@@ -921,4 +913,4 @@ inline void swap(Value& a, Value& b) { a.swap(b); }
921913
#pragma warning(pop)
922914
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
923915

924-
#endif // CPPTL_JSON_H_INCLUDED
916+
#endif // JSON_H_INCLUDED

0 commit comments

Comments
 (0)