Oracle Coherence for C++ API
Release 3.6.1.0
E18813-01

- Main Page
- Namespaces
- Classes
- Files

# coherence/io/pof/UserTypeWriter.hpp

    00001 /*
    00002 * UserTypeWriter.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_USER_TYPE_WRITER_HPP
    00017 #define COH_USER_TYPE_WRITER_HPP
    00018
    00019 #include "coherence/lang.ns"
    00020
    00021 #include "coherence/io/WriteBuffer.hpp"
    00022 #include "coherence/io/pof/PofBufferWriter.hpp"
    00023 #include "coherence/io/pof/PofContext.hpp"
    00024 #include "coherence/io/pof/WritingPofHandler.hpp"
    00025 #include "coherence/util/Binary.hpp"
    00026
    00027 COH_OPEN_NAMESPACE3(coherence,io,pof)
    00028
    00029 using coherence::io::WriteBuffer;
    00030 using coherence::util::Binary;
    00031
    00032
    00033 /**
    00034 * The UserTypeWriter implementation is a contextually-aware PofWriter whose
    00035 * purpose is to write the properties of a value of a specified user type. The
    00036 * "contextual awareness" refers to the fact that the UserTypeWriter maintains
    00037 * state about the type identifier, the PofWriter's property index position
    00038 * within the user type value, and a PofContext that may differ from the
    00039 * PofContext that provided the PofSerializer which is using this
    00040 * UserTypeWriter to serialize a user type.
    00041 *
    00042 * @author jh  2008.04.11
    00043 */
    00044 class COH_EXPORT UserTypeWriter
    00045         : public class_spec<UserTypeWriter,
    00046             extends<PofBufferWriter> >
    00047     {
    00048     friend class factory<UserTypeWriter>;
    00049
    00050     // ----- constructors ---------------------------------------------------
    00051
    00052     public:
    00053         /**
    00054         * Construct a UserTypeWriter for writing the property values of a
    00055         * user type.
    00056         *
    00057         * @param hOut     the BufferOutput object to write to; must not be
    00058         *                 NULL
    00059         * @param vCtx     the PofContext to use for writing the user type
    00060         *                 property values within the user type that this
    00061         *                 writer will be writing
    00062         * @param nTypeId  the type identifier of the user type; must be
    00063         *                 non-negative
    00064         * @param iProp    the index of the user type being written
    00065         */
    00066         UserTypeWriter(WriteBuffer::BufferOutput::Handle hOut,
    00067                 PofContext::View vCtx, int32_t nTypeId, int32_t iProp);
    00068
    00069         /**
    00070         * Construct a UserTypeWriter for writing the property values of a
    00071         * user type.
    00072         *
    00073         * @param hParent  the containing PofBufferWriter
    00074         * @param hOut     the BufferOutput object to write to; must not be
    00075         *                 null
    00076         * @param vCtx     the PofContext to use for writing the user type
    00077         *                 property values within the user type that this
    00078         *                 writer will be writing
    00079         * @param nTypeId  the type identifier of the user type; must be
    00080         *                 non-negative
    00081         * @param iProp    the index of the user type being written
    00082         */
    00083         UserTypeWriter(PofBufferWriter::Handle hParent,
    00084                 WriteBuffer::BufferOutput::Handle hOut,
    00085                 PofContext::View vCtx, int32_t nTypeId, int32_t iProp);
    00086
    00087         /**
    00088         * Construct a UserTypeWriter for writing the property values of a
    00089         * user type.
    00090         *
    00091         * @param hHandler  the WritingPofHandler used to write user type data
    00092         *                  (except for the user type id itself, which is
    00093         *                  passed as a constructor argument)
    00094         * @param vCtx      the PofContext to use for writing the user type
    00095         *                  property values within the user type that this
    00096         *                  writer will be writing
    00097         * @param nTypeId   the type identifier of the user type; must be
    00098         *                  non-negative
    00099         * @param iProp     the index of the user type being written
    00100         */
    00101         UserTypeWriter(WritingPofHandler::Handle hHandler,
    00102                 PofContext::View vCtx, int32_t nTypeId, int32_t iProp);
    00103
    00104         /**
    00105         * Construct a UserTypeWriter for writing the property values of a
    00106         * user type.
    00107         *
    00108         * @param hParent  the containing PofBufferWriter
    00109         * @param hHandle  the WritingPofHandler used to write user type data
    00110         *                 (except for the user type id itself, which is
    00111         *                 passed as a constructor argument)
    00112         * @param vCtx     the PofContext to use for writing the user type
    00113         *                 property values within the user type that this
    00114         *                 writer will be writing
    00115         * @param nTypeId  the type identifier of the user type; must be
    00116         *                 non-negative
    00117         * @param iProp    the index of the user type being written
    00118         * @param nId      the identity of the object to encode, or -1 if the
    00119         *                 identity shouldn't be encoded in the POF stream
    00120         */
    00121         UserTypeWriter(PofBufferWriter::Handle hParent,
    00122                 WritingPofHandler::Handle hHandler,
    00123                 PofContext::View vCtx, int nTypeId, int iProp, int nId=-1);
    00124
    00125
    00126     // ----- PofWriter interface --------------------------------------------
    00127
    00128     public:
    00129         /**
    00130         * {@inheritDoc}
    00131         */
    00132         virtual void writeObject(int32_t iProp, Object::View v);
    00133
    00134         /**
    00135         * {@inheritDoc}
    00136         */
    00137         virtual int32_t getUserTypeId() const;
    00138
    00139         /**
    00140         * {@inheritDoc}
    00141         */
    00142         virtual int32_t getVersionId() const;
    00143
    00144         /**
    00145         * {@inheritDoc}
    00146         */
    00147         virtual void setVersionId(int32_t nVersionId);
    00148
    00149         /**
    00150         * {@inheritDoc}
    00151         */
    00152         virtual PofWriter::Handle createNestedPofWriter(int32_t iProp);
    00153
    00154         /**
    00155         * {@inheritDoc}
    00156         */
    00157         virtual void writeRemainder(Binary::View vBinProps);
    00158
    00159
    00160     // ----- internal methods -----------------------------------------------
    00161
    00162     protected:
    00163         /**
    00164         * {@inheritDoc}
    00165         */
    00166         virtual PofBufferWriter::Handle getParentWriter();
    00167
    00168         /**
    00169         * {@inheritDoc}
    00170         */
    00171         virtual PofBufferWriter::View getParentWriter() const;
    00172
    00173         /**
    00174         * {@inheritDoc}
    00175         */
    00176         virtual void beginProperty(int32_t iProp);
    00177
    00178         /**
    00179         * {@inheritDoc}
    00180         */
    00181         virtual void endProperty(int32_t iProp);
    00182
    00183         /**
    00184         * Notify the UserTypeWriter that it is being "closed". This
    00185         * notification allows the UserTypeWriter to write any remaining data
    00186         * that it has pending to write.
    00187         */
    00188         virtual void closeNested();
    00189
    00190         /**
    00191         * Write out the type and version identifiers of the user type to the
    00192         * POF stream, if they haven't already been written.
    00193         *
    00194         * @throws IOException on I/O error
    00195         */
    00196         virtual void writeUserTypeInfo();
    00197
    00198         /**
    00199         * {@inheritDoc}
    00200         */
    00201         virtual void enableReferences();
    00202
    00203
    00204     // ----- data members ---------------------------------------------------
    00205
    00206     protected:
    00207         /**
    00208         * The parent (ie containing) PofBufferWriter.
    00209         */
    00210         MemberHandle<PofBufferWriter> m_hWriterParent;
    00211
    00212         /**
    00213         * The type identifier of the user type that is being written.
    00214         */
    00215         const int32_t m_nTypeId;
    00216
    00217         /**
    00218         * The version identifier of the user type that is being written.
    00219         */
    00220         int32_t m_nVersionId;
    00221
    00222         /**
    00223         * The index of the user type being written.
    00224         */
    00225         const int32_t m_iProp;
    00226
    00227         /**
    00228         * The identity of the object to encode, or -1 if the identity
    00229         * shouldn't be encoded in the POF stream
    00230         */
    00231         int32_t m_nId;
    00232
    00233         /**
    00234         * The index of the last property written to the POF stream or -1 if
    00235         * the first property has yet to be written.
    00236         */
    00237         int32_t m_iPrevProp;
    00238
    00239         /**
    00240         * True iff the type and version identifier of the user type was
    00241         * written to the POF stream.
    00242         */
    00243         bool m_fUserTypeBegin;
    00244
    00245         /**
    00246         * True iff the user type was written to the POF stream.
    00247         */
    00248         bool m_fUserTypeEnd;
    00249
    00250         /**
    00251         * The Complex value that corresponds to the user type that is being
    00252         * written.
    00253         */
    00254         MemberHandle<WritingPofHandler::Complex> m_hComplex;
    00255
    00256         /**
    00257         * The currently open nested writer, if any.
    00258         */
    00259         MemberHandle<UserTypeWriter> m_hWriterNested;
    00260     };
    00261
    00262 COH_CLOSE_NAMESPACE3
    00263
    00264 #endif // COH_USER_TYPE_WRITER_HPP

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