00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_CORE_ROUTINE_PRIMARY_HH 00027 # define MLN_CORE_ROUTINE_PRIMARY_HH 00028 00035 00036 # include <mln/core/concept/image.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 // Forward declaration. 00043 namespace internal 00044 { 00045 template <typename I> struct primary_type; 00046 } 00047 00048 00050 template <typename I> 00051 const typename internal::primary_type<I>::ret& 00052 primary(const Image<I>& input); 00053 00054 00055 00056 # ifndef MLN_INCLUDE_ONLY 00057 00058 00059 namespace internal 00060 { 00061 00062 // Primary_type. 00063 00064 template <typename I> struct primary_type; 00065 00066 template <typename I, typename C> 00067 struct primary_type_helper 00068 { 00069 typedef typename I::delegatee D; 00070 typedef typename primary_type<D>::ret ret; 00071 }; 00072 00073 template <typename I> 00074 struct primary_type_helper< I, mln::trait::image::category::primary > 00075 { 00076 typedef I ret; 00077 }; 00078 00079 template <typename I> 00080 struct primary_type 00081 { 00082 typedef mln_trait_image_category(I) Cat; 00083 typedef typename primary_type_helper<I, Cat>::ret ret; 00084 }; 00085 00086 00087 // Routine. 00088 00089 template <typename I> 00090 const typename internal::primary_type<I>::ret& 00091 primary_(const Image<I>& input); // Forward declaration. 00092 00093 template <typename I> 00094 inline 00095 const typename internal::primary_type<I>::ret& 00096 primary_(trait::image::category::primary, 00097 const Image<I>& input) 00098 { 00099 return exact(input); 00100 } 00101 00102 template <typename I> 00103 inline 00104 const typename internal::primary_type<I>::ret& 00105 primary_(trait::image::category::morpher, 00106 const Image<I>& input) 00107 { 00108 return primary_(exact(input).unmorph_()); 00109 } 00110 00111 template <typename I> 00112 inline 00113 const typename internal::primary_type<I>::ret& 00114 primary_(const Image<I>& input) 00115 { 00116 return primary_(mln_trait_image_category(I)(), 00117 input); 00118 } 00119 00120 } // end of namespace mln::internal 00121 00122 00123 00124 // Facade. 00125 00126 template <typename I> 00127 inline 00128 const typename internal::primary_type<I>::ret& 00129 primary(const Image<I>& input) 00130 { 00131 mln_precondition(exact(input).is_valid()); 00132 return internal::primary_(input); 00133 } 00134 00135 00136 # endif // ! MLN_INCLUDE_ONLY 00137 00138 } // end of namespace mln 00139 00140 00141 #endif // ! MLN_CORE_ROUTINE_PRIMARY_HH