• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

meta_accumulator.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_CONCEPT_META_ACCUMULATOR_HH
00028 # define MLN_CORE_CONCEPT_META_ACCUMULATOR_HH
00029 
00033 
00034 # include <mln/core/concept/object.hh>
00035 # include <mln/core/concept/accumulator.hh>
00036 
00037 
00038 # define mln_accu_with(A, T) \
00039 typename mln::internal::accu_with_helper<A,T>::ret
00040 
00041 # define mln_accu_with_(A, T) \
00042 mln::internal::accu_with_helper<A,T>::ret
00043 
00044 
00045 # define mln_meta_accu_result(A, T) \
00046 typename mln::internal::meta_accu_ret_result_helper<A,T>::result
00047 
00048 
00049 # define mln_meta_accu_result_(A, T)                            \
00050 mln::internal::meta_accu_ret_result_helper<A,T>::result
00051 
00052 
00053 
00054 
00055 namespace mln
00056 {
00057 
00058   // Forward declaration.
00059   template <typename E> struct Meta_Accumulator;
00060 
00061 
00062   namespace internal
00063   {
00064 
00067     //
00068     template <typename A, typename T>
00069     struct meta_accu_ret_result_helper
00070     {
00071         typedef typename A::template with< T >::ret::result result;
00072     };
00073 
00074 
00077     //
00078     template <typename A, typename T>
00079     struct accu_with_helper
00080     {
00081         typedef typename A::template with< T >::ret ret;
00082     };
00083 
00084 
00085   } // end of namespace mln::internal
00086 
00087 
00088   // Meta_Accumulator category flag type.
00089   template <>
00090   struct Meta_Accumulator<void>
00091   {
00092     typedef Object<void> super;
00093   };
00094 
00102   template <typename E>
00103   struct Meta_Accumulator : public Object<E>
00104   {
00105     typedef Meta_Accumulator<void> category;
00106   protected:
00107     Meta_Accumulator();
00108   };
00109 
00110 
00111   namespace accu
00112   {
00113 
00114     // To be specialized when some state (attributes) have to be transfered
00115     // from the meta-accumulator to the accumulator.
00116     // Warning: the first argument has to be an object with the exact type.
00117     template <typename M, typename T>
00118     mln_accu_with(M, T)
00119     unmeta(const M&, T);
00120 
00121     template <typename M, typename T>
00122     void
00123     unmeta(const Meta_Accumulator<M>&, T); // Safety.
00124 
00125   } // end of namespace mln::accu
00126 
00127 
00128 
00129 # ifndef MLN_INCLUDE_ONLY
00130 
00131   template <typename E>
00132   inline
00133   Meta_Accumulator<E>::Meta_Accumulator()
00134   {
00135     // FIXME: Check "with" on E.
00136   }
00137 
00138   namespace accu
00139   {
00140 
00141     template <typename M, typename T>
00142     inline
00143     mln_accu_with(M, T)
00144     unmeta(const M&, T)
00145     {
00146       mlc_is_a(M, Meta_Accumulator)::check();
00147       mln_accu_with(M, T) a;
00148       return a;
00149     }
00150 
00151   } // end of namespace mln::accu
00152 
00153 # endif // ! MLN_INCLUDE_ONLY
00154 
00155 } // end of namespace mln
00156 
00157 
00158 #endif // ! MLN_CORE_CONCEPT_META_ACCUMULATOR_HH

Generated on Tue Oct 4 2011 15:24:06 for Milena (Olena) by  doxygen 1.7.1