ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_STORAGE_ID_GENERATOR_HPP 00002 #define VIENNAGRID_STORAGE_ID_GENERATOR_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/forwards.hpp" 00017 #include "viennagrid/meta/typelist.hpp" 00018 #include "viennagrid/meta/typemap.hpp" 00019 #include "viennagrid/storage/id.hpp" 00020 #include "viennagrid/config/config.hpp" 00021 00026 namespace viennagrid 00027 { 00028 namespace detail 00029 { 00030 namespace result_of 00031 { 00032 template<typename typelist, typename id_type> 00033 struct continuous_id_generator_config_helper; 00034 00036 template<typename head, typename tail, typename id_type> 00037 struct continuous_id_generator_config_helper< viennagrid::typelist<head, tail>, id_type > 00038 { 00039 typedef typename viennagrid::detail::result_of::insert< 00040 typename continuous_id_generator_config_helper<tail, id_type>::type, 00041 viennagrid::static_pair< 00042 head, 00043 id_type 00044 > 00045 >::type type; 00046 }; 00047 00048 template<typename id_type> 00049 struct continuous_id_generator_config_helper<viennagrid::null_type, id_type> 00050 { 00051 typedef viennagrid::null_type type; 00052 }; 00053 00054 00055 template<typename WrappedConfigType, typename typemap> 00056 struct continuous_id_generator_config_from_mesh_config_helper; 00057 00058 template<typename WrappedConfigType, typename element_tag, typename element_config, typename tail> 00059 struct continuous_id_generator_config_from_mesh_config_helper< WrappedConfigType, viennagrid::typelist<viennagrid::static_pair<element_tag, element_config>, tail> > 00060 { 00061 typedef typename viennagrid::detail::result_of::insert< 00062 typename continuous_id_generator_config_from_mesh_config_helper<WrappedConfigType, tail>::type, 00063 viennagrid::static_pair< 00064 viennagrid::element<element_tag, WrappedConfigType>, 00065 // typename viennagrid::result_of::element<mesh_config, element_tag>::type, 00066 typename config::result_of::query<element_config, viennagrid::smart_id_tag<int>, config::element_id_tag>::type 00067 // typename element_config::element_config::id_tag 00068 > 00069 >::type type; 00070 }; 00071 00072 template<typename WrappedConfigType> 00073 struct continuous_id_generator_config_from_mesh_config_helper<WrappedConfigType, viennagrid::null_type> 00074 { 00075 typedef viennagrid::null_type type; 00076 }; 00077 00078 template<typename typelist, typename id_type> 00079 struct continuous_id_generator_config 00080 { 00081 typedef typename continuous_id_generator_config_helper< 00082 typename viennagrid::detail::result_of::no_duplicates<typelist>::type, 00083 id_type 00084 >::type type; 00085 }; 00086 00087 template<typename WrappedConfigType> 00088 struct continuous_id_generator_config_from_mesh_config 00089 { 00090 typedef typename continuous_id_generator_config_from_mesh_config_helper<WrappedConfigType, typename WrappedConfigType::type>::type type; 00091 }; 00092 00094 } 00095 00096 00097 00098 00099 template<typename id_generator_config> 00100 class continuous_id_generator_layer; 00101 00102 template<typename value_type, typename id_tag, typename tail> 00103 class continuous_id_generator_layer<viennagrid::typelist< viennagrid::static_pair<value_type, id_tag>, tail> > : public continuous_id_generator_layer<tail> 00104 { 00105 typedef continuous_id_generator_layer<tail> base; 00106 public: 00107 00108 typedef viennagrid::typelist< viennagrid::static_pair<value_type, id_tag>, tail> config_type; 00109 00110 typedef typename result_of::make_id<value_type, id_tag>::type id_type; 00111 00112 continuous_id_generator_layer() : base(), last_id(0) {} 00113 00114 using base::operator(); 00115 id_type operator()( viennagrid::detail::tag<value_type> ) 00116 { 00117 return last_id++; 00118 } 00119 00120 using base::set_max_id; 00121 void set_max_id( id_type last_id_ ) 00122 { 00123 if (last_id_ > last_id) 00124 { 00125 last_id = last_id_; 00126 ++last_id; 00127 } 00128 } 00129 00130 using base::max_id; 00131 id_type max_id( viennagrid::detail::tag<value_type> ) const 00132 { 00133 return last_id; 00134 } 00135 00136 private: 00137 id_type last_id; 00138 }; 00139 00140 template<> 00141 class continuous_id_generator_layer<viennagrid::null_type> 00142 { 00143 public: 00144 void operator()(); 00145 void set_max_id(); 00146 void max_id() const; 00147 }; 00148 00149 } 00150 00155 template<typename typemap> 00156 class continuous_id_generator : public detail::continuous_id_generator_layer< typemap > 00157 {}; 00158 00159 namespace result_of 00160 { 00162 template<typename typemap> 00163 struct continuous_id_generator 00164 { 00165 typedef viennagrid::continuous_id_generator< typemap > type; 00166 }; 00168 } 00169 } 00170 00171 #endif