| 48 | */ |
| 49 | template <typename NodeType> |
| 50 | class GenericNode { |
| 51 | public: |
| 52 | using alloc_type = |
| 53 | typename NodeTraits<NodeType>::alloc_type; ///< Derived class allocator |
| 54 | ///< type. |
| 55 | using MemberNode = |
| 56 | typename NodeTraits<NodeType>::MemberNode; ///< Derived class key-value |
| 57 | ///< pair struct. |
| 58 | using MemberIterator = |
| 59 | typename NodeTraits<NodeType>::MemberIterator; ///< Derived class object |
| 60 | ///< iterator type. |
| 61 | using ConstMemberIterator = typename NodeTraits<NodeType>:: |
| 62 | ConstMemberIterator; ///< Derived class object const iterator type. |
| 63 | using ValueIterator = |
| 64 | typename NodeTraits<NodeType>::ValueIterator; ///< Derived class array |
| 65 | ///< iterator type. |
| 66 | using ConstValueIterator = typename NodeTraits<NodeType>:: |
| 67 | ConstValueIterator; ///< Derived class array const iterator type. |
| 68 | |
| 69 | /** |
| 70 | * @brief Default constructor, which creates a null node. |
| 71 | */ |
| 72 | GenericNode() noexcept {} |
| 73 | |
| 74 | /** |
| 75 | * @brief Constructor for creating specific types. |
| 76 | * @param type the type of JSON value. |
| 77 | * @note If type is kString, the pointer of string will be set to a constant |
| 78 | * empty string(""). |
| 79 | */ |
| 80 | explicit GenericNode(TypeFlag type) noexcept { setType(type); } |
| 81 | |
| 82 | /** |
| 83 | * @brief Constructor for creating boolean JSON value. |
| 84 | * @param b boolean, true/false |
| 85 | * @note This function rejects converting from others type to boolean when |
| 86 | * overload resolution. |
| 87 | */ |
| 88 | template <class T, typename std::enable_if<std::is_same<T, bool>::value, |
| 89 | bool>::type = false> |
| 90 | explicit GenericNode(T b) noexcept { |
| 91 | b ? setType(kTrue) : setType(kFalse); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @brief Constructor for creating int node. |
| 96 | * @param i data of int node. |
| 97 | */ |
| 98 | explicit GenericNode(int i) noexcept { |
| 99 | (i >= 0) ? setType(kUint) : setType(kSint); |
| 100 | n.i64 = i; |
| 101 | } |
| 102 | /** |
| 103 | * @brief Constructor for creating a uint node. |
| 104 | * @param i data of the uint node. |
| 105 | */ |
| 106 | explicit GenericNode(unsigned int i) noexcept { |
| 107 | setType(kUint); |