Oracle Coherence for C++ API
Release 3.7.1.0
E22845-01
00001 /* 00002 * AbstractReadBuffer.hpp 00003 * 00004 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_ABSTRACT_READ_BUFFER_HPP 00017 #define COH_ABSTRACT_READ_BUFFER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/ReadBuffer.hpp" 00022 00023 // ----- forward declarations ----------------------------------------------- 00024 00025 COH_OPEN_NAMESPACE2(coherence,util) 00026 00027 class Binary; 00028 00029 COH_CLOSE_NAMESPACE2 00030 00031 COH_OPEN_NAMESPACE2(coherence,io) 00032 00033 00034 /** 00035 * Abstract base implementation of the ReadBuffer interface. 00036 * 00037 * @author jh 2007.12.31 00038 */ 00039 class COH_EXPORT AbstractReadBuffer 00040 : public abstract_spec<AbstractReadBuffer, 00041 extends<Object>, 00042 implements<ReadBuffer> > 00043 { 00044 // ----- handle definitions (needed for nested classes) ----------------- 00045 00046 public: 00047 typedef this_spec::Handle Handle; 00048 typedef this_spec::View View; 00049 typedef this_spec::Holder Holder; 00050 00051 /** 00052 * Binary View definition. 00053 */ 00054 typedef TypedHandle<const coherence::util::Binary> BinaryView; 00055 00056 /** 00057 * Binary Handle definition. 00058 */ 00059 typedef TypedHandle<coherence::util::Binary> BinaryHandle; 00060 00061 00062 // ----- ReadBuffer interface ------------------------------------------- 00063 00064 public: 00065 /** 00066 * {@inheritDoc} 00067 */ 00068 virtual BufferInput::Handle getBufferInput() const; 00069 00070 /** 00071 * {@inheritDoc} 00072 */ 00073 virtual ReadBuffer::View getReadBuffer(size32_t of, size32_t cb) const; 00074 00075 /** 00076 * {@inheritDoc} 00077 */ 00078 virtual BinaryView toBinary() const; 00079 00080 /** 00081 * {@inheritDoc} 00082 */ 00083 virtual BinaryView toBinary(size32_t of, size32_t cb) const; 00084 00085 /** 00086 * {@inheritDoc} 00087 */ 00088 virtual Array<octet_t>::View toOctetArray() const; 00089 00090 /** 00091 * {@inheritDoc} 00092 */ 00093 virtual Array<octet_t>::View toOctetArray(size32_t of, size32_t cb) const; 00094 00095 00096 // ----- Object interface ----------------------------------------------- 00097 00098 public: 00099 /** 00100 * {@inheritDoc} 00101 */ 00102 virtual bool equals(Object::View v) const; 00103 00104 00105 // ----- internal methods ----------------------------------------------- 00106 00107 protected: 00108 /** 00109 * Factory method: Instantiate a ReadBuffer for a portion of this 00110 * ReadBuffer. 00111 * 00112 * @param of the beginning index, inclusive 00113 * @param cb the number of bytes to include in the resulting 00114 * ReadBuffer 00115 * 00116 * @return a ReadBuffer that represents a portion of this ReadBuffer 00117 */ 00118 virtual ReadBuffer::View instantiateReadBuffer(size32_t of, 00119 size32_t cb) const = 0; 00120 00121 /** 00122 * Factory method: Instantiate a BufferInput object to read data from 00123 * the ReadBuffer. 00124 * 00125 * @return a new BufferInput reading from this ReadBuffer 00126 */ 00127 virtual BufferInput::Handle instantiateBufferInput() const; 00128 00129 /** 00130 * Check if the specified read is within bounds. 00131 * 00132 * @param of the absolute offset of the read operation 00133 * @param cb the length in bytes of the read operation 00134 * 00135 * @throws IndexOutOfBoundsException if the specified read is not 00136 * within bounds 00137 */ 00138 virtual void checkBounds(size32_t of, size32_t cb) const; 00139 00140 00141 // ----- AbstractBufferInput inner class -------------------------------- 00142 00143 public: 00144 /** 00145 * This is an implementation of the BufferInput interface that 00146 * delegates its work back to its ReadBuffer. 00147 * 00148 * @author jh 2007.12.31 00149 */ 00150 class COH_EXPORT AbstractBufferInput 00151 : public class_spec<AbstractBufferInput, 00152 extends<Object>, 00153 implements<BufferInput> > 00154 { 00155 friend class factory<AbstractBufferInput>; 00156 00157 // ----- constructors --------------------------------------- 00158 00159 protected: 00160 /** 00161 * Create a new AbstractBufferInput instance that delegates 00162 * to the given AbstractReadBuffer. 00163 * 00164 * @param vBuf the delegate AbstractReadBuffer 00165 */ 00166 AbstractBufferInput(AbstractReadBuffer::View vBuf); 00167 00168 00169 // ----- BufferInput interface ------------------------------ 00170 00171 public: 00172 /** 00173 * {@inheritDoc} 00174 */ 00175 virtual ReadBuffer::View getBuffer() const; 00176 00177 /** 00178 * {@inheritDoc} 00179 */ 00180 virtual size32_t getOffset() const; 00181 00182 /** 00183 * {@inheritDoc} 00184 */ 00185 virtual void setOffset(size32_t of); 00186 00187 /** 00188 * {@inheritDoc} 00189 */ 00190 virtual size32_t available() const; 00191 00192 /** 00193 * {@inheritDoc} 00194 */ 00195 virtual void skip(size32_t cb); 00196 00197 /** 00198 * {@inheritDoc} 00199 */ 00200 virtual octet_t read(); 00201 00202 /** 00203 * {@inheritDoc} 00204 */ 00205 virtual void read(Array<octet_t>::Handle hab); 00206 00207 /** 00208 * {@inheritDoc} 00209 */ 00210 virtual void read(Array<octet_t>::Handle hab, size32_t of, 00211 size32_t cb); 00212 00213 /** 00214 * {@inheritDoc} 00215 */ 00216 virtual ReadBuffer::View readBuffer(size32_t cb); 00217 00218 /** 00219 * {@inheritDoc} 00220 */ 00221 virtual bool readBoolean(); 00222 00223 /** 00224 * {@inheritDoc} 00225 */ 00226 virtual char16_t readChar16(); 00227 00228 /** 00229 * {@inheritDoc} 00230 */ 00231 virtual String::View readString(); 00232 00233 /** 00234 * {@inheritDoc} 00235 */ 00236 virtual int16_t readInt16(); 00237 00238 /** 00239 * {@inheritDoc} 00240 */ 00241 virtual int32_t readInt32(); 00242 00243 /** 00244 * {@inheritDoc} 00245 */ 00246 virtual int64_t readInt64(); 00247 00248 /** 00249 * {@inheritDoc} 00250 */ 00251 virtual float32_t readFloat32(); 00252 00253 /** 00254 * {@inheritDoc} 00255 */ 00256 virtual float64_t readFloat64(); 00257 00258 // ----- internal methods ----------------------------------- 00259 00260 protected: 00261 /** 00262 * Update the internal stream offset. 00263 * 00264 * @param of the new offset 00265 */ 00266 virtual void setOffsetInternal(size32_t of); 00267 00268 /** 00269 * Reads the specified-length UTF-8 data and converts it to a 00270 * String value. 00271 * 00272 * @param cb the number of bytes that the UTF data takes up 00273 * in the stream 00274 * 00275 * @return a String value 00276 * 00277 * @throws UTFDataFormatException if the bytes that were 00278 * read were not a valid UTF-8 encoded string 00279 * @throws EOFException if the value could not be read because 00280 * no more data remains to be read 00281 * @throws IOException if an I/O error occurs 00282 */ 00283 virtual String::View readUTF(size32_t cb); 00284 00285 /** 00286 * Convert a UTF-8 encoded section of the binary stream into a 00287 * String. 00288 * 00289 * @param of the offset within the stream 00290 * @param cb the length in bytes within the stream 00291 * 00292 * @return the String value 00293 * 00294 * @throws IOException on convertion error 00295 */ 00296 virtual String::View convertUTF(size32_t of, size32_t cb) const; 00297 00298 // ----- data members --------------------------------------- 00299 00300 protected: 00301 /** 00302 * The delegate AbstractReadBuffer. 00303 */ 00304 FinalView<AbstractReadBuffer> m_vBuf; 00305 00306 /** 00307 * Current stream offset into the delegate AbstractReadBuffer. 00308 */ 00309 size32_t m_of; 00310 }; 00311 00312 00313 // ----- constants ------------------------------------------------------ 00314 00315 public: 00316 /** 00317 * An empty octet array (by definition immutable). 00318 */ 00319 static Array<octet_t>::Handle getEmptyOctetArray(); 00320 00321 /** 00322 * An empty Binary object. 00323 * 00324 * @since Coherence 3.7.1 00325 */ 00326 static BinaryHandle getEmptyBinary(); 00327 00328 /** 00329 * A zero-length ReadBuffer (by definition immutable). 00330 */ 00331 static ReadBuffer::Handle getEmptyReadBuffer(); 00332 }; 00333 00334 COH_CLOSE_NAMESPACE2 00335 00336 #endif // COH_ABSTRACT_READ_BUFFER_HPP