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