| 34 | |
| 35 | template <typename Allocator = SONIC_DEFAULT_ALLOCATOR> |
| 36 | class DNode : public GenericNode<DNode<Allocator>> { |
| 37 | public: |
| 38 | using NodeType = DNode; |
| 39 | using BaseNode = GenericNode<DNode<Allocator>>; |
| 40 | using AllocatorType = Allocator; |
| 41 | using MemberNode = typename NodeTraits<DNode>::MemberNode; |
| 42 | using MemberIterator = typename NodeTraits<DNode>::MemberIterator; |
| 43 | using ConstMemberIterator = typename NodeTraits<DNode>::ConstMemberIterator; |
| 44 | using ValueIterator = typename NodeTraits<DNode>::ValueIterator; |
| 45 | using ConstValueIterator = typename NodeTraits<DNode>::ConstValueIterator; |
| 46 | |
| 47 | friend class SAXHandler<DNode>; |
| 48 | friend class LazySAXHandler<DNode>; |
| 49 | friend class SchemaHandler<DNode>; |
| 50 | |
| 51 | friend BaseNode; |
| 52 | template <typename> |
| 53 | friend class DNode; |
| 54 | template <unsigned serializeFlags, typename NodeType> |
| 55 | friend SonicError internal::SerializeImpl(const NodeType*, WriteBuffer&); |
| 56 | |
| 57 | // constructor |
| 58 | using BaseNode::BaseNode; |
| 59 | /** |
| 60 | * @brief move constructor |
| 61 | * @param rhs moved value, must be a rvalue reference |
| 62 | */ |
| 63 | DNode() noexcept : BaseNode() {} |
| 64 | DNode(DNode&& rhs) noexcept : BaseNode() { rawAssign(rhs); } |
| 65 | DNode(const DNode& rhs) = delete; |
| 66 | |
| 67 | /** |
| 68 | * @brief copy constructor |
| 69 | * @tparam rhs class Allocator type |
| 70 | * @param rhs copied value reference |
| 71 | * @param alloc allocator reference that maintain this node memory |
| 72 | * @param copyString false defautlly, copy const string or not. |
| 73 | */ |
| 74 | template <typename SourceAllocator> |
| 75 | DNode(const DNode<SourceAllocator>& rhs, Allocator& alloc, |
| 76 | bool copyString = false) |
| 77 | : BaseNode() { |
| 78 | using rhsNodeType = DNode<SourceAllocator>; |
| 79 | switch (rhs.getBasicType()) { |
| 80 | case kObject: { |
| 81 | size_t count = rhs.Size(); |
| 82 | this->o.len = rhs.getTypeAndLen(); // Copy size and type. |
| 83 | if (count > 0) { |
| 84 | void* mem = containerMalloc<MemberNode>(count, alloc); |
| 85 | rhsNodeType* rn = rhs.getObjChildrenFirst(); |
| 86 | DNode* ln = (DNode*)((char*)mem + sizeof(MetaNode)); |
| 87 | for (size_t i = 0; i < count * 2; i += 2) { |
| 88 | new (ln + i) DNode(*(rn + i), alloc, copyString); |
| 89 | new (ln + i + 1) DNode(*(rn + i + 1), alloc, copyString); |
| 90 | } |
| 91 | setChildren(mem); |
| 92 | } else { |
| 93 | setChildren(nullptr); |