coherence/io/pof/UserTypeWriter.hpp

00001 /*
00002 * UserTypeWriter.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_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 hHandler  the WritingPofHandler used to write user type data
00074         *                  (except for the user type id itself, which is
00075         *                  passed as a constructor argument)
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(WritingPofHandler::Handle hHandler,
00084                 PofContext::View vCtx, int32_t nTypeId, int32_t iProp);
00085 
00086 
00087     // ----- PofWriter interface --------------------------------------------
00088 
00089     public:
00090         /**
00091         * {@inheritDoc}
00092         */
00093         virtual void writeObject(int32_t iProp, Object::View v);
00094 
00095         /**
00096         * {@inheritDoc}
00097         */
00098         virtual int32_t getUserTypeId() const;
00099 
00100         /**
00101         * {@inheritDoc}
00102         */
00103         virtual int32_t getVersionId() const;
00104 
00105         /**
00106         * {@inheritDoc}
00107         */
00108         virtual void setVersionId(int32_t nVersionId);
00109 
00110         /**
00111         * {@inheritDoc}
00112         */
00113         virtual void writeRemainder(Binary::View vBinProps);
00114 
00115 
00116     // ----- internal methods -----------------------------------------------
00117 
00118     protected:
00119         /**
00120         * {@inheritDoc}
00121         */
00122         virtual void beginProperty(int32_t iProp);
00123 
00124         /**
00125         * {@inheritDoc}
00126         */
00127         virtual void endProperty(int32_t iProp);
00128 
00129         /**
00130         * Write out the type and version identifiers of the user type to the
00131         * POF stream, if they haven't already been written.
00132         *
00133         * @throws IOException on I/O error
00134         */
00135         virtual void writeUserTypeInfo();
00136 
00137 
00138     // ----- data members ---------------------------------------------------
00139 
00140     protected:
00141         /**
00142         * The type identifier of the user type that is being written.
00143         */
00144         const int32_t m_nTypeId;
00145 
00146         /**
00147         * The version identifier of the user type that is being written.
00148         */
00149         int32_t m_nVersionId;
00150 
00151         /**
00152         * The index of the user type being written.
00153         */
00154         const int32_t m_iProp;
00155 
00156         /**
00157         * The index of the last property written to the POF stream or -1 if
00158         * the first property has yet to be written.
00159         */
00160         int32_t m_iPrevProp;
00161 
00162         /**
00163         * True iff the type and version identifier of the user type was
00164         * written to the POF stream.
00165         */
00166         bool m_fUserTypeBegin;
00167 
00168         /**
00169         * True iff the user type was written to the POF stream.
00170         */
00171         bool m_fUserTypeEnd;
00172 
00173         /**
00174         * The Complex value that corresponds to the user type that is being
00175         * written.
00176         */
00177         MemberHandle<WritingPofHandler::Complex> m_hComplex;
00178     };
00179 
00180 COH_CLOSE_NAMESPACE3
00181 
00182 #endif // COH_USER_TYPE_WRITER_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.