coherence/io/AbstractWriteBuffer.hpp

00001 /*
00002 * AbstractWriteBuffer.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_ABSTRACT_WRITE_BUFFER_HPP
00017 #define COH_ABSTRACT_WRITE_BUFFER_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/ReadBuffer.hpp"
00022 #include "coherence/io/WriteBuffer.hpp"
00023 
00024 COH_OPEN_NAMESPACE2(coherence,io)
00025 
00026 
00027 /**
00028 * The AbstractWriteBuffer is a partial implementation of the WriteBuffer
00029 * interface intended to be used as a base class for easily creating concrete
00030 * WriteBuffer implementations.
00031 * <p>
00032 * This implementation is explicitly not thread-safe.
00033 *
00034 * @author jh  2008.01.08
00035 */
00036 class COH_EXPORT AbstractWriteBuffer
00037     : public abstract_spec<AbstractWriteBuffer,
00038         extends<Object>,
00039         implements<WriteBuffer> >
00040     {
00041     // ----- handle definitions (needed for nested classes) -----------------
00042 
00043     public:
00044         typedef this_spec::Handle Handle;
00045         typedef this_spec::View   View;
00046         typedef this_spec::Holder Holder;
00047 
00048 
00049     // ----- constructors ---------------------------------------------------
00050 
00051     protected:
00052         /**
00053         * @internal
00054         */
00055         AbstractWriteBuffer();
00056 
00057         /**
00058         * @internal
00059         */
00060         AbstractWriteBuffer(const AbstractWriteBuffer& that);
00061 
00062 
00063     // ----- WriteBuffer interface ------------------------------------------
00064 
00065     public:
00066         /**
00067         * {@inheritDoc}
00068         */
00069         virtual size32_t getMaximumCapacity() const;
00070 
00071         /**
00072         * {@inheritDoc}
00073         */
00074         virtual void write(size32_t ofDest, Array<octet_t>::View vabSrc);
00075 
00076         /**
00077         * {@inheritDoc}
00078         */
00079         virtual void write(size32_t ofDest, ReadBuffer::View vBufSrc);
00080 
00081         /**
00082         * {@inheritDoc}
00083         */
00084         virtual void write(size32_t ofDest, ReadBuffer::View vBufSrc,
00085                 size32_t ofSrc, size32_t cbSrc);
00086 
00087         /**
00088         * {@inheritDoc}
00089         */
00090         using WriteBuffer::write;
00091 
00092         /**
00093         * {@inheritDoc}
00094         */
00095         virtual void retain(size32_t of);
00096 
00097         /**
00098         * {@inheritDoc}
00099         */
00100         using WriteBuffer::retain;
00101 
00102         /**
00103         * {@inheritDoc}
00104         */
00105         virtual void clear();
00106 
00107         /**
00108         * {@inheritDoc}
00109         */
00110         virtual WriteBuffer::Handle getWriteBuffer(size32_t of);
00111 
00112         /**
00113         * {@inheritDoc}
00114         */
00115         virtual WriteBuffer::Handle getWriteBuffer(size32_t of, size32_t cb);
00116 
00117         /**
00118         * {@inheritDoc}
00119         */
00120         virtual ReadBuffer::View getReadBuffer() const;
00121 
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual Array<octet_t>::View toOctetArray() const;
00126 
00127 
00128     // ----- internal methods -----------------------------------------------
00129 
00130     protected:
00131         /**
00132         * Factory method: Instantiate a BufferOutput object to write data to
00133         * the WriteBuffer.
00134         *
00135         * @return a new BufferOutput writing to this ReadBuffer
00136         */
00137         virtual BufferOutput::Handle instantiateBufferOutput();
00138 
00139         /**
00140         * Get a small buffer for formating data.
00141         *
00142         * @return a small octet array
00143         */
00144         virtual Array<octet_t>::Handle tmpbuf();
00145 
00146         /**
00147         * Get a buffer for formating data.
00148         *
00149         * @param cb  the minimum size for the buffer
00150         *
00151         * @return an octet array that is at least <tt>cb</tt> octets long
00152         */
00153         virtual Array<octet_t>::Handle tmpbuf(size32_t cb);
00154 
00155 
00156     // ----- AbstractBufferOutput inner class -------------------------------
00157 
00158     public:
00159         /**
00160         * AbstractBufferOutput is a concrete implementation of BufferOutput
00161         * for the non-concrete AbstractWriteBuffer implementation.
00162         *
00163         * @author jh  2008.01.08
00164         */
00165         class COH_EXPORT AbstractBufferOutput
00166             : public class_spec<AbstractBufferOutput,
00167                 extends<Object>,
00168                 implements<BufferOutput> >
00169             {
00170             friend class factory<AbstractBufferOutput>;
00171 
00172             // ----- constructors ---------------------------------------
00173 
00174             protected:
00175                 /**
00176                 * Create a new AbstractBufferOutput instance that delegates
00177                 * to the given AbstractWriteBuffer.
00178                 *
00179                 * @param hBuf  the delegate AbstractWriteBuffer
00180                 */
00181                 AbstractBufferOutput(AbstractWriteBuffer::Handle hBuf);
00182 
00183             // ----- BufferOutput interface -----------------------------
00184 
00185             public:
00186                 /**
00187                 * {@inheritDoc}
00188                 */
00189                 virtual WriteBuffer::Handle getBuffer();
00190 
00191                 /**
00192                 * {@inheritDoc}
00193                 */
00194                 virtual WriteBuffer::View getBuffer() const;
00195 
00196                 /**
00197                 * {@inheritDoc}
00198                 */
00199                 virtual size32_t getOffset() const;
00200 
00201                 /**
00202                 * {@inheritDoc}
00203                 */
00204                 virtual void setOffset(size32_t of);
00205 
00206                 /**
00207                 * {@inheritDoc}
00208                 */
00209                 virtual void write(octet_t b);
00210 
00211                 /**
00212                 * {@inheritDoc}
00213                 */
00214                 virtual void write(Array<octet_t>::View vab);
00215 
00216                 /**
00217                 * {@inheritDoc}
00218                 */
00219                 virtual void write(Array<octet_t>::View vab, size32_t of,
00220                         size32_t cb);
00221 
00222                 /**
00223                 * {@inheritDoc}
00224                 */
00225                 virtual void writeBuffer(ReadBuffer::View vBuf);
00226 
00227                 /**
00228                 * {@inheritDoc}
00229                 */
00230                 virtual void writeBuffer(ReadBuffer::View vBuf, size32_t of,
00231                         size32_t cb);
00232 
00233                 /**
00234                 * {@inheritDoc}
00235                 */
00236                 virtual void writeBoolean(bool f);
00237 
00238                 /**
00239                 * {@inheritDoc}
00240                 */
00241                 virtual void writeChar16(char16_t ch);
00242 
00243                 /**
00244                 * {@inheritDoc}
00245                 */
00246                 virtual void writeString(String::View vs);
00247 
00248                 /**
00249                 * {@inheritDoc}
00250                 */
00251                 virtual void writeInt16(int16_t n);
00252 
00253                 /**
00254                 * {@inheritDoc}
00255                 */
00256                 virtual void writeInt32(int32_t n);
00257 
00258                 /**
00259                 * {@inheritDoc}
00260                 */
00261                 virtual void writeInt64(int64_t n);
00262 
00263                 /**
00264                 * {@inheritDoc}
00265                 */
00266                 virtual void writeFloat32(float32_t fl);
00267 
00268                 /**
00269                 * {@inheritDoc}
00270                 */
00271                 virtual void writeFloat64(float64_t dfl);
00272 
00273             // ----- data members ---------------------------------------
00274 
00275             protected:
00276                 /**
00277                 * The delegate AbstractWriteBuffer.
00278                 */
00279                 MemberHandle<AbstractWriteBuffer> m_hBuf;
00280 
00281                 /**
00282                 * Current write offset within the AbstractWriteBuffer.
00283                 */
00284                 size32_t m_ofWrite;
00285             };
00286 
00287         /**
00288         * {@inheritDoc}
00289         */
00290         virtual BufferOutput::Handle getBufferOutput(size32_t of = 0);
00291 
00292         /**
00293         * {@inheritDoc}
00294         */
00295         virtual BufferOutput::Handle getAppendingBufferOutput();
00296 
00297 
00298     // ----- data members ---------------------------------------------------
00299 
00300     protected:
00301         /**
00302         * A temp buffer to use for building the data to write.
00303         */
00304         MemberHandle<Array<octet_t> > m_habBuf;
00305     };
00306 
00307 COH_CLOSE_NAMESPACE2
00308 
00309 #endif // COH_ABSTRACT_WRITE_BUFFER_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.