source: NonGTP/Xerces/xercesc/framework/XMLBufferMgr.hpp @ 188

Revision 188, 8.8 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: XMLBufferMgr.hpp,v $
59 * Revision 1.7  2004/01/29 11:46:29  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.6  2003/05/16 21:36:55  knoaman
63 * Memory manager implementation: Modify constructors to pass in the memory manager.
64 *
65 * Revision 1.5  2003/05/15 18:26:07  knoaman
66 * Partial implementation of the configurable memory manager.
67 *
68 * Revision 1.4  2002/12/04 02:32:43  knoaman
69 * #include cleanup.
70 *
71 * Revision 1.3  2002/11/04 15:00:21  tng
72 * C++ Namespace Support.
73 *
74 * Revision 1.2  2002/08/21 18:54:52  tng
75 * [Bug 11869] Add the const modifier (XMLBuffer.hpp).
76 *
77 * Revision 1.1.1.1  2002/02/01 22:21:51  peiyongz
78 * sane_include
79 *
80 * Revision 1.5  2000/03/02 19:54:24  roddey
81 * This checkin includes many changes done while waiting for the
82 * 1.1.0 code to be finished. I can't list them all here, but a list is
83 * available elsewhere.
84 *
85 * Revision 1.4  2000/02/24 20:00:23  abagchi
86 * Swat for removing Log from API docs
87 *
88 * Revision 1.3  2000/02/15 01:21:30  roddey
89 * Some initial documentation improvements. More to come...
90 *
91 * Revision 1.2  2000/02/06 07:47:47  rahulj
92 * Year 2K copyright swat.
93 *
94 * Revision 1.1.1.1  1999/11/09 01:08:30  twl
95 * Initial checkin
96 *
97 * Revision 1.2  1999/11/08 20:44:36  rahul
98 * Swat for adding in Product name and CVS comment log variable.
99 *
100 */
101
102
103#if !defined(XMLBUFFERMGR_HPP)
104#define XMLBUFFERMGR_HPP
105
106#include <xercesc/framework/XMLBuffer.hpp>
107
108XERCES_CPP_NAMESPACE_BEGIN
109
110class XMLBufBid;
111
112/**
113 *  There are many places where XMLBuffer objects are needed. In order to
114 *  avoid either constantly creating and destroying them or maintaining a
115 *  fixed set and worrying about accidental reuse, a buffer manager can
116 *  provide a pool of buffers which can be temporarily used and then put
117 *  back into the pool. This provides a good compromise between performance
118 *  and easier maintenance.
119 */
120class XMLPARSER_EXPORT XMLBufferMgr : public XMemory
121{
122public :
123    // -----------------------------------------------------------------------
124    //  Constructors and Destructor
125    // -----------------------------------------------------------------------
126
127    /** @name Constructor */
128    //@{
129    XMLBufferMgr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
130    //@}
131
132    /** @name Destructor */
133    //@{
134    ~XMLBufferMgr();
135    //@}
136
137
138    // -----------------------------------------------------------------------
139    //  Buffer management
140    // -----------------------------------------------------------------------
141    XMLBuffer& bidOnBuffer();
142    void releaseBuffer(XMLBuffer& toRelease);
143
144
145private :
146    // -----------------------------------------------------------------------
147    //  Unimplemented constructors and operators
148    // -----------------------------------------------------------------------
149    XMLBufferMgr(const XMLBufferMgr&);
150    XMLBufferMgr& operator=(const XMLBufferMgr&);
151
152    // -----------------------------------------------------------------------
153    //  Private data members
154    //
155    //  fBufCount
156    //      The count of buffers that have been allocated so far.
157    //
158    //  fBufList;
159    //      The list of pointers to buffers that are loaned out. There will
160    //      never be a lot of them, so a flat list is good enough.
161    // -----------------------------------------------------------------------
162    unsigned int    fBufCount;
163    MemoryManager*  fMemoryManager;
164    XMLBuffer**     fBufList;
165};
166
167
168/**
169 *  XMLBufBid is a scoped based janitor that allows the scanner code to ask
170 *  for a buffer on a scoped basis and then insure that it gets freed back
171 *  into the pool no matter how the scope is exited (exception or normal exit.)
172 */
173class XMLBufBid : public XMemory
174{
175public :
176    // -----------------------------------------------------------------------
177    //  Constructors and Destructor
178    // -----------------------------------------------------------------------
179    XMLBufBid(XMLBufferMgr* const srcMgr) :
180
181        fBuffer(srcMgr->bidOnBuffer())
182        , fMgr(srcMgr)
183    {
184    }
185
186    ~XMLBufBid()
187    {
188        fMgr->releaseBuffer(fBuffer);
189    }
190
191
192
193    // -----------------------------------------------------------------------
194    //  Buffer access
195    // -----------------------------------------------------------------------
196    void append(const XMLCh toAppend)
197    {
198        fBuffer.append(toAppend);
199    }
200
201    void append(const XMLCh* const toAppend, const unsigned int count = 0)
202    {
203        fBuffer.append(toAppend, count);
204    }
205
206    const XMLBuffer& getBuffer() const
207    {
208        return fBuffer;
209    }
210
211    XMLBuffer& getBuffer()
212    {
213        return fBuffer;
214    }
215
216    const XMLCh* getRawBuffer() const
217    {
218        fBuffer.fBuffer[fBuffer.fIndex] = 0;
219        return fBuffer.fBuffer;
220    }
221
222    XMLCh* getRawBuffer()
223    {
224        fBuffer.fBuffer[fBuffer.fIndex] = 0;
225        return fBuffer.fBuffer;
226    }
227
228    unsigned int getLen() const
229    {
230        return fBuffer.fIndex;
231    }
232
233    bool isEmpty() const
234    {
235        return (fBuffer.fIndex == 0);
236    }
237
238    void reset()
239    {
240        fBuffer.reset();
241    }
242
243    void set(const XMLCh* const chars, const unsigned int count = 0)
244    {
245        fBuffer.set(chars, count);
246    }
247
248
249private :
250    // -----------------------------------------------------------------------
251    //  Unimplemented constructors and operators
252    // -----------------------------------------------------------------------
253    XMLBufBid(const XMLBufBid&);
254    XMLBufBid& operator=(const XMLBufBid&);
255
256    // -----------------------------------------------------------------------
257    //  Private data members
258    //
259    //  fBuffer
260    //      This is the buffer we got, and which we will release.
261    //
262    //  fMgr
263    //      This is the buffer manager we got the buffer from. This is needed
264    //      to release the buffer later.
265    // -----------------------------------------------------------------------
266    XMLBuffer&          fBuffer;
267    XMLBufferMgr* const fMgr;
268};
269
270XERCES_CPP_NAMESPACE_END
271
272#endif
Note: See TracBrowser for help on using the repository browser.