Xerces-C++ 3.2.2

MemBufFormatTarget.hpp
Go to the documentation of this file.
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 932889 2010-04-11 13:10:10Z borisk $
20 */
21
22 #if !defined(XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP)
23 #define XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP
24
25 #include <xercesc/framework/XMLFormatter.hpp>
26
27 XERCES_CPP_NAMESPACE_BEGIN
28
29 /*
30 * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
31 * may plug into DOMLSSerializer to retrieve the serialized XML stream (from DOM Tree)
32 * in a memory buffer.
33 *
34 * The MemBufFormatTarget is initialized 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
45 class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget {
46 public:
47
50 MemBufFormatTarget
51 (
52 XMLSize_t initCapacity = 1023
53 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
54 ) ;
55 ~MemBufFormatTarget();
57
58 // -----------------------------------------------------------------------
59 // Implementations of the format target interface
60 // -----------------------------------------------------------------------
61 virtual void writeChars(const XMLByte* const toWrite
62 , const XMLSize_t count
63 , XMLFormatter* const formatter);
64
65 // -----------------------------------------------------------------------
66 // Getter
67 // -----------------------------------------------------------------------
75 const XMLByte* getRawBuffer() const;
76
84 XMLSize_t getLen() const
85 {
86 return fIndex;
87 }
88
95 void reset();
97
98 private:
99 // -----------------------------------------------------------------------
100 // Unimplemented methods.
101 // -----------------------------------------------------------------------
102 MemBufFormatTarget(const MemBufFormatTarget&);
103 MemBufFormatTarget& operator=(const MemBufFormatTarget&);
104
105 // -----------------------------------------------------------------------
106 // Private helpers
107 // -----------------------------------------------------------------------
108 void ensureCapacity(const XMLSize_t 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 XMLSize_t fIndex;
129 XMLSize_t fCapacity;
130
131 };
132
133 XERCES_CPP_NAMESPACE_END
134
135 #endif
136
XMLFormatTarget::writeChars
virtual void writeChars(const XMLByte *const toWrite, const XMLSize_t count, XMLFormatter *const formatter)=0
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLFormatter
This class provides the basic formatting capabilities that are required to turn the Unicode based XML...
Definition: XMLFormatter.hpp:41
XMLPARSER_EXPORT
#define XMLPARSER_EXPORT
Definition: XercesDefs.hpp:163
XMLFormatter.hpp
MemBufFormatTarget
Definition: MemBufFormatTarget.hpp:45
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLByte
unsigned char XMLByte
Definition: XercesDefs.hpp:65
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLFormatTarget
Definition: XMLFormatter.hpp:442
MemBufFormatTarget::getLen
XMLSize_t getLen() const
Returned the length of the raw buffer.
Definition: MemBufFormatTarget.hpp:84