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

E80355-01

coherence/stl/boxing_map.hpp

00001 /*
00002 * boxing_map.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_BOXING_MAP_HPP
00017 #define COH_BOXING_MAP_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/stl/adapter_map.hpp"
00022 
00023 
00024 
00025 COH_OPEN_NAMESPACE2(coherence,stl)
00026 
00027 
00028 /**
00029 * boxing_map provides an STL-like map adapter around a coherence::util::map,
00030 * and additionally auto-boxes the keys and values to their corresponding
00031 * non-managed types. The key and value template parameters specify the managed
00032 * class which will be stored in the Map. Other then the definition, the access
00033 * to the keys and values may use either the managed view type or the
00034 * corresponding unmanaged type. This also allows for easy copying of mapped
00035 * entries from a std::map to coherence maps and caches.
00036 *
00037 * @code
00038 * boxing_map<Managed<Foo>, Managed<Bar> > mycache
00039 *         (CacheFactory::getCache("mycache")); // declare boxing adapter
00040 *
00041 * Foo foo(...); // initialize non-managed object Foo
00042 * Bar bar(...); // initialize non-managed object Bar
00043 *
00044 * mycache[foo] = bar;         // insert directly into cache via auto-boxing
00045 * Bar barRead = mycache[foo]; // read from cache using auto-boxing
00046 *
00047 * std::map<Foo, Bar> mymap;
00048 * mymap.insert(mycache.begin(), mycache.end()); // copy from coherence to STL
00049 * mycache.insert(mymap.begin(), mymap.end());   // copy from STL to coherence
00050 * @endcode
00051 *
00052 * @see coherence::util::TypedCollections::TypedMap for an Object based equivalent
00053 *
00054 * @author mf  2008.06.02
00055 */
00056 template<class K, class V>
00057 class boxing_map
00058         : public adapter_map<BoxHandle<const K, typename K::BoxedType, false>,
00059                              BoxHandle<const V, typename V::BoxedType, false> >
00060     {
00061     // ----- typedefs -------------------------------------------------------
00062 
00063     public:
00064         /**
00065         * Super type
00066         */
00067         typedef adapter_map<BoxHandle<const K, typename K::BoxedType, false>,
00068                             BoxHandle<const V, typename V::BoxedType, false> >
00069                 super;
00070 
00071 
00072     // ----- constructor ----------------------------------------------------
00073 
00074     public:
00075         /**
00076         * Create new boxing_map from the given Coherence Map.
00077         *
00078         * @param ohMap the Map to be delegated by the boxing_map.
00079         */
00080         boxing_map(Map::Holder ohMap = NULL)
00081             : super(ohMap)
00082             {
00083             }
00084 
00085         /**
00086         * Create a boxing_map copy. The new boxing_map will reference the
00087         * same Map, as the original boxing_map.
00088         */
00089         boxing_map(const boxing_map& that)
00090             : super(that)
00091             {
00092             }
00093 
00094 
00095     // ----- operators ------------------------------------------------------
00096 
00097     public:
00098         /**
00099         * Reassign this boxing_map to reference the same Map as another
00100         * boxing_map.
00101         */
00102         boxing_map& operator=(const boxing_map& that)
00103             {
00104             super::operator=(that);
00105             return *this;
00106             }
00107 
00108         /**
00109         * Reassign this boxing_map to reference another Map.
00110         */
00111         boxing_map& operator=(Map::Holder ohMap)
00112             {
00113             super::operator=(ohMap);
00114             return *this;
00115             }
00116     };
00117 
00118 COH_CLOSE_NAMESPACE2
00119 
00120 #endif // COH_BOXING_MAP_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.