w_windownd.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
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; // forward declaration
00038   } // end of abstract
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)             // Don't add 0 weighted entries
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         // if the dp exists, return a ref to the existing entry
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         // otherwise, create new entry
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   } // end of abstract
00163 } // end of oln
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

Generated on Thu Apr 15 20:13:15 2004 for Olena by doxygen 1.3.6-20040222