source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/framework/MemBufFormatTarget.hpp @ 2674

Revision 2674, 4.4 KB checked in by mattausch, 16 years ago (diff)
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: MemBufFormatTarget.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#ifndef MemBufFormatTarget_HEADER_GUARD_
23#define MemBufFormatTarget_HEADER_GUARD_
24
25#include <xercesc/framework/XMLFormatter.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29/*
30 * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
31 * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree)
32 * in a memory buffer.
33 *
34 * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon
35 * construction, which grows as needed. The buffer will be deleted when
36 * MemBufFormatTarget is destructed; or will be reset when the reset() function
37 * is called.
38 *
39 * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,
40 * through the method getRawBuffer(), and user should make its own copy of the
41 * returned buffer if it intends to keep it independent on the state of the
42 * MemBufFormatTarget.
43 */
44
45class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget {
46public:
47
48    /** @name constructors and destructor */
49    //@{
50    MemBufFormatTarget
51    (
52          int                  initCapacity = 1023
53        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
54    ) ;
55    ~MemBufFormatTarget();
56    //@}
57
58    // -----------------------------------------------------------------------
59    //  Implementations of the format target interface
60    // -----------------------------------------------------------------------
61    virtual void writeChars(const XMLByte* const toWrite
62                          , const unsigned int   count
63                          , XMLFormatter* const  formatter);
64
65    // -----------------------------------------------------------------------
66    //  Getter
67    // -----------------------------------------------------------------------
68    /** @name getRawBuffer */
69    //@{
70    /**
71     * Returned the internal raw buffer.
72     *
73     */
74    //@}
75    const XMLByte* getRawBuffer() const;
76
77    /** @name getLen */
78    //@{
79    /**
80     * Returned the length of the raw buffer.
81     *
82     */
83    //@}
84    unsigned int getLen() const
85    {
86        return fIndex;
87    }
88
89    /** @name reset */
90    //@{
91    /**
92     * Reset the internal string buffer.
93     *
94     */
95    void reset();
96    //@}
97
98private:
99    // -----------------------------------------------------------------------
100    //  Unimplemented methods.
101    // -----------------------------------------------------------------------
102    MemBufFormatTarget(const MemBufFormatTarget&);
103    MemBufFormatTarget& operator=(const MemBufFormatTarget&);
104
105    // -----------------------------------------------------------------------
106    //  Private helpers
107    // -----------------------------------------------------------------------
108    void insureCapacity(const unsigned int extraNeeded);
109
110    // -----------------------------------------------------------------------
111    //  Private data members
112    //
113    //  fDataBuf
114    //      The pointer to the buffer data. Its grown as needed. Its always
115    //      one larger than fCapacity, to leave room for the null terminator.
116    //
117    //  fIndex
118    //      The current index into the buffer, as characters are appended
119    //      to it. If its zero, then the buffer is empty.
120    //
121    //  fCapacity
122    //      The current capacity of the buffer. Its actually always one
123    //      larger, to leave room for the null terminator.
124    //
125    // -----------------------------------------------------------------------
126    MemoryManager*  fMemoryManager;
127    XMLByte*        fDataBuf;
128    unsigned int    fIndex;
129    unsigned int    fCapacity;
130
131};
132
133XERCES_CPP_NAMESPACE_END
134
135#endif
136
Note: See TracBrowser for help on using the repository browser.