GME  13
KVStringPair.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: KVStringPair.cpp 554580 2007-07-09 09:09:51Z amassari $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/util/KVStringPair.hpp>
00027 #include <xercesc/util/XMLString.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 // ---------------------------------------------------------------------------
00032 //  KVStringPair: Constructors and Destructor
00033 // ---------------------------------------------------------------------------
00034 KVStringPair::KVStringPair(MemoryManager* const manager)
00035 :fKeyAllocSize(0)
00036 ,fValueAllocSize(0)
00037 ,fKey(0)
00038 ,fValue(0)
00039 ,fMemoryManager(manager)
00040 {
00041 }
00042 
00043 KVStringPair::KVStringPair(const XMLCh* const key,
00044                            const XMLCh* const value,
00045                            MemoryManager* const manager)
00046 :fKeyAllocSize(0)
00047 ,fValueAllocSize(0)
00048 ,fKey(0)
00049 ,fValue(0)
00050 ,fMemoryManager(manager)
00051 {
00052    set(key, value);
00053 }
00054 
00055 KVStringPair::KVStringPair(const XMLCh* const key,
00056                            const XMLCh* const value,
00057                            const XMLSize_t    valueLength,
00058                            MemoryManager* const manager)
00059 :fKeyAllocSize(0)
00060 ,fValueAllocSize(0)
00061 ,fKey(0)
00062 ,fValue(0)
00063 ,fMemoryManager(manager)
00064 {
00065     setKey(key);
00066     setValue(value, valueLength);
00067 }
00068 
00069 KVStringPair::KVStringPair(const XMLCh* const key,
00070                            const XMLSize_t    keyLength,
00071                            const XMLCh* const value,
00072                            const XMLSize_t    valueLength,
00073                            MemoryManager* const manager)
00074 :fKeyAllocSize(0)
00075 ,fValueAllocSize(0)
00076 ,fKey(0)
00077 ,fValue(0)
00078 ,fMemoryManager(manager)
00079 {    
00080     setKey(key, keyLength);
00081     setValue(value, valueLength);
00082 }
00083 
00084 KVStringPair::KVStringPair(const KVStringPair& toCopy)
00085 :XSerializable(toCopy)
00086 ,XMemory(toCopy)
00087 ,fKeyAllocSize(0)
00088 ,fValueAllocSize(0)
00089 ,fKey(0)
00090 ,fValue(0)
00091 ,fMemoryManager(toCopy.fMemoryManager)
00092 {
00093    set(toCopy.fKey, toCopy.fValue);
00094 }
00095 
00096 KVStringPair::~KVStringPair()
00097 {
00098     fMemoryManager->deallocate(fKey); //delete [] fKey;
00099     fMemoryManager->deallocate(fValue); //delete [] fValue;
00100 }
00101 
00102 /***
00103  * Support for Serialization/De-serialization
00104  ***/
00105 
00106 IMPL_XSERIALIZABLE_TOCREATE(KVStringPair)
00107 
00108 void KVStringPair::serialize(XSerializeEngine& serEng)
00109 {
00110 
00111     if (serEng.isStoring())
00112     {
00113 
00114         serEng.writeString(fKey,   fKeyAllocSize,   XSerializeEngine::toWriteBufferLen);
00115         serEng.writeString(fValue, fValueAllocSize, XSerializeEngine::toWriteBufferLen);
00116     }
00117     else
00118     {
00119         XMLSize_t dataLen = 0;
00120         serEng.readString(fKey,   fKeyAllocSize,   dataLen, XSerializeEngine::toReadBufferLen);
00121         serEng.readString(fValue, fValueAllocSize, dataLen, XSerializeEngine::toReadBufferLen);
00122     }
00123 
00124 }
00125 
00126 XERCES_CPP_NAMESPACE_END