source: icXML/icXML-devel/src/xercesc/dom/impl/DOMStringPool.cpp @ 2777

Last change on this file since 2777 was 2777, checked in by cameron, 7 years ago

Set up to use xercesc/icxercesc root-relative paths for all includes

File size: 2.1 KB
Line 
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: DOMStringPool.cpp 678766 2008-07-22 14:00:16Z borisk $
20 */
21
22#include <icxercesc/util/XMLString.hpp>
23#include <icxercesc/util/PlatformUtils.hpp>
24
25#include <xercesc/dom/impl/DOMStringPool.hpp>
26#include <xercesc/dom/impl/DOMDocumentImpl.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30DOMBuffer::
31DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity) :
32    fBuffer(0)
33    , fIndex(0)
34    , fCapacity(capacity)
35    , fDoc(doc)
36{
37    // Buffer is one larger than capacity, to allow for zero term
38    fBuffer = (XMLCh*) doc->allocate((fCapacity+1)*sizeof(XMLCh));
39
40    // Keep it null terminated
41    fBuffer[0] = XMLCh(0);
42}
43
44// ---------------------------------------------------------------------------
45//  DOMBuffer: Private helper methods
46// ---------------------------------------------------------------------------
47void DOMBuffer::expandCapacity(const XMLSize_t extraNeeded)
48{
49    //not enough room. Calc new capacity and allocate new buffer
50    const XMLSize_t newCap = (XMLSize_t)((fIndex + extraNeeded) * 1.25);
51    XMLCh* newBuf = (XMLCh*) fDoc->allocate((newCap+1)*sizeof(XMLCh));
52
53    // Copy over the old stuff
54    memcpy(newBuf, fBuffer, fCapacity * sizeof(XMLCh));
55
56    // revisit: Leave the old buffer in document heap, yes, this is a leak, but live with it!
57    // store new stuff
58    fBuffer = newBuf;
59    fCapacity = newCap;
60}
61
62XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.