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

- Main Page
- Namespaces
- Classes
- Files

# coherence/util/extractor/TypedUpdater.hpp

    00001 /*
    00002 * TypedUpdater.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_UPDATER_HPP
    00017 #define COH_TYPED_UPDATER_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/ReflectionUpdater.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 ValueUpdater implementation.
    00035 *
    00036 * This updater functions on non-const methods which take Objects, for an
    00037 * updater which works with non-Object types see BoxUpdater.
    00038 *
    00039 * For ease of use the COH_TYPED_UPDATER macro can be used to easily construct
    00040 * an instance of this class. For example the following constructs an updater
    00041 * for calling the "void Address::setState(String::View)" method.
    00042 *
    00043 * @code
    00044 * ValueUpdater::View vUpd = COH_TYPED_UPDATER(Address, setState, String::View);
    00045 * @endcode
    00046 *
    00047 * @author mf 2009.07.29
    00048 *
    00049 * @see BoxUpdater
    00050 */
    00051 template<class A, class C, void (C::*M)(A), class AH = A, class OH = typename C::Handle>
    00052 class TypedUpdater
    00053     : public class_spec<TypedUpdater<A, C, M, AH, OH>,
    00054         extends<ReflectionUpdater> >
    00055     {
    00056     friend class factory<TypedUpdater<A, C, M, AH, OH> >;
    00057
    00058     // ----- constructors ---------------------------------------------------
    00059
    00060     protected:
    00061         /**
    00062         * Construct a TypedUpdater
    00063         */
    00064         TypedUpdater()
    00065             {
    00066             }
    00067
    00068         /**
    00069         * Construct a TypedUpdater based on a method name and optional
    00070         * parameters.
    00071         *
    00072         * The method name is only used for the purposes of serializing the
    00073         * updater for execution on remote Java members.
    00074         *
    00075         * @param vsMethod  the name of the method to invoke via reflection
    00076         */
    00077         TypedUpdater(String::View vsMethod)
    00078             : class_spec<TypedUpdater<A, C, M, AH, OH>,
    00079             extends<ReflectionUpdater> >(vsMethod)
    00080             {
    00081             }
    00082
    00083
    00084    // ----- ValueUpdater interface ---------------------------------------
    00085
    00086     public:
    00087         /**
    00088         * {@inheritDoc}
    00089         */
    00090         virtual void update(Object::Handle hTarget, Object::Holder ohValue) const
    00091             {
    00092             (*cast<OH>(hTarget).*(M))(cast<AH>(ohValue));
    00093             }
    00094
    00095
    00096     // ----- Object interface -----------------------------------------------
    00097
    00098     public:
    00099         /**
    00100         * {@inheritDoc}
    00101         */
    00102         virtual bool equals(Object::View v) const
    00103             {
    00104             return instanceof<typename TypedUpdater<A, C, M, AH, OH>::View>(v);
    00105             }
    00106
    00107         /**
    00108         * {@inheritDoc}
    00109         */
    00110         virtual size32_t hashCode() const
    00111             {
    00112             return Class::getClassName(this)->hashCode();
    00113             }
    00114
    00115         /**
    00116         * {@inheritDoc}
    00117         */
    00118         virtual void toStream(std::ostream& out) const
    00119             {
    00120             out << Class::getClassName(this);
    00121             }
    00122     };
    00123
    00124 COH_CLOSE_NAMESPACE3
    00125
    00126 /**
    00127 * Helper macro for creating a TypedUpdater.
    00128 *
    00129 * @param C  the class to call the method on, i.e. Address
    00130 * @param M  the method to call, i.e. setState
    00131 * @param A  the argument type, i.e. String::View
    00132 */
    00133 #define COH_TYPED_UPDATER(C, M, A) \
    00134     coherence::util::extractor::TypedUpdater<A, C, &C::M>::create(#M)
    00135
    00136 #endif // COH_TYPED_UPDATER_HPP

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