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
00027
00028 #ifndef OLENA_CORE_ABSTRACT_W_WINDOWND_HH
00029 # define OLENA_CORE_ABSTRACT_W_WINDOWND_HH
00030
00031 # include <oln/core/abstract/window_base.hh>
00032
00033 namespace oln {
00034
00035 namespace abstract {
00036 template<class Exact>
00037 struct w_windownd;
00038 }
00039
00043 template<class Exact>
00044 struct struct_elt_traits<abstract::w_windownd<Exact> >: public
00045 struct_elt_traits<abstract::window_base<abstract::w_window<Exact>, Exact> >
00046 {
00047
00048 };
00049
00050 namespace abstract {
00051
00058 template<class Exact>
00059 struct w_windownd: public window_base<w_window<Exact>, Exact>
00060 {
00061 typedef window_base<abstract::w_window<Exact>, Exact> super_type;
00063 typedef w_windownd<Exact> self_type;
00064 typedef Exact exact_type;
00065 typedef typename struct_elt_traits<Exact>::weight_type weight_type;
00067
00073 typedef typename struct_elt_traits<Exact>::dpoint_type dpoint_type;
00074
00075 friend class w_window<exact_type>;
00076
00078 static std::string
00079 name()
00080 {
00081 return std::string("w_windownd<") + Exact::name() + ">" ;
00082 }
00083
00084 protected:
00085
00092 weight_type
00093 get_weight(unsigned i) const
00094 {
00095 precondition(i < this->card());
00096 return w_[i];
00097 }
00098
00107 exact_type&
00108 add_(const dpoint_type& dp, const weight_type& w)
00109 {
00110 precondition(! has_(dp));
00111 if (w == 0)
00112 return this->exact();
00113 if (dp.is_centered())
00114 this->centered_ = true;
00115 this->dp_.push_back(dp);
00116 delta_update(dp);
00117 w_.push_back(w);
00118 return this->exact();
00119 }
00120
00128 const weight_type&
00129 set_(const dpoint_type& dp, const weight_type& w)
00130 {
00131
00132 for (unsigned i = 0; i < this->card_(); ++i)
00133 if (this->dp_[i] == dp)
00134 {
00135 w_[i] = w;
00136 return w_[i];
00137 }
00138
00139
00140 add(dp, w);
00141 return w_.back();
00142 }
00143
00147 w_windownd() : super_type()
00148 {}
00149
00154 w_windownd(unsigned size) : super_type(size)
00155 {
00156 w_.reserve(size);
00157 }
00158
00159 std::vector< weight_type > w_;
00160
00161 };
00162 }
00163 }
00164
00174 template<class Exact>
00175 std::ostream&
00176 operator<<(std::ostream& o, const oln::abstract::w_windownd<Exact>& w)
00177 {
00178 unsigned c = w.card();
00179 o << "[";
00180 for (unsigned i = 0; i < c; ++i)
00181 o << "(" << w.dp(i) << "," << w.w(i) << ")";
00182 o << "]";
00183 return o;
00184 }
00185
00186 #endif // OLENA_CORE_ABSTRACT_W_WINDOWND_HH