Oracle Coherence for C++ API
Release 3.6.0.0
E15728-01

- Main Page
- Namespaces
- Classes
- Files

# coherence/io/OctetArrayWriteBuffer.hpp

    00001 /*
    00002 * OctetArrayWriteBuffer.hpp
    00003 *
    00004 * Copyright (c) 2000, 2010, 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_WRITE_BUFFER_HPP
    00017 #define COH_OCTET_ARRAY_WRITE_BUFFER_HPP
    00018
    00019 #include "coherence/lang.ns"
    00020
    00021 #include "coherence/io/AbstractWriteBuffer.hpp"
    00022 #include "coherence/io/ReadBuffer.hpp"
    00023
    00024 #include <limits>
    00025
    00026 COH_OPEN_NAMESPACE2(coherence,io)
    00027
    00028
    00029 /**
    00030 * OctetArrayWriteBuffer is an implementation of WriteBuffer on an octet
    00031 * array. It is designed to support both fixed length buffers and resizable
    00032 * buffers.
    00033 *
    00034 * This implementation is explicitly not thread-safe.
    00035 *
    00036 * @author jh  2007.01.11
    00037 */
    00038 class COH_EXPORT OctetArrayWriteBuffer
    00039     : public cloneable_spec<OctetArrayWriteBuffer,
    00040         extends<AbstractWriteBuffer> >
    00041     {
    00042     friend class factory<OctetArrayWriteBuffer>;
    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     // ----- constructors ---------------------------------------------------
    00053
    00054     protected:
    00055         /**
    00056         * Construct an OctetArrayWriteBuffer on an octet array.
    00057         *
    00058         * @param hab  an octet array
    00059         *
    00060         * @throws NullPointerException if <tt>hab</tt> is NULL
    00061         */
    00062         OctetArrayWriteBuffer(Array<octet_t>::Handle hab);
    00063
    00064         /**
    00065         * Construct an OctetArrayWriteBuffer with a certain initial capacity
    00066         * and a certain maximum capacity.
    00067         *
    00068         * @param cbCap  initial capacity
    00069         * @param cbMax  maximum capacity
    00070         *
    00071         * @throws IllegalArgumentException if <tt>cbCap</tt> is greater than
    00072         *         <tt>cbMax</tt>
    00073         */
    00074         OctetArrayWriteBuffer(size32_t cbCap,
    00075                 size32_t cbMax = std::numeric_limits<size32_t>::max());
    00076
    00077         /**
    00078         * Copy constructor.
    00079         */
    00080         OctetArrayWriteBuffer(const OctetArrayWriteBuffer& that);
    00081
    00082
    00083     // ----- WriteBuffer interface ------------------------------------------
    00084
    00085     public:
    00086         /**
    00087         * {@inheritDoc}
    00088         */
    00089         virtual size32_t length() const;
    00090
    00091         /**
    00092         * {@inheritDoc}
    00093         */
    00094         virtual size32_t getCapacity() const;
    00095
    00096         /**
    00097         * {@inheritDoc}
    00098         */
    00099         virtual size32_t getMaximumCapacity() const;
    00100
    00101         /**
    00102         * {@inheritDoc}
    00103         */
    00104         virtual void write(size32_t ofDest, octet_t b);
    00105
    00106         /**
    00107         * {@inheritDoc}
    00108         */
    00109         virtual void write(size32_t ofDest, Array<octet_t>::View vabSrc,
    00110                 size32_t ofSrc, size32_t cbSrc);
    00111
    00112         /**
    00113         * {@inheritDoc}
    00114         */
    00115         virtual void write(size32_t ofDest, ReadBuffer::View vBufSrc,
    00116                 size32_t ofSrc, size32_t cbSrc);
    00117
    00118         /**
    00119         * {@inheritDoc}
    00120         */
    00121         using AbstractWriteBuffer::write;
    00122
    00123         /**
    00124         * {@inheritDoc}
    00125         */
    00126         virtual void retain(size32_t of, size32_t cb);
    00127
    00128         /**
    00129         * {@inheritDoc}
    00130         */
    00131         using AbstractWriteBuffer::retain;
    00132
    00133         /**
    00134         * {@inheritDoc}
    00135         */
    00136         virtual ReadBuffer::View getUnsafeReadBuffer() const;
    00137
    00138
    00139     // ----- internal methods -----------------------------------------------
    00140
    00141     protected:
    00142         /**
    00143         * {@inheritDoc}
    00144         */
    00145         virtual BufferOutput::Handle instantiateBufferOutput();
    00146
    00147         /**
    00148         * Validate the ranges for the passed bounds and make sure that the
    00149         * underlying array is big enough to handle them.
    00150         *
    00151         * @param of  the offset that data is about to be written to
    00152         * @param cb  the length of the data that is about to be written
    00153         */
    00154         virtual void checkBounds(size32_t of, size32_t cb);
    00155
    00156         /**
    00157         * Grow the underlying octet array to at least the specified size.
    00158         *
    00159         * @param cbCap  the required or requested capacity
    00160         */
    00161         virtual void grow(size32_t cbCap);
    00162
    00163         /**
    00164         * Update the length if the passed length is greater than the current
    00165         * buffer length.
    00166         *
    00167         * @param cb  the count of the last octet written (or the index of
    00168         *            the next octet to write)
    00169         */
    00170         virtual void updateLength(size32_t cb);
    00171
    00172
    00173     // ----- OctetArrayBufferOutput inner class -----------------------------
    00174
    00175     public:
    00176         /**
    00177         * OctetArrayBufferOutput is an implementation of BufferOutput
    00178         * optimized for writing to the buffer's underlying octet array. A
    00179         * BufferOutput implementation that delegates to a BufferOutput
    00180         * implementation, except that its offset range is shifted and
    00181         * limited.
    00182         *
    00183         * @author jh  2008.01.11
    00184         */
    00185         class COH_EXPORT OctetArrayBufferOutput
    00186             : public class_spec<OctetArrayBufferOutput,
    00187                 extends<AbstractBufferOutput> >
    00188             {
    00189             friend class factory<OctetArrayBufferOutput>;
    00190
    00191             // ----- constructors ---------------------------------------
    00192
    00193             protected:
    00194                 /**
    00195                 * Create a new OctetArrayBufferOutput instance that delegates
    00196                 * to the given OctetArrayWriteBuffer.
    00197                 *
    00198                 * @param hBuf  the delegate WriteBuffer
    00199                 */
    00200                 OctetArrayBufferOutput(OctetArrayWriteBuffer::Handle hBuf);
    00201
    00202             // ----- BufferOutput interface -----------------------------
    00203
    00204             public:
    00205                 /**
    00206                 * {@inheritDoc}
    00207                 */
    00208                 virtual void writeChar16(char16_t ch);
    00209
    00210                 /**
    00211                 * {@inheritDoc}
    00212                 */
    00213                 virtual void writeString(String::View vs);
    00214
    00215                 /**
    00216                 * {@inheritDoc}
    00217                 */
    00218                 virtual void writeInt16(int16_t n);
    00219
    00220                 /**
    00221                 * {@inheritDoc}
    00222                 */
    00223                 virtual void writeInt32(int32_t n);
    00224
    00225                 /**
    00226                 * {@inheritDoc}
    00227                 */
    00228                 virtual void writeInt64(int64_t n);
    00229
    00230                 /**
    00231                 * {@inheritDoc}
    00232                 */
    00233                 virtual void writeFloat32(float32_t fl);
    00234
    00235                 /**
    00236                 * {@inheritDoc}
    00237                 */
    00238                 virtual void writeFloat64(float64_t dfl);
    00239
    00240             // ----- internal methods -----------------------------------
    00241
    00242             protected:
    00243                 /**
    00244                 * Move the offset within the stream forward.
    00245                 *
    00246                 * @param cb  the number of octets to advance the offset
    00247                 */
    00248                 virtual void moveOffset(size32_t cb);
    00249             };
    00250
    00251
    00252     // ----- data members ---------------------------------------------------
    00253
    00254     protected:
    00255         /**
    00256         * The octet array that holds the binary data.
    00257         */
    00258         MemberHandle<Array<octet_t> > m_hab;
    00259
    00260         /**
    00261         * Number of octets in the octet array that have been written by this
    00262         * WriteBuffer. This is the length.
    00263         */
    00264         size32_t m_cb;
    00265
    00266         /**
    00267         * Number of octets that the octet array can be grown to. This is the
    00268         * maximum capacity.
    00269         */
    00270         size32_t m_cbMax;
    00271
    00272         /**
    00273         * Cached ReadBuffer to quickly provide an answer to
    00274         * {@link #getUnsafeReadBuffer()}.
    00275         */
    00276         mutable MemberHandle<ReadBuffer> m_hBufUnsafe;
    00277     };
    00278
    00279 COH_CLOSE_NAMESPACE2
    00280
    00281 #endif // COH_OCTET_ARRAY_WRITE_BUFFER_HPP

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.