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

E26041-01

coherence/lang/SubscriptHolder.hpp

00001 /*
00002 * SubscriptHolder.hpp
00003 *
00004 * Copyright (c) 2000, 2013, 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_SUBSCRIPT_HOLDER_HPP
00017 #define COH_SUBSCRIPT_HOLDER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/TypedHandle.hpp"
00022 #include "coherence/lang/TypedHolder.hpp"
00023 
00024 COH_OPEN_NAMESPACE2(coherence,lang)
00025 
00026 
00027 /**
00028 * A TypedHolder implementation which supports automatic delegation of the
00029 * subscript operator.
00030 *
00031 * @author mf  2009.03.10
00032 */
00033 template<class T, class ET, class IT = size32_t>
00034 class SubscriptHolder
00035     : public TypedHolder<T>
00036     {
00037     // ----- typedefs -------------------------------------------------------
00038 
00039     typedef ET ElementType;
00040 
00041 
00042     // ----- constructors ---------------------------------------------------
00043 
00044     public:
00045         /**
00046         * Create an empty SubscriptHolder.
00047         */
00048         SubscriptHolder()
00049             : TypedHolder<T>()
00050             {
00051             }
00052 
00053         /**
00054         * Create a new SubscriptHolder from the TypedHandle with a type
00055         * conversion.
00056         */
00057         template<class DT> SubscriptHolder<T, ET, IT>(const TypedHandle<DT>& that)
00058             : TypedHolder<T>(that)
00059             {
00060             }
00061 
00062         /**
00063         * Create a new SubscriptHolder from the TypedHolder with a type
00064         * conversion.
00065         */
00066         template<class DT> SubscriptHolder<T, ET, IT>(const TypedHolder<DT>& that)
00067             : TypedHolder<T>(that)
00068             {
00069             }
00070 
00071         /**
00072         * Create a new SubscriptHolder from the raw pointer.
00073         */
00074         SubscriptHolder(T* o)
00075             : TypedHolder<T>(o)
00076             {
00077             }
00078 
00079         /**
00080         * The copy constructor.
00081         */
00082         SubscriptHolder<T, ET, IT>(const SubscriptHolder<T, ET, IT>& that)
00083             : TypedHolder<T>(that)
00084             {
00085             }
00086 
00087         /**
00088         * The subscript operator.
00089         */
00090         ElementType& operator[](IT i) const
00091             {
00092             const T* cpo = TypedHolder<T>::m_cpo;
00093             if (NULL == cpo)
00094                 {
00095                 coh_throw_npe(typeid(T));
00096                 }
00097             return (*cpo)[i];
00098             }
00099     };
00100 
00101 COH_CLOSE_NAMESPACE2
00102 
00103 #endif // COH_SUBSCRIPT_HOLDER_HPP
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.