GME  13
DOMStringPool.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: DOMStringPool.cpp 678766 2008-07-22 14:00:16Z borisk $
00020  */
00021 
00022 #include <xercesc/util/XMLString.hpp>
00023 #include <xercesc/util/PlatformUtils.hpp>
00024 
00025 #include "DOMStringPool.hpp"
00026 #include "DOMDocumentImpl.hpp"
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00030 DOMBuffer::
00031 DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity) :
00032     fBuffer(0)
00033     , fIndex(0)
00034     , fCapacity(capacity)
00035     , fDoc(doc)
00036 {
00037     // Buffer is one larger than capacity, to allow for zero term
00038     fBuffer = (XMLCh*) doc->allocate((fCapacity+1)*sizeof(XMLCh));
00039 
00040     // Keep it null terminated
00041     fBuffer[0] = XMLCh(0);
00042 }
00043 
00044 // ---------------------------------------------------------------------------
00045 //  DOMBuffer: Private helper methods
00046 // ---------------------------------------------------------------------------
00047 void DOMBuffer::expandCapacity(const XMLSize_t extraNeeded)
00048 {
00049     //not enough room. Calc new capacity and allocate new buffer
00050     const XMLSize_t newCap = (XMLSize_t)((fIndex + extraNeeded) * 1.25);
00051     XMLCh* newBuf = (XMLCh*) fDoc->allocate((newCap+1)*sizeof(XMLCh));
00052 
00053     // Copy over the old stuff
00054     memcpy(newBuf, fBuffer, fCapacity * sizeof(XMLCh));
00055 
00056     // revisit: Leave the old buffer in document heap, yes, this is a leak, but live with it!
00057     // store new stuff
00058     fBuffer = newBuf;
00059     fCapacity = newCap;
00060 }
00061 
00062 XERCES_CPP_NAMESPACE_END