00001 /* 00002 * Copyright 1999-2002,2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /* 00018 * $Id: MemBufFormatTarget.hpp 191054 2005-06-17 02:56:35Z jberry $ 00019 */ 00020 00021 #ifndef MemBufFormatTarget_HEADER_GUARD_ 00022 #define MemBufFormatTarget_HEADER_GUARD_ 00023 00024 #include <xercesc/framework/XMLFormatter.hpp> 00025 00026 XERCES_CPP_NAMESPACE_BEGIN 00027 00028 /* 00029 * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code 00030 * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree) 00031 * in a memory buffer. 00032 * 00033 * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon 00034 * construction, which grows as needed. The buffer will be deleted when 00035 * MemBufFormatTarget is destructed; or will be reset when the reset() function 00036 * is called. 00037 * 00038 * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request, 00039 * through the method getRawBuffer(), and user should make its own copy of the 00040 * returned buffer if it intends to keep it independent on the state of the 00041 * MemBufFormatTarget. 00042 */ 00043 00044 class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget { 00045 public: 00046 00049 MemBufFormatTarget 00050 ( 00051 int initCapacity = 1023 00052 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 00053 ) ; 00054 ~MemBufFormatTarget(); 00056 00057 // ----------------------------------------------------------------------- 00058 // Implementations of the format target interface 00059 // ----------------------------------------------------------------------- 00060 virtual void writeChars(const XMLByte* const toWrite 00061 , const unsigned int count 00062 , XMLFormatter* const formatter); 00063 00064 // ----------------------------------------------------------------------- 00065 // Getter 00066 // ----------------------------------------------------------------------- 00074 const XMLByte* getRawBuffer() const; 00075 00083 unsigned int getLen() const 00084 { 00085 return fIndex; 00086 } 00087 00094 void reset(); 00096 00097 private: 00098 // ----------------------------------------------------------------------- 00099 // Unimplemented methods. 00100 // ----------------------------------------------------------------------- 00101 MemBufFormatTarget(const MemBufFormatTarget&); 00102 MemBufFormatTarget& operator=(const MemBufFormatTarget&); 00103 00104 // ----------------------------------------------------------------------- 00105 // Private helpers 00106 // ----------------------------------------------------------------------- 00107 void insureCapacity(const unsigned int extraNeeded); 00108 00109 // ----------------------------------------------------------------------- 00110 // Private data members 00111 // 00112 // fDataBuf 00113 // The pointer to the buffer data. Its grown as needed. Its always 00114 // one larger than fCapacity, to leave room for the null terminator. 00115 // 00116 // fIndex 00117 // The current index into the buffer, as characters are appended 00118 // to it. If its zero, then the buffer is empty. 00119 // 00120 // fCapacity 00121 // The current capacity of the buffer. Its actually always one 00122 // larger, to leave room for the null terminator. 00123 // 00124 // ----------------------------------------------------------------------- 00125 MemoryManager* fMemoryManager; 00126 XMLByte* fDataBuf; 00127 unsigned int fIndex; 00128 unsigned int fCapacity; 00129 00130 }; 00131 00132 XERCES_CPP_NAMESPACE_END 00133 00134 #endif 00135