ViennaGrid - The Vienna Grid Library  2.1.0
viennagrid/storage/collection.hpp
Go to the documentation of this file.
00001 #ifndef VIENNAGRID_STORAGE_COLLECTION_HPP
00002 #define VIENNAGRID_STORAGE_COLLECTION_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    License:      MIT (X11), see file LICENSE in the base directory
00014 ======================================================================= */
00015 
00016 #include "viennagrid/meta/utils.hpp"
00017 #include "viennagrid/meta/typemap.hpp"
00018 
00023 namespace viennagrid
00024 {
00025   namespace detail
00026   {
00027 
00028     template<typename typemap>
00029     class collection_layer;
00030 
00031 
00032 
00033     template<typename key_, typename value_, typename tail>
00034     class collection_layer< viennagrid::typelist< viennagrid::static_pair<key_, value_> , tail> > : public collection_layer<tail>
00035     {
00036     public:
00037       typedef collection_layer< tail > base;
00038       typedef key_ key_type;
00039       typedef value_ value_type;
00040 
00041       using base::get;
00042       value_type & get( viennagrid::detail::tag<key_type> ) { return element; }
00043       const value_type & get( viennagrid::detail::tag<key_type> ) const { return element; }
00044 
00045     private:
00046       value_type element;
00047     };
00048 
00049     template<>
00050     class collection_layer< viennagrid::null_type >
00051     {
00052     public:
00053       void get();
00054     };
00055 
00056   }
00057 
00062   template<typename typemap_>
00063   class collection : public detail::collection_layer< typemap_ >
00064   {
00065   public:
00066     typedef typemap_ typemap;
00067     typedef detail::collection_layer< typemap > base;
00068 
00069     using base::get;
00070   private:
00071   };
00072 
00073 //   namespace result_of
00074 //   {
00075 //     template<typename typemap>
00076 //     struct collection
00077 //     {
00078 //         typedef viennagrid::collection<typemap> type;
00079 //     };
00080 //   } // namespace result_of
00081 
00082 
00083   namespace detail
00084   {
00085     namespace result_of
00086     {
00087       template<typename typemap, typename key_type>
00088       struct lookup< viennagrid::collection<typemap>, key_type >
00089       {
00090         typedef typename viennagrid::detail::result_of::lookup<typemap, key_type>::type type;
00091       };
00092     }
00093   }
00094 
00095 
00101   template<typename KeyTypeT, typename TypeMapT>
00102   typename viennagrid::detail::result_of::lookup<TypeMapT, typename viennagrid::detail::remove_const<KeyTypeT>::type >::type & get( collection<TypeMapT> & c )
00103   {
00104     return c.get( viennagrid::detail::tag< typename viennagrid::detail::remove_const<KeyTypeT>::type >() );
00105   }
00106 
00112   template<typename KeyTypeT, typename TypeMapT>
00113   typename viennagrid::detail::result_of::lookup<TypeMapT, typename viennagrid::detail::remove_const<KeyTypeT>::type >::type const & get( collection<TypeMapT> const & c )
00114   {
00115     return c.get( viennagrid::detail::tag< typename viennagrid::detail::remove_const<KeyTypeT>::type >() );
00116   }
00117 
00118 
00119 } // namespace viennagrid
00120 
00121 #endif