Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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_ACCU_P_HH 00027 # define MLN_ACCU_P_HH 00028 00032 00033 # include <mln/core/concept/meta_accumulator.hh> 00034 00035 # include <mln/accu/internal/base.hh> 00036 # include <mln/metal/is_a.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 namespace accu 00043 { 00044 00045 00049 template <typename A> 00050 struct p : public mln::accu::internal::base< const mln_result(A)& , p<A> > 00051 { 00052 typedef mln_argument(A) argument; 00053 00054 p(); 00055 p(const A& a); 00056 00059 void init(); 00060 void take_as_init_(const argument& t); 00061 void take(const argument& t); 00062 void take(const p<A>& other); 00064 00066 const mln_result(A)& to_result() const; 00067 00070 bool is_valid() const; 00071 00072 protected: 00073 A a_; 00074 }; 00075 00076 00077 namespace meta 00078 { 00079 00081 00082 template <typename mA> 00083 struct p : public Meta_Accumulator< p<mA> > 00084 { 00085 template <typename V> 00086 struct with 00087 { 00088 typedef p<V> ret; 00089 }; 00090 }; 00091 00092 } // end of namespace mln::accu::meta 00093 00094 00095 # ifndef MLN_INCLUDE_ONLY 00096 00097 template <typename A> 00098 inline 00099 p<A>::p() 00100 { 00101 init(); 00102 } 00103 00104 template <typename A> 00105 inline 00106 p<A>::p(const A& a) 00107 : a_(a) 00108 { 00109 init(); 00110 } 00111 00112 template <typename A> 00113 inline 00114 void 00115 p<A>::init() 00116 { 00117 a_.init(); 00118 } 00119 00120 template <typename A> 00121 inline 00122 void 00123 p<A>::take_as_init_(const argument& t) 00124 { 00125 a_.take_as_init_(t.p()); // FIXME: Generalize with "psite(t)". 00126 } 00127 00128 template <typename A> 00129 inline 00130 void 00131 p<A>::take(const argument& t) 00132 { 00133 a_.take(t.p()); 00134 } 00135 00136 template <typename A> 00137 inline 00138 void 00139 p<A>::take(const p<A>& other) 00140 { 00141 a_.take(other.a_); 00142 } 00143 00144 template <typename A> 00145 inline 00146 const mln_result(A)& 00147 p<A>::to_result() const 00148 { 00149 return a_.to_result(); 00150 } 00151 00152 template <typename A> 00153 inline 00154 bool 00155 p<A>::is_valid() const 00156 { 00157 return a_.is_valid(); 00158 } 00159 00160 # endif // ! MLN_INCLUDE_ONLY 00161 00162 } // end of namespace mln::accu 00163 00164 } // end of namespace mln 00165 00166 00167 #endif // ! MLN_ACCU_P_HH