3
3
// recognized in your jurisdiction.
4
4
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
5
6
- #ifndef CPPTL_JSON_H_INCLUDED
7
- #define CPPTL_JSON_H_INCLUDED
6
+ #ifndef JSON_H_INCLUDED
7
+ #define JSON_H_INCLUDED
8
8
9
9
#if !defined(JSON_IS_AMALGAMATION)
10
10
#include " forwards.h"
23
23
24
24
#include < array>
25
25
#include < exception>
26
+ #include < map>
26
27
#include < memory>
27
28
#include < string>
28
29
#include < vector>
29
30
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
-
39
31
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
40
32
// be used by...
41
33
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
@@ -120,11 +112,6 @@ enum PrecisionType {
120
112
decimalPlaces // /< we set max number of digits after "." in string
121
113
};
122
114
123
- // # ifdef JSON_USE_CPPTL
124
- // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
125
- // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
126
- // # endif
127
-
128
115
/* * \brief Lightweight wrapper to tag static string.
129
116
*
130
117
* Value constructor and objectValue member assignment takes advantage of the
@@ -287,11 +274,7 @@ class JSON_API Value {
287
274
};
288
275
289
276
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;
295
278
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
296
279
297
280
public:
@@ -340,9 +323,6 @@ class JSON_API Value {
340
323
*/
341
324
Value (const StaticString& value);
342
325
Value (const String& value);
343
- #ifdef JSON_USE_CPPTL
344
- Value (const CppTL::ConstString& value);
345
- #endif
346
326
Value (bool value);
347
327
Value (const Value& other);
348
328
Value (Value&& other);
@@ -384,9 +364,6 @@ class JSON_API Value {
384
364
* \return false if !string. (Seg-fault if str or end are NULL.)
385
365
*/
386
366
bool getString (char const ** begin, char const ** end) const ;
387
- #ifdef JSON_USE_CPPTL
388
- CppTL::ConstString asConstString () const ;
389
- #endif
390
367
Int asInt () const ;
391
368
UInt asUInt () const ;
392
369
#if defined(JSON_HAS_INT64)
@@ -412,6 +389,10 @@ class JSON_API Value {
412
389
bool isArray () const ;
413
390
bool isObject () const ;
414
391
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
+
415
396
bool isConvertibleTo (ValueType other) const ;
416
397
417
398
// / Number of values in array or object
@@ -464,8 +445,10 @@ class JSON_API Value {
464
445
// / Equivalent to jsonvalue[jsonvalue.size()] = value;
465
446
Value& append (const Value& value);
466
447
Value& append (Value&& value);
448
+
467
449
// / \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);
469
452
470
453
// / Access an object value by name, create a null member if it does not exist.
471
454
// / \note Because of our implementation, keys are limited to 2^30 -1 chars.
@@ -494,13 +477,6 @@ class JSON_API Value {
494
477
* \endcode
495
478
*/
496
479
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
504
480
// / Return the member named key if it exist, defaultValue otherwise.
505
481
// / \note deep copy
506
482
Value get (const char * key, const Value& defaultValue) const ;
@@ -513,11 +489,6 @@ class JSON_API Value {
513
489
// / \note deep copy
514
490
// / \param key may contain embedded nulls.
515
491
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
521
492
// / Most general and efficient version of isMember()const, get()const,
522
493
// / and operator[]const
523
494
// / \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
@@ -563,10 +534,6 @@ class JSON_API Value {
563
534
bool isMember (const String& key) const ;
564
535
// / Same as isMember(String const& key)const
565
536
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
570
537
571
538
// / \brief Return a list of the member names.
572
539
// /
@@ -575,11 +542,6 @@ class JSON_API Value {
575
542
// / \post if type() was nullValue, it remains nullValue
576
543
Members getMemberNames () const ;
577
544
578
- // # ifdef JSON_USE_CPPTL
579
- // EnumMemberNames enumMemberNames() const;
580
- // EnumValues enumValues() const;
581
- // # endif
582
-
583
545
// / \deprecated Always pass len.
584
546
JSONCPP_DEPRECATED (" Use setComment(String const&) instead." )
585
547
void setComment (const char * comment, CommentPlacement placement) {
@@ -673,6 +635,36 @@ class JSON_API Value {
673
635
ptrdiff_t limit_;
674
636
};
675
637
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
+
676
668
/* * \brief Experimental and untested: represents an element of the "path" to
677
669
* access a node.
678
670
*/
@@ -921,4 +913,4 @@ inline void swap(Value& a, Value& b) { a.swap(b); }
921
913
#pragma warning(pop)
922
914
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
923
915
924
- #endif // CPPTL_JSON_H_INCLUDED
916
+ #endif // JSON_H_INCLUDED
0 commit comments