http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

MemBufFormatTarget.hpp

Go to the documentation of this file.
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,v 1.8 2004/09/08 13:55:57 peiyongz Exp $
00019  * $Log: MemBufFormatTarget.hpp,v $
00020  * Revision 1.8  2004/09/08 13:55:57  peiyongz
00021  * Apache License Version 2.0
00022  *
00023  * Revision 1.7  2003/05/16 21:36:55  knoaman
00024  * Memory manager implementation: Modify constructors to pass in the memory manager.
00025  *
00026  * Revision 1.6  2003/05/15 18:26:07  knoaman
00027  * Partial implementation of the configurable memory manager.
00028  *
00029  * Revision 1.5  2002/11/04 15:00:21  tng
00030  * C++ Namespace Support.
00031  *
00032  * Revision 1.4  2002/08/12 21:38:22  peiyongz
00033  * Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from
00034  *                      Esmond Pitt (pitte@anz.com)
00035  *
00036  * Revision 1.3  2002/07/22 23:23:15  tng
00037  * DOM L3: MemBufFormatTarget stores fDataBuf as XMLByte directly, consistent design as MemBufInputSource
00038  *
00039  * Revision 1.2  2002/06/05 15:47:13  peiyongz
00040  * data member changed, reset() added.
00041  *
00042  * Revision 1.1  2002/05/28 22:40:46  peiyongz
00043  * DOM3 Save Interface: DOMWriter/DOMWriterFilter
00044  *
00045  */
00046 
00047 #ifndef MemBufFormatTarget_HEADER_GUARD_
00048 #define MemBufFormatTarget_HEADER_GUARD_
00049 
00050 #include <xercesc/framework/XMLFormatter.hpp>
00051 
00052 XERCES_CPP_NAMESPACE_BEGIN
00053 
00054 /*
00055  * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
00056  * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree)
00057  * in a memory buffer.
00058  *
00059  * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon
00060  * construction, which grows as needed. The buffer will be deleted when
00061  * MemBufFormatTarget is destructed; or will be reset when the reset() function
00062  * is called.
00063  *
00064  * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,
00065  * through the method getRawBuffer(), and user should make its own copy of the
00066  * returned buffer if it intends to keep it independent on the state of the
00067  * MemBufFormatTarget.
00068  */
00069 
00070 class  MemBufFormatTarget : public XMLFormatTarget {
00071 public:
00072 
00075     MemBufFormatTarget
00076     (
00077           int                  initCapacity = 1023
00078         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00079     ) ;
00080     ~MemBufFormatTarget();
00082 
00083     // -----------------------------------------------------------------------
00084     //  Implementations of the format target interface
00085     // -----------------------------------------------------------------------
00086     virtual void writeChars(const XMLByte* const toWrite
00087                           , const unsigned int   count
00088                           , XMLFormatter* const  formatter);
00089 
00090     // -----------------------------------------------------------------------
00091     //  Getter
00092     // -----------------------------------------------------------------------
00100     const XMLByte* getRawBuffer() const;
00101 
00109     unsigned int getLen() const
00110     {
00111         return fIndex;
00112     }
00113 
00120     void reset();
00122 
00123 private:
00124     // -----------------------------------------------------------------------
00125     //  Unimplemented methods.
00126     // -----------------------------------------------------------------------
00127     MemBufFormatTarget(const MemBufFormatTarget&);
00128     MemBufFormatTarget& operator=(const MemBufFormatTarget&);
00129 
00130     // -----------------------------------------------------------------------
00131     //  Private helpers
00132     // -----------------------------------------------------------------------
00133     void insureCapacity(const unsigned int extraNeeded);
00134 
00135     // -----------------------------------------------------------------------
00136     //  Private data members
00137     //
00138     //  fDataBuf
00139     //      The pointer to the buffer data. Its grown as needed. Its always
00140     //      one larger than fCapacity, to leave room for the null terminator.
00141     //
00142     //  fIndex
00143     //      The current index into the buffer, as characters are appended
00144     //      to it. If its zero, then the buffer is empty.
00145     //
00146     //  fCapacity
00147     //      The current capacity of the buffer. Its actually always one
00148     //      larger, to leave room for the null terminator.
00149     //
00150     // -----------------------------------------------------------------------
00151     MemoryManager*  fMemoryManager;
00152     XMLByte*        fDataBuf;
00153     unsigned int    fIndex;
00154     unsigned int    fCapacity;
00155 
00156 };
00157 
00158 XERCES_CPP_NAMESPACE_END
00159 
00160 #endif
00161 


Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.