00001 /*00002 * Licensed to the Apache Software Foundation (ASF) under one or more00003 * contributor license agreements. See the NOTICE file distributed with00004 * this work for additional information regarding copyright ownership.00005 * The ASF licenses this file to You under the Apache License, Version 2.000006 * (the "License"); you may not use this file except in compliance with00007 * the License. You may obtain a copy of the License at00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.000010 * 00011 * Unless required by applicable law or agreed to in writing, software00012 * distributed under the License is distributed on an "AS IS" BASIS,00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.00014 * See the License for the specific language governing permissions and00015 * limitations under the License.00016 */00017
00018 /*00019 * $Id: MemBufFormatTarget.hpp 568078 2007-08-21 11:43:25Z amassari $00020 */00021
00022 #ifndef MemBufFormatTarget_HEADER_GUARD_00023 #define MemBufFormatTarget_HEADER_GUARD_00024
00025 #include <xercesc/framework/XMLFormatter.hpp>00026
00027 XERCES_CPP_NAMESPACE_BEGIN00028
00029 /*00030 * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code00031 * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree)00032 * in a memory buffer.00033 *00034 * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon00035 * construction, which grows as needed. The buffer will be deleted when00036 * MemBufFormatTarget is destructed; or will be reset when the reset() function00037 * is called.00038 *00039 * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,00040 * through the method getRawBuffer(), and user should make its own copy of the00041 * returned buffer if it intends to keep it independent on the state of the00042 * MemBufFormatTarget.00043 */00044
00045class MemBufFormatTarget : publicXMLFormatTarget {
00046 public:
00047
00050 MemBufFormatTarget00051 (
00052 int initCapacity = 1023
00053 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager00054 ) ;
00055 ~MemBufFormatTarget();
00057
00058 // -----------------------------------------------------------------------00059 // Implementations of the format target interface00060 // -----------------------------------------------------------------------00061 virtualvoidwriteChars(constXMLByte* const toWrite
00062 , constunsignedint count
00063 , XMLFormatter* const formatter);
00064
00065 // -----------------------------------------------------------------------00066 // Getter00067 // -----------------------------------------------------------------------00075 constXMLByte* getRawBuffer() const;
00076
00084unsignedint getLen() const00085 {
00086 return fIndex;
00087 }
00088
00095 void reset();
00097
00098 private:
00099 // -----------------------------------------------------------------------00100 // Unimplemented methods.00101 // -----------------------------------------------------------------------00102 MemBufFormatTarget(constMemBufFormatTarget&);
00103 MemBufFormatTarget& operator=(constMemBufFormatTarget&);
00104
00105 // -----------------------------------------------------------------------00106 // Private helpers00107 // -----------------------------------------------------------------------00108 void insureCapacity(constunsignedint extraNeeded);
00109
00110 // -----------------------------------------------------------------------00111 // Private data members00112 //00113 // fDataBuf00114 // The pointer to the buffer data. Its grown as needed. Its always00115 // one larger than fCapacity, to leave room for the null terminator.00116 //00117 // fIndex00118 // The current index into the buffer, as characters are appended00119 // to it. If its zero, then the buffer is empty.00120 //00121 // fCapacity00122 // The current capacity of the buffer. Its actually always one00123 // larger, to leave room for the null terminator.00124 //00125 // -----------------------------------------------------------------------00126 MemoryManager* fMemoryManager;
00127 XMLByte* fDataBuf;
00128 unsignedint fIndex;
00129 unsignedint fCapacity;
00130
00131 };
00132
00133 XERCES_CPP_NAMESPACE_END00134
00135 #endif00136