Xerces-C++: MemBufFormatTarget.hpp Source File

| API Docs for SAX and DOM |
| Main Page Classes Files Related Pages # MemBufFormatTarget.hpp Go to the documentation of this file.
    00001 /*
    00002  * Licensed to the Apache Software Foundation (ASF) under one or more
    00003  * contributor license agreements.  See the NOTICE file distributed with
    00004  * this work for additional information regarding copyright ownership.
    00005  * The ASF licenses this file to You under the Apache License, Version 2.0
    00006  * (the "License"); you may not use this file except in compliance with
    00007  * the License.  You may obtain a copy of the License at
    00008  *
    00009  *      http://www.apache.org/licenses/LICENSE-2.0
    00010  *
    00011  * Unless required by applicable law or agreed to in writing, software
    00012  * 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 and
    00015  * 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_BEGIN
    00028
    00029 /*
    00030  * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
    00031  * 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 upon
    00035  * construction, which grows as needed. The buffer will be deleted when
    00036  * MemBufFormatTarget is destructed; or will be reset when the reset() function
    00037  * 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 the
    00041  * returned buffer if it intends to keep it independent on the state of the
    00042  * MemBufFormatTarget.
    00043  */
    00044
    00045 class  MemBufFormatTarget : public XMLFormatTarget {
    00046 public:
    00047
    00050     MemBufFormatTarget
    00051     (
    00052           int                  initCapacity = 1023
    00053         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00054     ) ;
    00055     ~MemBufFormatTarget();
    00057
    00058     // -----------------------------------------------------------------------
    00059     //  Implementations of the format target interface
    00060     // -----------------------------------------------------------------------
    00061     virtual void writeChars(const XMLByte* const toWrite
    00062                           , const unsigned int   count
    00063                           , XMLFormatter* const  formatter);
    00064
    00065     // -----------------------------------------------------------------------
    00066     //  Getter
    00067     // -----------------------------------------------------------------------
    00075     const XMLByte* getRawBuffer() const;
    00076
    00084     unsigned int getLen() const
    00085     {
    00086         return fIndex;
    00087     }
    00088
    00095     void reset();
    00097
    00098 private:
    00099     // -----------------------------------------------------------------------
    00100     //  Unimplemented methods.
    00101     // -----------------------------------------------------------------------
    00102     MemBufFormatTarget(const MemBufFormatTarget&);
    00103     MemBufFormatTarget& operator=(const MemBufFormatTarget&);
    00104
    00105     // -----------------------------------------------------------------------
    00106     //  Private helpers
    00107     // -----------------------------------------------------------------------
    00108     void insureCapacity(const unsigned int extraNeeded);
    00109
    00110     // -----------------------------------------------------------------------
    00111     //  Private data members
    00112     //
    00113     //  fDataBuf
    00114     //      The pointer to the buffer data. Its grown as needed. Its always
    00115     //      one larger than fCapacity, to leave room for the null terminator.
    00116     //
    00117     //  fIndex
    00118     //      The current index into the buffer, as characters are appended
    00119     //      to it. If its zero, then the buffer is empty.
    00120     //
    00121     //  fCapacity
    00122     //      The current capacity of the buffer. Its actually always one
    00123     //      larger, to leave room for the null terminator.
    00124     //
    00125     // -----------------------------------------------------------------------
    00126     MemoryManager*  fMemoryManager;
    00127     XMLByte*        fDataBuf;
    00128     unsigned int    fIndex;
    00129     unsigned int    fCapacity;
    00130
    00131 };
    00132
    00133 XERCES_CPP_NAMESPACE_END
    00134
    00135 #endif
    00136

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