Xerces-C++  3.1.4
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 932887 2010-04-11 13:04:59Z borisk $
20  */
21 
22 #if !defined(XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP)
23 #define XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP
24 
26 
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 
46 public:
47 
51  (
52  XMLSize_t initCapacity = 1023
54  ) ;
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  // -----------------------------------------------------------------------
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 
134 
135 #endif
136 
virtual void writeChars(const XMLByte *const toWrite, const XMLSize_t count, XMLFormatter *const formatter)=0
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
This class provides the basic formatting capabilities that are required to turn the Unicode based XML...
Definition: XMLFormatter.hpp:41
XMLSize_t getLen() const
Returned the length of the raw buffer.
Definition: MemBufFormatTarget.hpp:84
#define XMLPARSER_EXPORT
Definition: XercesDefs.hpp:163
Definition: MemBufFormatTarget.hpp:45
Configurable memory manager.
Definition: MemoryManager.hpp:39
SIZE_T XMLSize_t
Definition: Xerces_autoconf_config.borland.hpp:86
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
unsigned char XMLByte
Definition: XercesDefs.hpp:65
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
Definition: XMLFormatter.hpp:442