00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_UTIL_INTERNAL_ID2ELEMENT_HH
00027 # define MLN_UTIL_INTERNAL_ID2ELEMENT_HH
00028 
00032 
00033 #include <mln/core/concept/graph.hh>
00034 #include <mln/core/concept/function.hh>
00035 
00036 namespace mln
00037 {
00038 
00039   namespace util
00040   {
00041 
00042     namespace internal
00043     {
00044 
00045       template <typename G, typename Elt>
00046       struct id2element : Function_v2v< id2element<G,Elt> >
00047       {
00048         typedef Elt result;
00049 
00050         id2element();
00051         id2element(const Graph<G>& g);
00052         Elt operator()(unsigned id) const;
00053 
00054         G g_;
00055       };
00056 
00057 
00058 # ifndef MLN_INCLUDE_ONLY
00059 
00060       template <typename G, typename Elt>
00061       inline
00062       id2element<G,Elt>::id2element()
00063       {
00064       }
00065 
00066       template <typename G, typename Elt>
00067       inline
00068       id2element<G,Elt>::id2element(const Graph<G>& g)
00069         : g_(exact(g))
00070       {
00071       }
00072 
00073       template <typename G, typename Elt>
00074       inline
00075       Elt
00076       id2element<G,Elt>::operator()(unsigned id) const
00077       {
00078         mln_assertion(g_.is_valid());
00079         mln_assertion(g_.has(Elt(g_,id)));
00083         return Elt(g_, id);
00084       }
00085 
00086 
00087 # endif // ! MLN_INCLUDE_ONLY
00088 
00089 
00090     } 
00091 
00092   } 
00093 
00094 } 
00095 
00096 
00097 #endif // ! MLN_UTIL_INTERNAL_ID2ELEMENT_HH