GME
13
|
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 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/util/BinMemInputStream.hpp> 00027 #include <xercesc/framework/MemBufInputSource.hpp> 00028 00029 XERCES_CPP_NAMESPACE_BEGIN 00030 00031 // --------------------------------------------------------------------------- 00032 // MemBufInputSource: Constructors and Destructor 00033 // --------------------------------------------------------------------------- 00034 MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes 00035 , const XMLSize_t byteCount 00036 , const XMLCh* const bufId 00037 , const bool adoptBuffer 00038 , MemoryManager* const manager) : 00039 InputSource(bufId, manager) 00040 , fAdopted(adoptBuffer) 00041 , fByteCount(byteCount) 00042 , fCopyBufToStream(true) 00043 , fSrcBytes(srcDocBytes) 00044 { 00045 } 00046 00047 MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes 00048 , const XMLSize_t byteCount 00049 , const char* const bufId 00050 , const bool adoptBuffer 00051 , MemoryManager* const manager) : 00052 InputSource(bufId, manager) 00053 , fAdopted(adoptBuffer) 00054 , fByteCount(byteCount) 00055 , fCopyBufToStream(true) 00056 , fSrcBytes(srcDocBytes) 00057 { 00058 } 00059 00060 MemBufInputSource::~MemBufInputSource() 00061 { 00062 if (fAdopted) 00063 delete [] (XMLByte*)fSrcBytes; 00064 } 00065 00066 void MemBufInputSource::resetMemBufInputSource(const XMLByte* const srcDocBytes 00067 , const XMLSize_t byteCount) 00068 { 00069 fByteCount = byteCount; 00070 fSrcBytes = srcDocBytes; 00071 } 00072 00073 // --------------------------------------------------------------------------- 00074 // MemBufInputSource: InputSource interface implementation 00075 // --------------------------------------------------------------------------- 00076 BinInputStream* MemBufInputSource::makeStream() const 00077 { 00078 // 00079 // Create a memory input stream over our buffer. According to our 00080 // fCopyBufToStream flag, we either tell it to copy the buffer or to 00081 // just reference it. 00082 // 00083 return new (getMemoryManager()) BinMemInputStream 00084 ( 00085 fSrcBytes 00086 , fByteCount 00087 , fCopyBufToStream ? BinMemInputStream::BufOpt_Copy 00088 : BinMemInputStream::BufOpt_Reference 00089 , getMemoryManager() 00090 ); 00091 } 00092 00093 XERCES_CPP_NAMESPACE_END 00094