Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/extractor/BoxExtractor.hpp

00001 /*
00002 * BoxExtractor.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_BOX_EXTRACTOR_HPP
00017 #define COH_BOX_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/TypedExtractor.hpp"
00025 
00026 COH_OPEN_NAMESPACE3(coherence,util,extractor)
00027 
00028 using coherence::io::pof::PofReader;
00029 using coherence::io::pof::PofWriter;
00030 
00031 
00032 /**
00033 * Template based auto-boxing ValueExtractor implementation.
00034 *
00035 * This extractor functions on const methods which return unmanaged types for
00036 * which there is a corresponding the is a managed type which can "box"
00037 * them via a BoxHandle.
00038 *
00039 * For ease of use the COH_BOX_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 "int32_t Address::getZip() const" method.
00042 *
00043 * @code
00044 * ValueExtractor::View vExt = COH_BOX_EXTRACTOR(Integer32::View, Address, getZip);
00045 * @endcode
00046 *
00047 * In the case that the supplied class does not extend from Object and instead
00048 * relies on the Managed<> wrapper, the COH_MANAGED_BOX_EXTRACTOR is to be
00049 * used.
00050 *
00051 * @author mf 2009.03.20
00052 *
00053 * @see TypedExtractor
00054 */
00055 template<class RH, class C, typename RH::ValueType::BoxedType (C::*M)() const,
00056     class OH = typename C::Holder>
00057 class BoxExtractor
00058     : public class_spec<BoxExtractor<RH, C, M, OH>,
00059         extends<TypedExtractor<typename RH::ValueType::BoxedType, C, M,
00060             BoxHandle<typename RH::ValueType>, OH> > >
00061     {
00062     friend class factory<BoxExtractor<RH, C, M, OH> >;
00063 
00064     // ----- constructors ---------------------------------------------------
00065 
00066     protected:
00067         /**
00068         * Construct a BoxExtractor
00069         */
00070         BoxExtractor()
00071             {
00072             }
00073 
00074         /**
00075         * Construct a BoxExtractor based on a method name and optional
00076         * parameters.
00077         *
00078         * The method name is only used for the purposes of serializing the
00079         * extractor for execution on remote Java members.
00080         *
00081         * @param vsMethod  the name of the method to invoke via reflection
00082         */
00083         BoxExtractor(String::View vsMethod)
00084             : class_spec<BoxExtractor<RH, C, M, OH>,
00085             extends<TypedExtractor<typename RH::ValueType::BoxedType, C, M,
00086                 BoxHandle<typename RH::ValueType>, OH> > >(vsMethod)
00087             {
00088             }
00089     };
00090 
00091 COH_CLOSE_NAMESPACE3
00092 
00093 /**
00094 * Helper macro for creating a BoxExtractor.
00095 *
00096 * @param H  the handle type to box to, i.e. Integer32::View
00097 * @param C  the class to call the method on, i.e. Address
00098 * @param M  the method to call, i.e. getZip
00099 */
00100 #define COH_BOX_EXTRACTOR(H, C, M) \
00101     coherence::util::extractor::BoxExtractor<H, C, &C::M>::create(#M)
00102 
00103 /**
00104 * Helper macro for creating a BoxExtractor around a Managed<> wrapped class.
00105 *
00106 * @param H  the handle type to box to, i.e. Integer32::View
00107 * @param C  the Managed<> wrapped class to call the method on, i.e. Address
00108 * @param M  the method to call, i.e. getZip
00109 */
00110 #define COH_MANAGED_BOX_EXTRACTOR(H, C, M) \
00111     coherence::util::extractor::BoxExtractor<H, C, &C::M, \
00112         coherence::lang::Managed<C>::Holder>::create(#M)
00113 
00114 #endif // COH_BOX_EXTRACTOR_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.