1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * $Id$
20 */
21
22
23 // ---------------------------------------------------------------------------
24 // Includes
25 // ---------------------------------------------------------------------------
26 #include <xercesc/util/KVStringPair.hpp>
27 #include <xercesc/util/XMLString.hpp>
28
29 XERCES_CPP_NAMESPACE_BEGIN
30
31 // ---------------------------------------------------------------------------
32 // KVStringPair: Constructors and Destructor
33 // ---------------------------------------------------------------------------
KVStringPair(MemoryManager * const manager)34 KVStringPair::KVStringPair(MemoryManager* const manager)
35 :fKeyAllocSize(0)
36 ,fValueAllocSize(0)
37 ,fKey(0)
38 ,fValue(0)
39 ,fMemoryManager(manager)
40 {
41 }
42
KVStringPair(const XMLCh * const key,const XMLCh * const value,MemoryManager * const manager)43 KVStringPair::KVStringPair(const XMLCh* const key,
44 const XMLCh* const value,
45 MemoryManager* const manager)
46 :fKeyAllocSize(0)
47 ,fValueAllocSize(0)
48 ,fKey(0)
49 ,fValue(0)
50 ,fMemoryManager(manager)
51 {
52 set(key, value);
53 }
54
KVStringPair(const XMLCh * const key,const XMLCh * const value,const XMLSize_t valueLength,MemoryManager * const manager)55 KVStringPair::KVStringPair(const XMLCh* const key,
56 const XMLCh* const value,
57 const XMLSize_t valueLength,
58 MemoryManager* const manager)
59 :fKeyAllocSize(0)
60 ,fValueAllocSize(0)
61 ,fKey(0)
62 ,fValue(0)
63 ,fMemoryManager(manager)
64 {
65 setKey(key);
66 setValue(value, valueLength);
67 }
68
KVStringPair(const XMLCh * const key,const XMLSize_t keyLength,const XMLCh * const value,const XMLSize_t valueLength,MemoryManager * const manager)69 KVStringPair::KVStringPair(const XMLCh* const key,
70 const XMLSize_t keyLength,
71 const XMLCh* const value,
72 const XMLSize_t valueLength,
73 MemoryManager* const manager)
74 :fKeyAllocSize(0)
75 ,fValueAllocSize(0)
76 ,fKey(0)
77 ,fValue(0)
78 ,fMemoryManager(manager)
79 {
80 setKey(key, keyLength);
81 setValue(value, valueLength);
82 }
83
KVStringPair(const KVStringPair & toCopy)84 KVStringPair::KVStringPair(const KVStringPair& toCopy)
85 :XSerializable(toCopy)
86 ,XMemory(toCopy)
87 ,fKeyAllocSize(0)
88 ,fValueAllocSize(0)
89 ,fKey(0)
90 ,fValue(0)
91 ,fMemoryManager(toCopy.fMemoryManager)
92 {
93 set(toCopy.fKey, toCopy.fValue);
94 }
95
~KVStringPair()96 KVStringPair::~KVStringPair()
97 {
98 fMemoryManager->deallocate(fKey); //delete [] fKey;
99 fMemoryManager->deallocate(fValue); //delete [] fValue;
100 }
101
102 /***
103 * Support for Serialization/De-serialization
104 ***/
105
IMPL_XSERIALIZABLE_TOCREATE(KVStringPair)106 IMPL_XSERIALIZABLE_TOCREATE(KVStringPair)
107
108 void KVStringPair::serialize(XSerializeEngine& serEng)
109 {
110
111 if (serEng.isStoring())
112 {
113
114 serEng.writeString(fKey, fKeyAllocSize, XSerializeEngine::toWriteBufferLen);
115 serEng.writeString(fValue, fValueAllocSize, XSerializeEngine::toWriteBufferLen);
116 }
117 else
118 {
119 XMLSize_t dataLen = 0;
120 serEng.readString(fKey, fKeyAllocSize, dataLen, XSerializeEngine::toReadBufferLen);
121 serEng.readString(fValue, fValueAllocSize, dataLen, XSerializeEngine::toReadBufferLen);
122 }
123
124 }
125
126 XERCES_CPP_NAMESPACE_END
127