source: trunk/VUT/GtpVisibilityPreprocessor/support/xercesc/framework/MemBufInputSource.hpp @ 188

Revision 188, 11.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: MemBufInputSource.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/12/01 23:23:25  neilg
63 * fix for bug 25118; thanks to Jeroen Witmond
64 *
65 * Revision 1.5  2003/07/30 14:48:38  peiyongz
66 * Allow default value
67 *
68 * Revision 1.4  2003/05/16 21:36:55  knoaman
69 * Memory manager implementation: Modify constructors to pass in the memory manager.
70 *
71 * Revision 1.3  2002/11/04 15:00:21  tng
72 * C++ Namespace Support.
73 *
74 * Revision 1.2  2002/02/20 18:17:01  tng
75 * [Bug 5977] Warnings on generating apiDocs.
76 *
77 * Revision 1.1.1.1  2002/02/01 22:21:50  peiyongz
78 * sane_include
79 *
80 * Revision 1.6  2000/12/14 18:49:54  tng
81 * Fix API document generation warning: "Warning: end of member group without matching begin"
82 *
83 * Revision 1.5  2000/02/24 20:00:22  abagchi
84 * Swat for removing Log from API docs
85 *
86 * Revision 1.4  2000/02/15 23:59:06  roddey
87 * More updated documentation of Framework classes.
88 *
89 * Revision 1.3  2000/02/15 01:21:30  roddey
90 * Some initial documentation improvements. More to come...
91 *
92 * Revision 1.2  2000/02/06 07:47:46  rahulj
93 * Year 2K copyright swat.
94 *
95 * Revision 1.1  2000/01/12 00:13:26  roddey
96 * These were moved from internal/ to framework/, which was something that should have
97 * happened long ago. They are really framework type of classes.
98 *
99 * Revision 1.1.1.1  1999/11/09 01:08:10  twl
100 * Initial checkin
101 *
102 * Revision 1.2  1999/11/08 20:44:43  rahul
103 * Swat for adding in Product name and CVS comment log variable.
104 *
105 */
106
107
108#if !defined(MEMBUFINPUTSOURCE_HPP)
109#define MEMBUFINPUTSOURCE_HPP
110
111#include <xercesc/sax/InputSource.hpp>
112
113XERCES_CPP_NAMESPACE_BEGIN
114
115class BinInputStream;
116
117
118/**
119 *  This class is a derivative of the standard InputSource class. It provides
120 *  for the parser access to data stored in a memory buffer. The type of
121 *  buffer and its host specific attributes are of little concern here. The
122 *  only real requirement is that the memory be readable by the current
123 *  process.
124 *
125 *  Note that the memory buffer size is expressed in <b>bytes</b>, not in
126 *  characters. If you pass it text data, you must account for the bytes
127 *  per character when indicating the buffer size.
128 *
129 *  As with all InputSource derivatives. The primary objective of an input
130 *  source is to create an input stream via which the parser can spool in
131 *  data from the referenced source. In this case, there are two options
132 *  available.
133 *
134 *  The passed buffer can be adopted or merely referenced. If it is adopted,
135 *  then it must be dynamically allocated and will be destroyed when the
136 *  input source is destroyed (no reference counting!.) If not adopted, the
137 *  caller must insure that it remains valid until the input source object
138 *  is destroyed.
139 *
140 *  The other option indicates whether each stream created for this input
141 *  source should get its own copy of the data, or whether it should just
142 *  stream the data directly from this object's copy of the data. The same
143 *  rules apply here, in that the buffer must either be copied by the
144 *  stream or it must remain valid until the stream is destroyed.
145 */
146class XMLPARSER_EXPORT MemBufInputSource : public InputSource
147{
148public :
149    // -----------------------------------------------------------------------
150    //  Constructors and Destructor
151    // -----------------------------------------------------------------------
152
153    /** @name Constructors */
154    //@{
155
156    /**
157      * A memory buffer input source is constructed from a buffer of byte
158      * data, and the count of bytes in that buffer. The parser will parse
159      * from this memory buffer until it has eaten the indicated number of
160      * bytes.
161      *
162      * Note that the system id provided serves two purposes. Firstly it is
163      * going to be displayed in error messages as the source of the error.
164      * And secondly, any entities which are refered to from this entity
165      * via relative paths/URLs will be relative to this fake system id.
166      *
167      * @param  srcDocBytes     The actual data buffer to be parsed from.
168      * @param  byteCount       The count of bytes (not characters, bytes!)
169      *                         in the buffer.
170      * @param  bufId           A fake system id for the buffer.
171      * @param  adoptBuffer     Indicates whether this object should adopt
172      *                         the buffer (i.e. make a copy of it) or just
173      *                         use it in place.
174      * @param  manager         Pointer to the memory manager to be used to
175      *                         allocate objects.
176      */
177    MemBufInputSource
178    (
179        const   XMLByte* const  srcDocBytes
180        , const unsigned int    byteCount
181        , const XMLCh* const    bufId
182        , const bool            adoptBuffer = false
183        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
184    );
185
186    /**
187      * This constructor is identical to the previous one, except that it takes
188      * the fake system id in local code page form and transcodes it internally.
189      */
190    MemBufInputSource
191    (
192        const   XMLByte* const  srcDocBytes
193        , const unsigned int    byteCount
194        , const char* const     bufId
195        , const bool            adoptBuffer = false
196        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
197    );
198    //@}
199
200    /** @name Destructor */
201    //@{
202    /**
203      * If the buffer was adopted, the copy made during construction is deleted
204      * at this point.
205      */
206    ~MemBufInputSource();
207    //@}
208
209
210    // -----------------------------------------------------------------------
211    //  Virtual input source interface
212    // -----------------------------------------------------------------------
213
214    /** @name Virtual methods */
215    //@{
216
217    /**
218      * This method will return a binary input stream derivative that will
219      * parse from the memory buffer. If setCopyBufToStream() has been set,
220      * then the stream will make its own copy. Otherwise, it will use the
221      * buffer as is (in which case it must remain valid until the stream
222      * is no longer in use, i.e. the parse completes.)
223      *
224      * @return A dynamically allocated binary input stream derivative that
225      *         can parse from the memory buffer.
226      */
227    BinInputStream* makeStream() const;
228
229    //@}
230
231
232    // -----------------------------------------------------------------------
233    //  Setter methods
234    // -----------------------------------------------------------------------
235
236    /** @name Setter methods */
237
238    //@{
239
240    /**
241      * By default, for safety's sake, each newly created stream from this
242      * input source will make its own copy of the buffer to stream from. This
243      * avoids having to deal with aliasing of the buffer for simple work. But,
244      * for higher performance applications or for large buffers, this is
245      * obviously not optimal.
246      *
247      * In such cases, you can call this method to turn off that default
248      * action. Once turned off, the streams will just get a pointer to the
249      * buffer and parse directly from that. In this case, you must insure that
250      * the buffer remains valid for as long as any parse events are still
251      * using it.
252      *
253      * @param  newState    The new boolean flag state to set.
254      */
255    void setCopyBufToStream(const bool newState);
256
257    //@}
258
259
260private :
261    // -----------------------------------------------------------------------
262    //  Unimplemented constructors and operators
263    // -----------------------------------------------------------------------
264    MemBufInputSource(const MemBufInputSource&);
265    MemBufInputSource& operator=(const MemBufInputSource&);
266
267    // -----------------------------------------------------------------------
268    //  Private data members
269    //
270    //  fAdopted
271    //      Indicates whether the buffer is adopted or not. If so, then it
272    //      is destroyed when the input source is destroyed.
273    //
274    //  fByteCount
275    //      The size of the source document.
276    //
277    //  fCopyBufToStream
278    //      This defaults to true (the safe option), which causes it to
279    //      give a copy of the buffer to any streams it creates. If you set
280    //      it to false, it will allow the streams to just reference the
281    //      buffer (in which case this input source must stay alive as long
282    //      as the buffer is in use by the stream.)
283    //
284    //  fSrcBytes
285    //      The source memory buffer that is being spooled from. Whether it
286    //      belongs to the this input source or not is controlled by the
287    //      fAdopted flag.
288    // -----------------------------------------------------------------------
289    bool            fAdopted;
290    unsigned int    fByteCount;
291    bool            fCopyBufToStream;
292    const XMLByte*  fSrcBytes;
293};
294
295
296inline void MemBufInputSource::setCopyBufToStream(const bool newState)
297{
298    fCopyBufToStream = newState;
299}
300
301XERCES_CPP_NAMESPACE_END
302
303#endif
Note: See TracBrowser for help on using the repository browser.