|
||||
File indexing completed on 2025-01-18 10:14:52
0001 /* 0002 * Licensed to the Apache Software Foundation (ASF) under one or more 0003 * contributor license agreements. See the NOTICE file distributed with 0004 * this work for additional information regarding copyright ownership. 0005 * The ASF licenses this file to You under the Apache License, Version 2.0 0006 * (the "License"); you may not use this file except in compliance with 0007 * the License. You may obtain a copy of the License at 0008 * 0009 * http://www.apache.org/licenses/LICENSE-2.0 0010 * 0011 * Unless required by applicable law or agreed to in writing, software 0012 * distributed under the License is distributed on an "AS IS" BASIS, 0013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0014 * See the License for the specific language governing permissions and 0015 * limitations under the License. 0016 */ 0017 0018 /* 0019 * $Id$ 0020 */ 0021 0022 0023 #if !defined(XERCESC_INCLUDE_GUARD_MEMBUFINPUTSOURCE_HPP) 0024 #define XERCESC_INCLUDE_GUARD_MEMBUFINPUTSOURCE_HPP 0025 0026 #include <xercesc/sax/InputSource.hpp> 0027 0028 XERCES_CPP_NAMESPACE_BEGIN 0029 0030 class BinInputStream; 0031 0032 0033 /** 0034 * This class is a derivative of the standard InputSource class. It provides 0035 * for the parser access to data stored in a memory buffer. The type of 0036 * buffer and its host specific attributes are of little concern here. The 0037 * only real requirement is that the memory be readable by the current 0038 * process. 0039 * 0040 * Note that the memory buffer size is expressed in <b>bytes</b>, not in 0041 * characters. If you pass it text data, you must account for the bytes 0042 * per character when indicating the buffer size. 0043 * 0044 * As with all InputSource derivatives. The primary objective of an input 0045 * source is to create an input stream via which the parser can spool in 0046 * data from the referenced source. In this case, there are two options 0047 * available. 0048 * 0049 * The passed buffer can be adopted or merely referenced. If it is adopted, 0050 * then it must be dynamically allocated and will be destroyed when the 0051 * input source is destroyed (no reference counting!.) Note that the 0052 * deallocation assumes that array deletion should be performed, so do 0053 * not pass a non-array-allocated buffer if asking for adoption. 0054 * If not adopted, the caller must insure that it remains valid until the 0055 * input source object is destroyed. 0056 * 0057 * The other option indicates whether each stream created for this input 0058 * source should get its own copy of the data, or whether it should just 0059 * stream the data directly from this object's copy of the data. The same 0060 * rules apply here, in that the buffer must either be copied by the 0061 * stream or it must remain valid until the stream is destroyed. 0062 */ 0063 class XMLPARSER_EXPORT MemBufInputSource : public InputSource 0064 { 0065 public : 0066 // ----------------------------------------------------------------------- 0067 // Constructors and Destructor 0068 // ----------------------------------------------------------------------- 0069 0070 /** @name Constructors */ 0071 //@{ 0072 0073 /** 0074 * A memory buffer input source is constructed from a buffer of byte 0075 * data, and the count of bytes in that buffer. The parser will parse 0076 * from this memory buffer until it has eaten the indicated number of 0077 * bytes. 0078 * 0079 * Note that the system id provided serves two purposes. Firstly it is 0080 * going to be displayed in error messages as the source of the error. 0081 * And secondly, any entities which are referred to from this entity 0082 * via relative paths/URLs will be relative to this fake system id. 0083 * 0084 * @param srcDocBytes The actual data buffer to be parsed from. 0085 * @param byteCount The count of bytes (not characters, bytes!) 0086 * in the buffer. 0087 * @param bufId A fake system id for the buffer. 0088 * @param adoptBuffer Indicates whether this object should adopt 0089 * the buffer (i.e. become responsible for 0090 * deletion) or just 0091 * use it in place. 0092 * @param manager Pointer to the memory manager to be used to 0093 * allocate objects. 0094 */ 0095 MemBufInputSource 0096 ( 0097 const XMLByte* const srcDocBytes 0098 , const XMLSize_t byteCount 0099 , const XMLCh* const bufId 0100 , const bool adoptBuffer = false 0101 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0102 ); 0103 0104 /** 0105 * This constructor is identical to the previous one, except that it takes 0106 * the fake system id in local code page form and transcodes it internally. 0107 */ 0108 MemBufInputSource 0109 ( 0110 const XMLByte* const srcDocBytes 0111 , const XMLSize_t byteCount 0112 , const char* const bufId 0113 , const bool adoptBuffer = false 0114 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0115 ); 0116 //@} 0117 0118 /** @name Destructor */ 0119 //@{ 0120 /** 0121 * If the buffer was adopted, the copy made during construction is deleted 0122 * at this point. 0123 */ 0124 ~MemBufInputSource(); 0125 //@} 0126 0127 0128 // ----------------------------------------------------------------------- 0129 // Virtual input source interface 0130 // ----------------------------------------------------------------------- 0131 0132 /** @name Virtual methods */ 0133 //@{ 0134 0135 /** 0136 * This method will return a binary input stream derivative that will 0137 * parse from the memory buffer. If setCopyBufToStream() has been set, 0138 * then the stream will make its own copy. Otherwise, it will use the 0139 * buffer as is (in which case it must remain valid until the stream 0140 * is no longer in use, i.e. the parse completes.) 0141 * 0142 * @return A dynamically allocated binary input stream derivative that 0143 * can parse from the memory buffer. 0144 */ 0145 BinInputStream* makeStream() const; 0146 0147 //@} 0148 0149 0150 // ----------------------------------------------------------------------- 0151 // Setter methods 0152 // ----------------------------------------------------------------------- 0153 0154 /** @name Setter methods */ 0155 0156 //@{ 0157 0158 /** 0159 * By default, for safety's sake, each newly created stream from this 0160 * input source will make its own copy of the buffer to stream from. This 0161 * avoids having to deal with aliasing of the buffer for simple work. But, 0162 * for higher performance applications or for large buffers, this is 0163 * obviously not optimal. 0164 * 0165 * In such cases, you can call this method to turn off that default 0166 * action. Once turned off, the streams will just get a pointer to the 0167 * buffer and parse directly from that. In this case, you must insure that 0168 * the buffer remains valid for as long as any parse events are still 0169 * using it. 0170 * 0171 * @param newState The new boolean flag state to set. 0172 */ 0173 void setCopyBufToStream(const bool newState); 0174 0175 /** 0176 * This methods allows the MemBufInputSource to be used for more than 0177 * one input source, instead of destructing/constructing another 0178 * MemBufInputSource. 0179 * 0180 * @param srcDocBytes The actual data buffer to be parsed from. 0181 * @param byteCount The count of bytes (not characters, bytes!) 0182 * in the buffer. 0183 */ 0184 void resetMemBufInputSource(const XMLByte* const srcDocBytes 0185 , const XMLSize_t byteCount); 0186 //@} 0187 0188 0189 private : 0190 // ----------------------------------------------------------------------- 0191 // Unimplemented constructors and operators 0192 // ----------------------------------------------------------------------- 0193 MemBufInputSource(const MemBufInputSource&); 0194 MemBufInputSource& operator=(const MemBufInputSource&); 0195 0196 // ----------------------------------------------------------------------- 0197 // Private data members 0198 // 0199 // fAdopted 0200 // Indicates whether the buffer is adopted or not. If so, then it 0201 // is destroyed when the input source is destroyed. 0202 // 0203 // fByteCount 0204 // The size of the source document. 0205 // 0206 // fCopyBufToStream 0207 // This defaults to true (the safe option), which causes it to 0208 // give a copy of the buffer to any streams it creates. If you set 0209 // it to false, it will allow the streams to just reference the 0210 // buffer (in which case this input source must stay alive as long 0211 // as the buffer is in use by the stream.) 0212 // 0213 // fSrcBytes 0214 // The source memory buffer that is being spooled from. Whether it 0215 // belongs to the this input source or not is controlled by the 0216 // fAdopted flag. 0217 // ----------------------------------------------------------------------- 0218 bool fAdopted; 0219 XMLSize_t fByteCount; 0220 bool fCopyBufToStream; 0221 const XMLByte* fSrcBytes; 0222 }; 0223 0224 0225 inline void MemBufInputSource::setCopyBufToStream(const bool newState) 0226 { 0227 fCopyBufToStream = newState; 0228 } 0229 0230 XERCES_CPP_NAMESPACE_END 0231 0232 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |