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

E47891-01

coherence/lang/SubscriptHandle.hpp

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