Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.3.0)

E80355-01

coherence/util/extractor/TypedUpdater.hpp

00001 /*
00002 * TypedUpdater.hpp
00003 *
00004 * Copyright (c) 2000, 2017, 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             // Bug19826856,COH-12476; strict aliasing errors
00093             // casting to local variable seems to be necessary, suspect
00094             // a compiler issue, GCC 4.8.2
00095             // get_pointer also needed for GCC 4.8.2
00096             OH hOHTarget = cast<OH>(hTarget);
00097             C* pTarget = get_pointer(hOHTarget);
00098             (*pTarget.*(M))(cast<AH>(ohValue));
00099             }
00100 
00101 
00102     // ----- Object interface -----------------------------------------------
00103 
00104     public:
00105         /**
00106         * {@inheritDoc}
00107         */
00108         virtual bool equals(Object::View v) const
00109             {
00110             return instanceof<typename TypedUpdater<A, C, M, AH, OH>::View>(v);
00111             }
00112 
00113         /**
00114         * {@inheritDoc}
00115         */
00116         virtual size32_t hashCode() const
00117             {
00118             return Class::getClassName(this)->hashCode();
00119             }
00120 
00121         /**
00122         * {@inheritDoc}
00123         */
00124         virtual TypedHandle<const String> toString() const
00125             {
00126             return Class::getClassName(this);
00127             }
00128     };
00129 
00130 COH_CLOSE_NAMESPACE3
00131 
00132 /**
00133 * Helper macro for creating a TypedUpdater.
00134 *
00135 * @param C  the class to call the method on, i.e. Address
00136 * @param M  the method to call, i.e. setState
00137 * @param A  the argument type, i.e. String::View
00138 */
00139 #define COH_TYPED_UPDATER(C, M, A) \
00140     coherence::util::extractor::TypedUpdater<A, C, &C::M>::create(#M)
00141 
00142 #endif // COH_TYPED_UPDATER_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.