1 | /*
|
---|
2 | * Copyright 1999-2002,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: MemBufFormatTarget.hpp,v 1.8 2004/09/08 13:55:57 peiyongz Exp $
|
---|
19 | * $Log: MemBufFormatTarget.hpp,v $
|
---|
20 | * Revision 1.8 2004/09/08 13:55:57 peiyongz
|
---|
21 | * Apache License Version 2.0
|
---|
22 | *
|
---|
23 | * Revision 1.7 2003/05/16 21:36:55 knoaman
|
---|
24 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
25 | *
|
---|
26 | * Revision 1.6 2003/05/15 18:26:07 knoaman
|
---|
27 | * Partial implementation of the configurable memory manager.
|
---|
28 | *
|
---|
29 | * Revision 1.5 2002/11/04 15:00:21 tng
|
---|
30 | * C++ Namespace Support.
|
---|
31 | *
|
---|
32 | * Revision 1.4 2002/08/12 21:38:22 peiyongz
|
---|
33 | * Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from
|
---|
34 | * Esmond Pitt (pitte@anz.com)
|
---|
35 | *
|
---|
36 | * Revision 1.3 2002/07/22 23:23:15 tng
|
---|
37 | * DOM L3: MemBufFormatTarget stores fDataBuf as XMLByte directly, consistent design as MemBufInputSource
|
---|
38 | *
|
---|
39 | * Revision 1.2 2002/06/05 15:47:13 peiyongz
|
---|
40 | * data member changed, reset() added.
|
---|
41 | *
|
---|
42 | * Revision 1.1 2002/05/28 22:40:46 peiyongz
|
---|
43 | * DOM3 Save Interface: DOMWriter/DOMWriterFilter
|
---|
44 | *
|
---|
45 | */
|
---|
46 |
|
---|
47 | #ifndef MemBufFormatTarget_HEADER_GUARD_
|
---|
48 | #define MemBufFormatTarget_HEADER_GUARD_
|
---|
49 |
|
---|
50 | #include <xercesc/framework/XMLFormatter.hpp>
|
---|
51 |
|
---|
52 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
|
---|
56 | * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree)
|
---|
57 | * in a memory buffer.
|
---|
58 | *
|
---|
59 | * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon
|
---|
60 | * construction, which grows as needed. The buffer will be deleted when
|
---|
61 | * MemBufFormatTarget is destructed; or will be reset when the reset() function
|
---|
62 | * is called.
|
---|
63 | *
|
---|
64 | * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,
|
---|
65 | * through the method getRawBuffer(), and user should make its own copy of the
|
---|
66 | * returned buffer if it intends to keep it independent on the state of the
|
---|
67 | * MemBufFormatTarget.
|
---|
68 | */
|
---|
69 |
|
---|
70 | class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget {
|
---|
71 | public:
|
---|
72 |
|
---|
73 | /** @name constructors and destructor */
|
---|
74 | //@{
|
---|
75 | MemBufFormatTarget
|
---|
76 | (
|
---|
77 | int initCapacity = 1023
|
---|
78 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
79 | ) ;
|
---|
80 | ~MemBufFormatTarget();
|
---|
81 | //@}
|
---|
82 |
|
---|
83 | // -----------------------------------------------------------------------
|
---|
84 | // Implementations of the format target interface
|
---|
85 | // -----------------------------------------------------------------------
|
---|
86 | virtual void writeChars(const XMLByte* const toWrite
|
---|
87 | , const unsigned int count
|
---|
88 | , XMLFormatter* const formatter);
|
---|
89 |
|
---|
90 | // -----------------------------------------------------------------------
|
---|
91 | // Getter
|
---|
92 | // -----------------------------------------------------------------------
|
---|
93 | /** @name getRawBuffer */
|
---|
94 | //@{
|
---|
95 | /**
|
---|
96 | * Returned the internal raw buffer.
|
---|
97 | *
|
---|
98 | */
|
---|
99 | //@}
|
---|
100 | const XMLByte* getRawBuffer() const;
|
---|
101 |
|
---|
102 | /** @name getLen */
|
---|
103 | //@{
|
---|
104 | /**
|
---|
105 | * Returned the length of the raw buffer.
|
---|
106 | *
|
---|
107 | */
|
---|
108 | //@}
|
---|
109 | unsigned int getLen() const
|
---|
110 | {
|
---|
111 | return fIndex;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /** @name reset */
|
---|
115 | //@{
|
---|
116 | /**
|
---|
117 | * Reset the internal string buffer.
|
---|
118 | *
|
---|
119 | */
|
---|
120 | void reset();
|
---|
121 | //@}
|
---|
122 |
|
---|
123 | private:
|
---|
124 | // -----------------------------------------------------------------------
|
---|
125 | // Unimplemented methods.
|
---|
126 | // -----------------------------------------------------------------------
|
---|
127 | MemBufFormatTarget(const MemBufFormatTarget&);
|
---|
128 | MemBufFormatTarget& operator=(const MemBufFormatTarget&);
|
---|
129 |
|
---|
130 | // -----------------------------------------------------------------------
|
---|
131 | // Private helpers
|
---|
132 | // -----------------------------------------------------------------------
|
---|
133 | void insureCapacity(const unsigned int extraNeeded);
|
---|
134 |
|
---|
135 | // -----------------------------------------------------------------------
|
---|
136 | // Private data members
|
---|
137 | //
|
---|
138 | // fDataBuf
|
---|
139 | // The pointer to the buffer data. Its grown as needed. Its always
|
---|
140 | // one larger than fCapacity, to leave room for the null terminator.
|
---|
141 | //
|
---|
142 | // fIndex
|
---|
143 | // The current index into the buffer, as characters are appended
|
---|
144 | // to it. If its zero, then the buffer is empty.
|
---|
145 | //
|
---|
146 | // fCapacity
|
---|
147 | // The current capacity of the buffer. Its actually always one
|
---|
148 | // larger, to leave room for the null terminator.
|
---|
149 | //
|
---|
150 | // -----------------------------------------------------------------------
|
---|
151 | MemoryManager* fMemoryManager;
|
---|
152 | XMLByte* fDataBuf;
|
---|
153 | unsigned int fIndex;
|
---|
154 | unsigned int fCapacity;
|
---|
155 |
|
---|
156 | };
|
---|
157 |
|
---|
158 | XERCES_CPP_NAMESPACE_END
|
---|
159 |
|
---|
160 | #endif
|
---|
161 |
|
---|