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$ 00020 */ 00021 00022 #if !defined(XERCESC_INCLUDE_GUARD_BINMEMINPUTSTREAM_HPP) 00023 #define XERCESC_INCLUDE_GUARD_BINMEMINPUTSTREAM_HPP 00024 00025 #include <xercesc/util/BinInputStream.hpp> 00026 #include <xercesc/util/PlatformUtils.hpp> 00027 00028 XERCES_CPP_NAMESPACE_BEGIN 00029 00030 class XMLUTIL_EXPORT BinMemInputStream : public BinInputStream 00031 { 00032 public : 00033 // ----------------------------------------------------------------------- 00034 // Class specific types 00035 // ----------------------------------------------------------------------- 00036 enum BufOpts 00037 { 00038 BufOpt_Adopt 00039 , BufOpt_Copy 00040 , BufOpt_Reference 00041 }; 00042 00043 00044 // ----------------------------------------------------------------------- 00045 // Constructors and Destructor 00046 // ----------------------------------------------------------------------- 00047 BinMemInputStream 00048 ( 00049 const XMLByte* const initData 00050 , const XMLSize_t capacity 00051 , const BufOpts bufOpt = BufOpt_Copy 00052 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 00053 ); 00054 virtual ~BinMemInputStream(); 00055 00056 00057 // ----------------------------------------------------------------------- 00058 // Stream management methods 00059 // ----------------------------------------------------------------------- 00060 void reset(); 00061 00062 00063 // ----------------------------------------------------------------------- 00064 // Implementation of the input stream interface 00065 // ----------------------------------------------------------------------- 00066 virtual XMLFilePos curPos() const; 00067 00068 virtual XMLSize_t readBytes 00069 ( 00070 XMLByte* const toFill 00071 , const XMLSize_t maxToRead 00072 ); 00073 00074 virtual const XMLCh* getContentType() const; 00075 00076 inline XMLSize_t getSize() const; 00077 00078 private : 00079 // ----------------------------------------------------------------------- 00080 // Unimplemented constructors and operators 00081 // ----------------------------------------------------------------------- 00082 BinMemInputStream(const BinMemInputStream&); 00083 BinMemInputStream& operator=(const BinMemInputStream&); 00084 // ----------------------------------------------------------------------- 00085 // Private data members 00086 // 00087 // fBuffer 00088 // The buffer of bytes that we are streaming. 00089 // 00090 // fBufOpt 00091 // Indicates the ownership status of the buffer. The caller can have 00092 // us adopt it (we delete it), reference it, or just make our own 00093 // copy of it. 00094 // 00095 // fCapacity 00096 // The size of the buffer being streamed. 00097 // 00098 // fCurIndex 00099 // The current index where the next byte will be read from. When it 00100 // hits fCapacity, we are done. 00101 // ----------------------------------------------------------------------- 00102 const XMLByte* fBuffer; 00103 BufOpts fBufOpt; 00104 XMLSize_t fCapacity; 00105 XMLSize_t fCurIndex; 00106 MemoryManager* fMemoryManager; 00107 }; 00108 00109 00110 // --------------------------------------------------------------------------- 00111 // BinMemInputStream: Stream management methods 00112 // --------------------------------------------------------------------------- 00113 inline void BinMemInputStream::reset() 00114 { 00115 fCurIndex = 0; 00116 } 00117 00118 00119 // --------------------------------------------------------------------------- 00120 // BinMemInputStream: Implementation of the input stream interface 00121 // --------------------------------------------------------------------------- 00122 inline XMLFilePos BinMemInputStream::curPos() const 00123 { 00124 return fCurIndex; 00125 } 00126 00127 inline XMLSize_t BinMemInputStream::getSize() const 00128 { 00129 return fCapacity; 00130 } 00131 00132 XERCES_CPP_NAMESPACE_END 00133 00134 #endif