source: icXML/icXML-devel/src/xercesc/dom/impl/DOMStringPool.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 6.0 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.hpp 678766 2008-07-22 14:00:16Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DOMSTRINGPOOL_HPP)
23#define XERCESC_INCLUDE_GUARD_DOMSTRINGPOOL_HPP
24
25//
26//  This file is part of the internal implementation of the C++ XML DOM.
27//  It should NOT be included or used directly by application programs.
28//
29//  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
30//  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
31//  name is substituded for the *.
32//
33
34#include <xercesc/util/XercesDefs.hpp>
35
36XERCES_CPP_NAMESPACE_BEGIN
37
38class   DOMDocumentImpl;
39
40//
41//  DStringPoolEntry - one of these structs is allocated for each
42//                      XMLCh String in the pool.  Each slot in the
43//                      hash table array itself is a pointer to the head
44//                      of a singly-linked list of these structs.
45//
46//                      Although this struct is delcared with a string length of one,
47//                      the factory method allocates enough storage to hold the full
48//                      string length.
49//
50struct DOMStringPoolEntry
51{
52    DOMStringPoolEntry    *fNext;
53    XMLCh                 fString[1];
54};
55
56//
57// DOMBuffer is a lightweight text buffer
58// The buffer is not nul terminated until some asks to see the raw buffer
59// contents. This also avoids overhead during append operations.
60class DOMBuffer
61{
62public :
63    // -----------------------------------------------------------------------
64    //  Constructors and Destructor
65    // -----------------------------------------------------------------------
66    DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity = 31);
67
68    ~DOMBuffer()
69    {
70    }
71
72    // -----------------------------------------------------------------------
73    //  Buffer Management
74    // -----------------------------------------------------------------------
75    void append (const XMLCh* const chars);
76    void append (const XMLCh* const chars, const XMLSize_t count);
77
78    void set (const XMLCh* const chars);
79    void set (const XMLCh* const chars, const XMLSize_t count);
80
81    const XMLCh* getRawBuffer() const
82    {
83        fBuffer[fIndex] = 0;
84        return fBuffer;
85    }
86
87    void reset()
88    {
89        fIndex = 0;
90        fBuffer[0] = 0;
91    }
92
93    void chop
94    (
95        const XMLSize_t    count
96    )
97    {
98        fBuffer[count] = 0;
99        fIndex = count;
100    }
101
102
103    // -----------------------------------------------------------------------
104    //  Getters
105    // -----------------------------------------------------------------------
106    XMLSize_t getLen() const
107    {
108        return fIndex;
109    }
110
111    XMLSize_t getCapacity() const
112    {
113        return fCapacity;
114    }
115
116    // -----------------------------------------------------------------------
117    //  Private helpers
118    // -----------------------------------------------------------------------
119    void expandCapacity(const XMLSize_t extraNeeded);
120
121
122private :
123    // -----------------------------------------------------------------------
124    //  Private data members
125    //
126    //  fBuffer
127    //      The pointer to the buffer data. Its grown as needed. Its always
128    //      one larger than fCapacity, to leave room for the null terminator.
129    //
130    //  fIndex
131    //      The current index into the buffer, as characters are appended
132    //      to it. If its zero, then the buffer is empty.
133    //
134    //  fCapacity
135    //      The current capacity of the buffer. Its actually always one
136    //      larger, to leave room for the null terminator.
137    //
138    //  fDoc
139    //      For allocating memory
140    // -----------------------------------------------------------------------
141    XMLCh*           fBuffer;
142    XMLSize_t        fIndex;
143    XMLSize_t        fCapacity;
144    DOMDocumentImpl* fDoc;
145
146    // -----------------------------------------------------------------------
147    // Unimplemented constructors and operators
148    // -----------------------------------------------------------------------
149    DOMBuffer(const DOMBuffer &);
150    DOMBuffer & operator = (const DOMBuffer &);
151};
152
153inline void DOMBuffer::
154append (const XMLCh* const chars)
155{
156  XMLSize_t count = XMLString::stringLen(chars);
157  if (fIndex + count >= fCapacity)
158    expandCapacity(count);
159
160  memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
161  fIndex += count;
162
163  // Keep it null terminated
164  fBuffer[fIndex] = 0;
165}
166
167inline void DOMBuffer::
168append (const XMLCh* const chars, const XMLSize_t count)
169{
170  if (fIndex + count >= fCapacity)
171    expandCapacity(count);
172
173  memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
174  fIndex += count;
175
176  // Keep it null terminated
177  fBuffer[fIndex] = 0;
178}
179
180inline void DOMBuffer::
181set (const XMLCh* const chars)
182{
183  XMLSize_t count = XMLString::stringLen(chars);
184  fIndex = 0;
185  if (count >= fCapacity)
186    expandCapacity(count);
187
188  memcpy(fBuffer, chars, count * sizeof(XMLCh));
189  fIndex = count;
190
191  // Keep it null terminated
192  fBuffer[fIndex] = 0;
193}
194
195inline void DOMBuffer::
196set (const XMLCh* const chars, const XMLSize_t count)
197{
198  fIndex = 0;
199  if (count >= fCapacity)
200    expandCapacity(count);
201
202  memcpy(fBuffer, chars, count * sizeof(XMLCh));
203  fIndex = count;
204
205  // Keep it null terminated
206  fBuffer[fIndex] = 0;
207}
208
209XERCES_CPP_NAMESPACE_END
210
211#endif
Note: See TracBrowser for help on using the repository browser.