C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/extractor/PofExtractor.hpp

00001 /*
00002  * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
00003  *
00004  * Licensed under the Universal Permissive License v 1.0 as shown at
00005  * http://oss.oracle.com/licenses/upl.
00006  */
00007 #ifndef COH_POF_EXTRACTOR_HPP
00008 #define COH_POF_EXTRACTOR_HPP
00009 
00010 #include "coherence/lang.ns"
00011 
00012 #include "coherence/io/pof/PofConstants.hpp"
00013 #include "coherence/io/pof/PofContext.hpp"
00014 #include "coherence/io/pof/PofHelper.hpp"
00015 #include "coherence/io/pof/PofReader.hpp"
00016 #include "coherence/io/pof/PofWriter.hpp"
00017 #include "coherence/io/pof/PortableObject.hpp"
00018 #include "coherence/io/pof/reflect/PofNavigator.hpp"
00019 #include "coherence/util/extractor/AbstractExtractor.hpp"
00020 
00021 #include <typeinfo>
00022 
00023 COH_OPEN_NAMESPACE3(coherence,util,extractor)
00024 
00025 using coherence::io::pof::PofConstants;
00026 using coherence::io::pof::PofContext;
00027 using coherence::io::pof::PofHelper;
00028 using coherence::io::pof::PofReader;
00029 using coherence::io::pof::PofWriter;
00030 using coherence::io::pof::reflect::PofNavigator;
00031 
00032 
00033 /**
00034 * POF-based ValueExtractor implementation.
00035 * PofExtractor takes advantage of POF's indexed state to extract part of an
00036 * object without needing to deserialize the entire object.
00037 * <p/>
00038 * POF uses a compact form in the serialized value when possible. For example,
00039 * some numeric values are represented as special POF intrinsic types in which
00040 * the type implies the value. As a result, POF requires the receiver of a
00041 * value to have implicit knowledge of the type. PofExtractor uses the type
00042 * supplied in the constructor as the source of the type information. If the
00043 * type is void, PofExtractor will infer the type from the serialized state.
00044 * See {@link PofConstants} for the list of the POF types.
00045 * <p/>
00046 * In C++ the type is expressed by type_info which is obtained from the typeid
00047 * operator.
00048 *
00049 * Example where extracted value is float64_t:
00050 * <pre><code>
00051 *     ValueExtractor::Handle hExtractor =
00052 *         PofExtractor::create(typeid(float64_t), 0);
00053 * </code></pre>
00054 *
00055 * Example where extracted value should be inferred from the serialized state:
00056 * <pre><code>
00057 *     ValueExtractor::Handle hExtractor =
00058 *         PofExtractor::create(typeid(void), 0);
00059 * </code></pre>
00060 *
00061 * @author as/gm 2009.04.02
00062 * @since Coherence 3.5
00063 */
00064 class COH_EXPORT PofExtractor
00065     : public class_spec<PofExtractor,
00066         extends<AbstractExtractor>,
00067         implements<PortableObject> >
00068     {
00069     friend class factory<PofExtractor>;
00070 
00071     // ----- constructors ---------------------------------------------------
00072 
00073     protected:
00074         /**
00075         * Default constructor (necessary for the PortableObject interface).
00076         */
00077         PofExtractor();
00078 
00079         /**
00080         * Constructs a PofExtractor based on a property index.
00081         * <p/>
00082         * This constructor is equivalent to:
00083         * <pre>
00084         *   PofExtractor::View vExtractor =
00085         *       PofExtractor::create(info, SimplePofPath::create(iProp), value);
00086         * </pre>
00087         *
00088         * @param info  the required type of the extracted value or void if
00089         *              the type is to be inferred from the serialized state
00090         * @param iProp  property index
00091         */
00092         PofExtractor(const std::type_info& info, int32_t iProp);
00093 
00094         /**
00095         * Constructs a PofExtractor based on a property path and the entry
00096         * extraction target.
00097         *
00098         * @param info        the required type of the extracted value or void
00099         *                    if the type is to be inferred from the serialized
00100         *                    state
00101         * @param vNavigator  POF navigator
00102         * @param nTarget     one of the {@link #value} or {@link #key} values
00103         */
00104         PofExtractor(const std::type_info& info, PofNavigator::View vNavigator,
00105                 int32_t nTarget = value);
00106 
00107 
00108     // ----- AbstractExtractor methods --------------------------------------
00109 
00110     public:
00111         /**
00112         * Extract the value from the passed Entry object. The returned value
00113         * should follow the conventions outlined in the {@link #extract}
00114         * method.
00115         * <p/>
00116         * This method will always throw a
00117         * {@link UnsupportedOperationException} if called directly by the
00118         * C++ client application, as its execution is only meaningful within
00119         * the cluster.
00120         * <p/>
00121         * It is expected that this extractor will only be used against
00122         * POF-encoded binary entries within a remote partitioned cache.
00123         *
00124         * @param entry  an Entry object to extract a desired value from
00125         *
00126         * @throws UnsupportedOperationException  always, as it is expected
00127         *         that this extractor will only be executed within the
00128         *         cluster.
00129         *
00130         * @return the extracted value
00131         */
00132         virtual Object::Holder extractFromEntry(Map::Entry::Holder ohEntry) const;
00133 
00134 
00135     // ----- PortableObject interface ---------------------------------------
00136 
00137     public:
00138         /**
00139         * {@inheritDoc}
00140         */
00141         virtual void readExternal(PofReader::Handle hIn);
00142 
00143         /**
00144         * {@inheritDoc}
00145         */
00146         virtual void writeExternal(PofWriter::Handle hOut) const;
00147 
00148 
00149     // ----- Object interface -----------------------------------------------
00150 
00151     public:
00152         /**
00153         * Compare the PofExtractor with another object to determine equality.
00154         * Two PofExtractor objects are considered equal iff their paths are
00155         * equal and they have the same target (key or value).
00156         *
00157         * @return true iff this PofExtractor and the passed object are
00158         *              equivalent
00159         */
00160         virtual bool equals(Object::View v) const;
00161 
00162         /**
00163         * Determine a hash value for the PofExtractor object according to the
00164         * general {@link Object#hashCode()} contract.
00165         *
00166         * @return an integer hash value for this PofExtractor object
00167         */
00168         virtual size32_t hashCode() const;
00169 
00170         /**
00171         * Return a human-readable description for this PofExtractor.
00172         *
00173         * @return a String description of the PofExtractor
00174         */
00175         virtual TypedHandle<const String> toString() const;
00176 
00177 
00178     // ----- accessors ------------------------------------------------------
00179 
00180     public:
00181         /**
00182         * Obtain the Class of the extracted value.
00183         *
00184         * @return the expected Class
00185         */
00186         Class::View getClassExtracted() const;
00187 
00188         /**
00189         * Obtain the PofPath for this extractor.
00190         *
00191         * @return the PofPath value
00192         */
00193         virtual PofNavigator::View getNavigator() const;
00194 
00195 
00196     // ----- helper methods -------------------------------------------------
00197 
00198     protected:
00199         /**
00200         * Compute the expected POF type id based on the class.
00201         *
00202         * @param vCtx  POF context
00203         *
00204         * @return POF type id or t_unknown if the class is NULL.
00205         */
00206         virtual int32_t getPofTypeId(PofContext::View vCtx) const;
00207 
00208 
00209     // ----- data members ---------------------------------------------------
00210 
00211     private:
00212         /**
00213         * POF navigator.
00214         */
00215         FinalView<PofNavigator> f_vNavigator;
00216 
00217         /**
00218         * Class for what is being extracted; or NULL if this information is
00219         * specified in m_nType.
00220         */
00221         FinalView<Class> f_vClass;
00222 
00223         /**
00224         * POF type for expected value.
00225         */
00226         int32_t m_nType;
00227     };
00228 
00229 COH_CLOSE_NAMESPACE3
00230 
00231 #endif // #define COH_POF_EXTRACTOR_HPP
Copyright © 2000, 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.