00001 /* 00002 * Copyright 1999-2000,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: MemBufInputSource.hpp 191054 2005-06-17 02:56:35Z jberry $ 00019 */ 00020 00021 00022 #if !defined(MEMBUFINPUTSOURCE_HPP) 00023 #define MEMBUFINPUTSOURCE_HPP 00024 00025 #include <xercesc/sax/InputSource.hpp> 00026 00027 XERCES_CPP_NAMESPACE_BEGIN 00028 00029 class BinInputStream; 00030 00031 00060 class XMLPARSER_EXPORT MemBufInputSource : public InputSource 00061 { 00062 public : 00063 // ----------------------------------------------------------------------- 00064 // Constructors and Destructor 00065 // ----------------------------------------------------------------------- 00066 00069 00092 MemBufInputSource 00093 ( 00094 const XMLByte* const srcDocBytes 00095 , const unsigned int byteCount 00096 , const XMLCh* const bufId 00097 , const bool adoptBuffer = false 00098 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 00099 ); 00100 00105 MemBufInputSource 00106 ( 00107 const XMLByte* const srcDocBytes 00108 , const unsigned int byteCount 00109 , const char* const bufId 00110 , const bool adoptBuffer = false 00111 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 00112 ); 00114 00121 ~MemBufInputSource(); 00123 00124 00125 // ----------------------------------------------------------------------- 00126 // Virtual input source interface 00127 // ----------------------------------------------------------------------- 00128 00131 00142 BinInputStream* makeStream() const; 00143 00145 00146 00147 // ----------------------------------------------------------------------- 00148 // Setter methods 00149 // ----------------------------------------------------------------------- 00150 00154 00170 void setCopyBufToStream(const bool newState); 00171 00181 void resetMemBufInputSource(const XMLByte* const srcDocBytes 00182 , const unsigned int byteCount); 00184 00185 00186 private : 00187 // ----------------------------------------------------------------------- 00188 // Unimplemented constructors and operators 00189 // ----------------------------------------------------------------------- 00190 MemBufInputSource(const MemBufInputSource&); 00191 MemBufInputSource& operator=(const MemBufInputSource&); 00192 00193 // ----------------------------------------------------------------------- 00194 // Private data members 00195 // 00196 // fAdopted 00197 // Indicates whether the buffer is adopted or not. If so, then it 00198 // is destroyed when the input source is destroyed. 00199 // 00200 // fByteCount 00201 // The size of the source document. 00202 // 00203 // fCopyBufToStream 00204 // This defaults to true (the safe option), which causes it to 00205 // give a copy of the buffer to any streams it creates. If you set 00206 // it to false, it will allow the streams to just reference the 00207 // buffer (in which case this input source must stay alive as long 00208 // as the buffer is in use by the stream.) 00209 // 00210 // fSrcBytes 00211 // The source memory buffer that is being spooled from. Whether it 00212 // belongs to the this input source or not is controlled by the 00213 // fAdopted flag. 00214 // ----------------------------------------------------------------------- 00215 bool fAdopted; 00216 unsigned int fByteCount; 00217 bool fCopyBufToStream; 00218 const XMLByte* fSrcBytes; 00219 }; 00220 00221 00222 inline void MemBufInputSource::setCopyBufToStream(const bool newState) 00223 { 00224 fCopyBufToStream = newState; 00225 } 00226 00227 XERCES_CPP_NAMESPACE_END 00228 00229 #endif