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

- Main Page
- Namespaces
- Classes
- Files

# coherence/io/DelegatingWriteBuffer.hpp

    00001 /*
    00002 * DelegatingWriteBuffer.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_DELEGATING_WRITE_BUFFER_HPP
    00017 #define COH_DELEGATING_WRITE_BUFFER_HPP
    00018
    00019 #include "coherence/lang.ns"
    00020
    00021 #include "coherence/io/AbstractWriteBuffer.hpp"
    00022 #include "coherence/io/WriteBuffer.hpp"
    00023
    00024 COH_OPEN_NAMESPACE2(coherence,io)
    00025
    00026
    00027 /**
    00028 * A DelegatingWriteBuffer is a WriteBuffer that writes through to an
    00029 * underlying (or "containing") WriteBuffer. Basically, it allows a process
    00030 * that is writing to a WriteBuffer to ask for a "protected" sub-portion of
    00031 * that WriteBuffer to hand to a second process, such that the second process
    00032 * can not affect (or even read from) the WriteBuffer outside of the portion
    00033 * that the first process explicitly designated as viewable and modifiable.
    00034 * <p>
    00035 * This implementation is explicitly not thread-safe.
    00036 *
    00037 * @author jh  2007.01.10
    00038 */
    00039 class COH_EXPORT DelegatingWriteBuffer
    00040     : public cloneable_spec<DelegatingWriteBuffer,
    00041         extends<AbstractWriteBuffer> >
    00042     {
    00043     friend class factory<DelegatingWriteBuffer>;
    00044
    00045     // ----- handle definitions (needed for nested classes) -----------------
    00046
    00047     public:
    00048         typedef this_spec::Handle Handle;
    00049         typedef this_spec::View   View;
    00050         typedef this_spec::Holder Holder;
    00051
    00052
    00053     // ----- constructors ---------------------------------------------------
    00054
    00055     protected:
    00056         /**
    00057         * Construct a DelegatingWriteBuffer that will delegate to the
    00058         * containing WriteBuffer.
    00059         *
    00060         * @param hBuf  the containing WriteBuffer
    00061         * @param of    the offset within the containing WriteBuffer that this
    00062         *              WriteBuffer is starting at
    00063         * @param cb    the maximum capacity for this WriteBuffer
    00064         */
    00065         DelegatingWriteBuffer(WriteBuffer::Handle hBuf, size32_t of,
    00066                 size32_t cb);
    00067
    00068         /**
    00069         * Copy constructor.
    00070         */
    00071         DelegatingWriteBuffer(const DelegatingWriteBuffer& that);
    00072
    00073
    00074     // ----- WriteBuffer interface ------------------------------------------
    00075
    00076     public:
    00077         /**
    00078         * {@inheritDoc}
    00079         */
    00080         virtual size32_t length() const;
    00081
    00082         /**
    00083         * {@inheritDoc}
    00084         */
    00085         virtual size32_t getCapacity() const;
    00086
    00087         /**
    00088         * {@inheritDoc}
    00089         */
    00090         virtual size32_t getMaximumCapacity() const;
    00091
    00092         /**
    00093         * {@inheritDoc}
    00094         */
    00095         virtual void write(size32_t ofDest, octet_t b);
    00096
    00097         /**
    00098         * {@inheritDoc}
    00099         */
    00100         virtual void write(size32_t ofDest, Array<octet_t>::View vabSrc,
    00101                 size32_t ofSrc, size32_t cbSrc);
    00102
    00103         /**
    00104         * {@inheritDoc}
    00105         */
    00106         virtual void write(size32_t ofDest, ReadBuffer::View vBufSrc,
    00107                 size32_t ofSrc, size32_t cbSrc);
    00108
    00109         /**
    00110         * {@inheritDoc}
    00111         */
    00112         using AbstractWriteBuffer::write;
    00113
    00114         /**
    00115         * {@inheritDoc}
    00116         */
    00117         virtual void retain(size32_t of, size32_t cb);
    00118
    00119         /**
    00120         * {@inheritDoc}
    00121         */
    00122         using AbstractWriteBuffer::retain;
    00123
    00124         /**
    00125         * {@inheritDoc}
    00126         */
    00127         virtual void clear();
    00128
    00129         /**
    00130         * {@inheritDoc}
    00131         */
    00132         virtual ReadBuffer::View getUnsafeReadBuffer() const;
    00133
    00134         /**
    00135         * {@inheritDoc}
    00136         */
    00137         virtual Array<octet_t>::View toOctetArray() const;
    00138
    00139
    00140     // ----- internal methods -----------------------------------------------
    00141
    00142     protected:
    00143         /**
    00144         * {@inheritDoc}
    00145         */
    00146         virtual BufferOutput::Handle instantiateBufferOutput();
    00147
    00148         /**
    00149         * Test an offset and length of data to write to see if it can be
    00150         * written to this buffer.
    00151         *
    00152         * @param of  offset to write data at
    00153         * @param cb  length in octets of data
    00154         */
    00155         virtual void checkBounds(size32_t of, size32_t cb) const;
    00156
    00157         /**
    00158         * Update the length if the passed length is greater than the current
    00159         * buffer length.
    00160         *
    00161         * @param cb  the possible new length
    00162         */
    00163         virtual void updateLength(size32_t cb);
    00164
    00165
    00166     // ----- DelegatingBufferOutput inner class -----------------------------
    00167
    00168     public:
    00169         /**
    00170         * A BufferOutput implementation that delegates to a BufferOutput
    00171         * implementation, except that its offset range is shifted and
    00172         * limited.
    00173         *
    00174         * @author jh  2008.01.10
    00175         */
    00176         class COH_EXPORT DelegatingBufferOutput
    00177             : public class_spec<DelegatingBufferOutput,
    00178                 extends<AbstractBufferOutput> >
    00179             {
    00180             friend class factory<DelegatingBufferOutput>;
    00181
    00182             // ----- constructors ---------------------------------------
    00183
    00184             protected:
    00185                 /**
    00186                 * Create a new DelegatingBufferOutput instance that delegates
    00187                 * to the BufferOutput of the underlying WriteBuffer of the
    00188                 * given DelegatingWriteBuffer.
    00189                 *
    00190                 * @param hBuf  the delegate WriteBuffer
    00191                 */
    00192                 DelegatingBufferOutput(DelegatingWriteBuffer::Handle hBuf);
    00193
    00194             // ----- BufferOutput interface -----------------------------
    00195
    00196             public:
    00197                 /**
    00198                 * {@inheritDoc}
    00199                 */
    00200                 using AbstractBufferOutput::write;
    00201
    00202                 /**
    00203                 * {@inheritDoc}
    00204                 */
    00205                 virtual void write(octet_t b);
    00206
    00207                 /**
    00208                 * {@inheritDoc}
    00209                 */
    00210                 virtual void write(Array<octet_t>::View vab, size32_t of,
    00211                     size32_t cb);
    00212
    00213                 /**
    00214                 * {@inheritDoc}
    00215                 */
    00216                 virtual void writeBuffer(ReadBuffer::View vBuf);
    00217
    00218                 /**
    00219                 * {@inheritDoc}
    00220                 */
    00221                 virtual void writeBuffer(ReadBuffer::View vBuf, size32_t of,
    00222                         size32_t cb);
    00223
    00224                 /**
    00225                 * {@inheritDoc}
    00226                 */
    00227                 virtual void writeBoolean(bool f);
    00228
    00229                 /**
    00230                 * {@inheritDoc}
    00231                 */
    00232                 virtual void writeChar16(char16_t ch);
    00233
    00234                 /**
    00235                 * {@inheritDoc}
    00236                 */
    00237                 virtual void writeFloat32(float32_t fl);
    00238
    00239                 /**
    00240                 * {@inheritDoc}
    00241                 */
    00242                 virtual void writeFloat64(float64_t dfl);
    00243
    00244             // ----- internal methods -----------------------------------
    00245
    00246             protected:
    00247                 /**
    00248                 * Move the offset within the stream forward.
    00249                 *
    00250                 * @param cb  the number of octets to advance the offset
    00251                 */
    00252                 virtual void moveOffset(size32_t cb);
    00253
    00254             // ----- data members ---------------------------------------
    00255
    00256             protected:
    00257                 /**
    00258                 * The BufferOutput to delegate to.
    00259                 */
    00260                 MemberHandle<BufferOutput> m_hOut;
    00261             };
    00262
    00263
    00264     // ----- data members ---------------------------------------------------
    00265
    00266     protected:
    00267         /**
    00268         * The WriteBuffer to delegate to; the "containing" WriteBuffer.
    00269         */
    00270         MemberHandle<WriteBuffer> m_hBuf;
    00271
    00272         /**
    00273         * Offset into the containing WriteBuffer where this WriteBuffer
    00274         * starts.
    00275         */
    00276         size32_t m_ofStart;
    00277
    00278         /**
    00279         * Length in octets of this WriteBuffer.
    00280         */
    00281         size32_t m_cb;
    00282
    00283         /**
    00284         * Maximum number of octets in this WriteBuffer.
    00285         */
    00286         size32_t m_cbMax;
    00287     };
    00288
    00289 COH_CLOSE_NAMESPACE2
    00290
    00291 #endif // COH_DELEGATING_WRITE_BUFFER_HPP

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