coherence/io/pof/UserTypeReader.hpp

00001 /*
00002 * UserTypeReader.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_READER_HPP
00017 #define COH_USER_TYPE_READER_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/ReadBuffer.hpp"
00022 #include "coherence/io/pof/PofBufferReader.hpp"
00023 #include "coherence/io/pof/PofContext.hpp"
00024 #include "coherence/util/Binary.hpp"
00025 
00026 COH_OPEN_NAMESPACE3(coherence,io,pof)
00027 
00028 using coherence::io::ReadBuffer;
00029 using coherence::util::Binary;
00030 
00031 
00032 /**
00033 * The UserTypeReader implementation is a contextually-aware PofReader whose
00034 * purpose is to advance through the properties of a value of a specified user
00035 * type. The "contextual awareness" refers to the fact that the UserTypeReader
00036 * maintains state about the type identifier and version of the user type, the
00037 * parser's property index position within the user type value, and a
00038 * PofContext that may differ from the PofContext that provided the
00039 * PofSerializer which is using this UserTypeReader to parse a user type.
00040 *
00041 * @author jh  2008.04.11
00042 */
00043 class COH_EXPORT UserTypeReader
00044     : public class_spec<UserTypeReader,
00045         extends<PofBufferReader> >
00046     {
00047     friend class factory<UserTypeReader>;
00048 
00049     // ----- constructors ---------------------------------------------------
00050 
00051     public:
00052         /**
00053         * Construct a parser for parsing the property values of a user type.
00054         *
00055         * @param hIn         the BufferInput that contains the user type
00056         *                    data, except for the user type id itself (which
00057         *                    is passed passed as a constructor argument)
00058         * @param vCtx        the PofContext to use for parsing the user type
00059         *                    property values within the user type that this
00060         *                    parser will be parsing
00061         * @param nTypeId     the type id of the user type
00062         * @param nVersionId  the version id of the user type
00063         *
00064         * @throws IOException  if an I/O error occurs
00065         */
00066         UserTypeReader(ReadBuffer::BufferInput::Handle hIn,
00067                 PofContext::View vCtx, int32_t nTypeId, int32_t nVersionId);
00068 
00069 
00070     // ----- PofReader interface --------------------------------------------
00071 
00072     public:
00073         /**
00074         * {@inheritDoc}
00075         */
00076         virtual int32_t getUserTypeId() const;
00077 
00078         /**
00079         * {@inheritDoc}
00080         */
00081         virtual int32_t getVersionId() const;
00082 
00083         /**
00084         * {@inheritDoc}
00085         */
00086         virtual Binary::View readRemainder();
00087 
00088 
00089     // ----- internal methods -----------------------------------------------
00090 
00091     protected:
00092         /**
00093         * {@inheritDoc}
00094         */
00095         virtual bool advanceTo(int32_t iProp);
00096 
00097         /**
00098         * {@inheritDoc}
00099         */
00100         virtual void complete(int32_t iProp);
00101 
00102 
00103     // ----- data members ---------------------------------------------------
00104 
00105     protected:
00106         /**
00107         * The type identifier of the user type that is being parsed.
00108         */
00109         const int32_t m_nTypeId;
00110 
00111         /**
00112         * The version identifier of the user type that is being parsed.
00113         */
00114         const int32_t m_nVersionId;
00115 
00116         /**
00117         * Most recent property read or (if it were missing) requested. This
00118         * is used to determine if the client is attempting to read properties
00119         * in the wrong order.
00120         */
00121         int32_t m_iPrevProp;
00122 
00123         /**
00124         * The index of the next property in the POF stream.
00125         */
00126         int32_t m_iNextProp;
00127 
00128         /**
00129         * The offset of the index of the next property to read.
00130         */
00131         size32_t m_ofNextProp;
00132     };
00133 
00134 COH_CLOSE_NAMESPACE3
00135 
00136 #endif // COH_USER_TYPE_READER_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.