Oracle Coherence for C++ API
Release 3.7.1.0
E22845-01
00001 /* 00002 * AbstractOctetArrayReadBuffer.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_OCTET_ARRAY_READ_BUFFER_HPP 00017 #define COH_ABSTRACT_OCTET_ARRAY_READ_BUFFER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/AbstractReadBuffer.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 * The AbstractOctetArrayReadBuffer abstract class is intended to serve as 00036 * a base class for the following: 00037 * <ol> 00038 * <li>the pre-existing Binary class</li> 00039 * <li>a new byte[] based class that does not attempt to add the immutability 00040 * aspect provided by the Binary class</li> 00041 * </ol> 00042 * 00043 * This implementation is not intended to be thread safe. 00044 * 00045 * @author phf 2011.03.15 00046 * 00047 * @since Coherence 3.7.1 00048 */ 00049 class COH_EXPORT AbstractOctetArrayReadBuffer 00050 : public abstract_spec<AbstractOctetArrayReadBuffer, 00051 extends<AbstractReadBuffer> > 00052 { 00053 // ----- constants ------------------------------------------------------ 00054 00055 public: 00056 /** 00057 * The largest possible value of type size32_t. 00058 */ 00059 static const size32_t npos = size32_t(-1); 00060 00061 00062 // ----- handle definitions (needed for nested classes) ----------------- 00063 00064 public: 00065 typedef this_spec::Handle Handle; 00066 typedef this_spec::View View; 00067 typedef this_spec::Holder Holder; 00068 00069 /** 00070 * Binary View definition. 00071 */ 00072 typedef TypedHandle<const coherence::util::Binary> BinaryView; 00073 00074 00075 // ----- constructors --------------------------------------------------- 00076 00077 protected: 00078 /** 00079 * Default constructor; intended for deserialization use by 00080 * subclasses. 00081 * 00082 * Note that this default constructor leaves the buffer in an invalid 00083 * state. 00084 */ 00085 AbstractOctetArrayReadBuffer(); 00086 00087 /** 00088 * Construct an AbstractOctetArrayReadBuffer on a portion of an octet 00089 * Array. 00090 * 00091 * @param vab an Array of octets 00092 * @param of an offset into the octet array 00093 * @param cb the number of octets to utilize or npos for 00094 * (vab->length - of) 00095 * 00096 * @throws IndexOutOfBoundsException if <code>of + cb</code> is 00097 * larger than <code>vab->length</code> 00098 * @throws NullPointerException if <code>vab</code> is 00099 * <code>NULL</code> 00100 */ 00101 AbstractOctetArrayReadBuffer(Array<octet_t>::View vab, size32_t of = 0, 00102 size32_t cb = npos); 00103 00104 00105 // ----- ReadBuffer interface ------------------------------------------- 00106 00107 public: 00108 /** 00109 * {@inheritDoc} 00110 */ 00111 virtual size32_t length() const; 00112 00113 /** 00114 * {@inheritDoc} 00115 */ 00116 virtual octet_t read(size32_t of) const; 00117 00118 /** 00119 * {@inheritDoc} 00120 */ 00121 virtual void read(size32_t ofBegin, size32_t ofEnd, 00122 Array<octet_t>::Handle habDest, size32_t ofDest) const; 00123 00124 /** 00125 * {@inheritDoc} 00126 */ 00127 virtual BinaryView toBinary() const; 00128 00129 /** 00130 * {@inheritDoc} 00131 */ 00132 virtual BinaryView toBinary(size32_t of, size32_t cb) const; 00133 00134 /** 00135 * {@inheritDoc} 00136 */ 00137 virtual Array<octet_t>::View toOctetArray(size32_t of, size32_t cb) const; 00138 00139 /** 00140 * {@inheritDoc} 00141 */ 00142 using AbstractReadBuffer::toOctetArray; 00143 00144 00145 // ----- Object interface ----------------------------------------------- 00146 00147 public: 00148 /** 00149 * {@inheritDoc} 00150 */ 00151 virtual bool equals(Object::View v) const; 00152 00153 00154 // ----- factory methods ------------------------------------------------ 00155 00156 protected: 00157 /** 00158 * {@inheritDoc} 00159 */ 00160 virtual BufferInput::Handle instantiateBufferInput() const; 00161 00162 00163 // ----- internal methods ----------------------------------------------- 00164 00165 protected: 00166 /** 00167 * Reset the portion of the octet array the ReadBuffer operates upon. 00168 * 00169 * @param of an offset into the octet array 00170 * @param cb the number of octets to utilize 00171 * 00172 * @throws IndexOutOfBoundsException if <code>of + cb</code> is 00173 * larger than the buffer's length 00174 */ 00175 virtual void resetRange(size32_t of, size32_t cb); 00176 00177 00178 // ----- OctetArrayBufferInput inner class ------------------------------ 00179 00180 public: 00181 /** 00182 * This is an implementation of the BufferInput interface on top of an 00183 * octet array. 00184 * 00185 * @author jh 2008.01.03 00186 * @author phf 2011.03.22 00187 */ 00188 class COH_EXPORT OctetArrayBufferInput 00189 : public class_spec<OctetArrayBufferInput, 00190 extends<AbstractBufferInput> > 00191 { 00192 friend class factory<OctetArrayBufferInput>; 00193 00194 // ----- constructors --------------------------------------- 00195 00196 protected: 00197 /** 00198 * Create a new OctetArrayBufferInput instance that 00199 * delegates to the given AbstractOctetArrayReadBuffer. 00200 * 00201 * @param vBuf the delegate ReadBuffer 00202 */ 00203 OctetArrayBufferInput(AbstractOctetArrayReadBuffer::View vBuf); 00204 00205 // ----- BufferInput interface ------------------------------ 00206 00207 public: 00208 /** 00209 * {@inheritDoc} 00210 */ 00211 using AbstractBufferInput::read; 00212 00213 /** 00214 * {@inheritDoc} 00215 */ 00216 virtual octet_t read(); 00217 00218 /** 00219 * {@inheritDoc} 00220 */ 00221 virtual void read(Array<octet_t>::Handle hab, size32_t of, 00222 size32_t cb); 00223 00224 /** 00225 * {@inheritDoc} 00226 */ 00227 virtual char16_t readChar16(); 00228 00229 /** 00230 * {@inheritDoc} 00231 */ 00232 virtual int16_t readInt16(); 00233 00234 /** 00235 * {@inheritDoc} 00236 */ 00237 virtual int32_t readInt32(); 00238 00239 /** 00240 * {@inheritDoc} 00241 */ 00242 virtual int64_t readInt64(); 00243 00244 /** 00245 * {@inheritDoc} 00246 */ 00247 virtual float32_t readFloat32(); 00248 00249 /** 00250 * {@inheritDoc} 00251 */ 00252 virtual float64_t readFloat64(); 00253 00254 // ----- internal methods ----------------------------------- 00255 00256 protected: 00257 /** 00258 * {@inheritDoc} 00259 */ 00260 virtual String::View convertUTF(size32_t of, size32_t cb) const; 00261 }; 00262 00263 00264 // ----- data members --------------------------------------------------- 00265 00266 protected: 00267 /** 00268 * The octet array that holds the binary data. 00269 * This value should not be changed. 00270 */ 00271 FinalView<Array<octet_t> > m_vab; 00272 00273 /** 00274 * Offset into the octet array at which the binary data is located. 00275 * This value should not be changed. 00276 */ 00277 size32_t m_of; 00278 00279 /** 00280 * Number of octets in the octet array that belong to this ReadBuffer 00281 * object. 00282 * This value should not be changed. 00283 */ 00284 size32_t m_cb; 00285 }; 00286 00287 COH_CLOSE_NAMESPACE2 00288 00289 #endif // COH_ABSTRACT_OCTET_ARRAY_READ_BUFFER_HPP