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

- Main Page
- Namespaces
- Classes
- Files

# coherence/util/extractor/TypedExtractor.hpp

    00001 /*
    00002 * TypedExtractor.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_TYPED_EXTRACTOR_HPP
    00017 #define COH_TYPED_EXTRACTOR_HPP
    00018
    00019 #include "coherence/lang.ns"
    00020
    00021 #include "coherence/io/pof/PofReader.hpp"
    00022 #include "coherence/io/pof/PofWriter.hpp"
    00023
    00024 #include "coherence/util/extractor/ReflectionExtractor.hpp"
    00025
    00026
    00027 COH_OPEN_NAMESPACE3(coherence,util,extractor)
    00028
    00029 using coherence::io::pof::PofReader;
    00030 using coherence::io::pof::PofWriter;
    00031
    00032
    00033 /**
    00034 * Template based ValueExtractor implementation.
    00035 *
    00036 * This extractor functions on const methods which return Objects, for an
    00037 * extractor which works with non-Object return types see BoxExtractor.
    00038 *
    00039 * For ease of use the COH_TYPED_EXTRACTOR macro can be used to easily construct
    00040 * an instance of this class. For example the following constructs an extractor
    00041 * for calling the "String::View Address::getState() const" method.
    00042 *
    00043 * @code
    00044 * ValueExtractor::View vExt = COH_TYPED_EXTRACTOR(String::View, Address, getState);
    00045 * @endcode
    00046 *
    00047 * @author mf 2009.03.20
    00048 *
    00049 * @see BoxExtractor
    00050 */
    00051 template<class R, class C, R (C::*M)() const, class RH = Object::Holder,
    00052     class OH = typename C::Holder>
    00053 class TypedExtractor
    00054     : public class_spec<TypedExtractor<R, C, M, RH, OH>,
    00055         extends<ReflectionExtractor> >
    00056     {
    00057     friend class factory<TypedExtractor<R, C, M, RH, OH> >;
    00058
    00059     // ----- constructors ---------------------------------------------------
    00060
    00061     protected:
    00062         /**
    00063         * Construct a TypedExtractor
    00064         */
    00065         TypedExtractor()
    00066             {
    00067             }
    00068
    00069         /**
    00070         * Construct a TypedExtractor based on a method name and optional
    00071         * parameters.
    00072         *
    00073         * The method name is only used for the purposes of serializing the
    00074         * extractor for execution on remote Java members.
    00075         *
    00076         * @param vsMethod  the name of the method to invoke via reflection
    00077         */
    00078         TypedExtractor(String::View vsMethod)
    00079             : class_spec<TypedExtractor<R, C, M, RH, OH>,
    00080             extends<ReflectionExtractor> >(vsMethod)
    00081             {
    00082             }
    00083
    00084
    00085    // ----- ValueExtractor interface ---------------------------------------
    00086
    00087     public:
    00088         /**
    00089         * {@inheritDoc}
    00090         */
    00091         virtual Object::Holder extract(Object::Holder ohTarget) const
    00092             {
    00093             return RH(((*cast<OH>(ohTarget)).*(M))());
    00094             }
    00095
    00096
    00097     // ----- Object interface -----------------------------------------------
    00098
    00099     public:
    00100         /**
    00101         * {@inheritDoc}
    00102         */
    00103         virtual bool equals(Object::View v) const
    00104             {
    00105             return instanceof<typename TypedExtractor<R, C, M, RH, OH>::View>(v);
    00106             }
    00107
    00108         /**
    00109         * {@inheritDoc}
    00110         */
    00111         virtual size32_t hashCode() const
    00112             {
    00113             return Class::getClassName(this)->hashCode();
    00114             }
    00115
    00116         /**
    00117         * {@inheritDoc}
    00118         */
    00119         virtual void toStream(std::ostream& out) const
    00120             {
    00121             out << Class::getClassName(this);
    00122             }
    00123     };
    00124
    00125 COH_CLOSE_NAMESPACE3
    00126
    00127 /**
    00128 * Helper macro for creating a TypedExtractor.
    00129 *
    00130 * @param H  the return object type, i.e. String::View
    00131 * @param C  the class to call the method on, i.e. Address
    00132 * @param M  the method to call, i.e. getState
    00133 */
    00134 #define COH_TYPED_EXTRACTOR(H, C, M) \
    00135     coherence::util::extractor::TypedExtractor<H, C, &C::M>::create(#M)
    00136
    00137 #endif // COH_TYPED_EXTRACTOR_HPP

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