coherence/io/OctetArrayReadBuffer.hpp

00001 /*
00002 * OctetArrayReadBuffer.hpp
00003 *
00004 * Copyright (c) 2000, 2009, 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_OCTET_ARRAY_READ_BUFFER_HPP
00017 #define COH_OCTET_ARRAY_READ_BUFFER_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/AbstractReadBuffer.hpp"
00022 
00023 COH_OPEN_NAMESPACE2(coherence,io)
00024 
00025 class OctetArrayWriteBuffer;
00026 
00027 
00028 /**
00029 * A ReadBuffer on top of an octet array.
00030 *
00031 * @author jh  2008.01.03
00032 */
00033 class COH_EXPORT OctetArrayReadBuffer
00034     : public cloneable_spec<OctetArrayReadBuffer,
00035         extends<AbstractReadBuffer> >
00036     {
00037     friend class factory<OctetArrayReadBuffer>;
00038 
00039     // ----- handle definitions (needed for nested classes) -----------------
00040 
00041     public:
00042         typedef this_spec::Handle Handle;
00043         typedef this_spec::View   View;
00044         typedef this_spec::Holder Holder;
00045 
00046 
00047     // ----- constructors ---------------------------------------------------
00048 
00049     protected:
00050         /**
00051         * Construct an OctetArrayReadBuffer object from a portion of an octet
00052         * array.
00053         *
00054         * @param vab    an array of octets
00055         * @param of     the offset into the octet array
00056         * @param cb     the number of octets to extract
00057         * @param fCopy  true to make a copy of the passed array
00058         */
00059         OctetArrayReadBuffer(Array<octet_t>::View vab, size32_t of,
00060                 size32_t cb, bool fCopy = false);
00061 
00062         /**
00063         * Copy constructor.
00064         */
00065         OctetArrayReadBuffer(const OctetArrayReadBuffer& that);
00066 
00067 
00068     // ----- ReadBuffer interface -------------------------------------------
00069 
00070     public:
00071         /**
00072         * {@inheritDoc}
00073         */
00074         virtual size32_t length() const;
00075 
00076         /**
00077         * {@inheritDoc}
00078         */
00079         virtual octet_t read(size32_t of) const;
00080 
00081         /**
00082         * {@inheritDoc}
00083         */
00084         virtual void read(size32_t ofBegin, size32_t ofEnd,
00085                 Array<octet_t>::Handle habDest, size32_t ofDest) const;
00086 
00087         /**
00088         * {@inheritDoc}
00089         */
00090         virtual Array<octet_t>::View toOctetArray(size32_t of, size32_t cb) const;
00091 
00092         /**
00093         * {@inheritDoc}
00094         */
00095         using AbstractReadBuffer::toOctetArray;
00096 
00097 
00098     // ----- Object interface -----------------------------------------------
00099 
00100     public:
00101         /**
00102         * {@inheritDoc}
00103         */
00104         virtual void toStream(std::ostream& out) const;
00105 
00106 
00107     // ----- internal methods -----------------------------------------------
00108 
00109     protected:
00110         /**
00111         * Allow the length to be modified. This method is provided for use by
00112         * OctetArrayWriteBuffer only, and only for read buffers that it owns.
00113         *
00114         * @param cb  the new length
00115         */
00116         virtual void updateLength(size32_t cb);
00117 
00118         /**
00119         * {@inheritDoc}
00120         */
00121         virtual ReadBuffer::View instantiateReadBuffer(size32_t of,
00122                 size32_t cb) const;
00123 
00124         /**
00125         * {@inheritDoc}
00126         */
00127         virtual BufferInput::Handle instantiateBufferInput() const;
00128 
00129 
00130     // ----- OctetArrayBufferInput inner class ------------------------------
00131 
00132     public:
00133         /**
00134         * This is an implementation of the BufferInput interface on top of a
00135         * octet array.
00136         *
00137         * @author jh  2008.01.03
00138         */
00139         class COH_EXPORT OctetArrayBufferInput
00140             : public class_spec<OctetArrayBufferInput,
00141                 extends<AbstractBufferInput> >
00142             {
00143             friend class factory<OctetArrayBufferInput>;
00144 
00145             // ----- constructors ---------------------------------------
00146 
00147             protected:
00148                 /**
00149                 * Create a new OctetArrayBufferInput instance that delegates
00150                 * to the given OctetArrayReadBuffer.
00151                 *
00152                 * @param vBuf  the delegate ReadBuffer
00153                 */
00154                 OctetArrayBufferInput(OctetArrayReadBuffer::View vBuf);
00155 
00156             // ----- BufferInput interface ------------------------------
00157 
00158             public:
00159                 /**
00160                 * {@inheritDoc}
00161                 */
00162                 using AbstractBufferInput::read;
00163 
00164                 /**
00165                 * {@inheritDoc}
00166                 */
00167                 virtual octet_t read();
00168 
00169                 /**
00170                 * {@inheritDoc}
00171                 */
00172                 virtual void read(Array<octet_t>::Handle hab, size32_t of,
00173                         size32_t cb);
00174 
00175                 /**
00176                 * {@inheritDoc}
00177                 */
00178                 virtual char16_t readChar16();
00179 
00180                 /**
00181                 * {@inheritDoc}
00182                 */
00183                 virtual int16_t readInt16();
00184 
00185                 /**
00186                 * {@inheritDoc}
00187                 */
00188                 virtual int32_t readInt32();
00189 
00190                 /**
00191                 * {@inheritDoc}
00192                 */
00193                 virtual int64_t readInt64();
00194 
00195                 /**
00196                 * {@inheritDoc}
00197                 */
00198                 virtual float32_t readFloat32();
00199 
00200                 /**
00201                 * {@inheritDoc}
00202                 */
00203                 virtual float64_t readFloat64();
00204 
00205             // ----- internal methods -----------------------------------
00206 
00207             protected:
00208                 /**
00209                 * {@inheritDoc}
00210                 */
00211                 virtual String::View convertUTF(size32_t of, size32_t cb) const;
00212             };
00213 
00214 
00215     // ----- data members ---------------------------------------------------
00216 
00217     protected:
00218         /**
00219         * The octet array that holds the binary data.
00220         */
00221         FinalView<Array<octet_t> > m_vab;
00222 
00223         /**
00224         * Offset into the octet array at which the binary data is located.
00225         */
00226         size32_t m_of;
00227 
00228         /**
00229         * Number of octets in the octet array that belong to this ReadBuffer
00230         * object.
00231         */
00232         size32_t m_cb;
00233 
00234 
00235     // ----- friends --------------------------------------------------------
00236 
00237     friend class OctetArrayWriteBuffer;
00238     };
00239 
00240 COH_CLOSE_NAMESPACE2
00241 
00242 #endif // COH_OCTET_ARRAY_READ_BUFFER_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.