struct_elt.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_STRUCT_ELT_HH
00029 # define OLENA_CORE_STRUCT_ELT_HH
00030 
00031 # include <mlc/type.hh>
00032 # include <oln/core/coord.hh>
00033 # include <oln/core/abstract/dpoint.hh>
00034 
00035 namespace oln {
00036 
00037   namespace abstract {
00038     template<class Exact>
00039     struct struct_elt; // forwarding declaration
00040 
00041   } // end of abstract
00042 
00043   template<class Exact>
00044   struct struct_elt_traits;
00045 
00049   template<class Exact>
00050   struct struct_elt_traits<abstract::struct_elt<Exact> >
00051   {
00052     typedef abstract::struct_elt<Exact> abstract_type;
00054   };
00055 
00056   namespace abstract {
00057 
00064     template<class Exact>
00065     struct struct_elt : public mlc_hierarchy::any< Exact >
00066     {
00067       enum { dim = struct_elt_traits<Exact>::dim };
00069 
00070       typedef struct_elt<Exact> self_type;
00072       typedef typename struct_elt_traits<Exact>::abstract_type abstract_type;
00074 
00076       static std::string
00077       name()
00078       {
00079         return std::string("struct_elt<") + Exact::name() + ">";
00080       }
00081 
00082       typedef typename struct_elt_traits<Exact>::point_type point_type;
00084       typedef typename struct_elt_traits<Exact>::dpoint_type dpoint_type;
00086       typedef Exact exact_type;
00087 
00093       bool
00094       has(const abstract::dpoint<dpoint_type>& dp) const
00095       {
00096         return this->exact().has_(dp.exact());
00097       }
00098 
00103       unsigned
00104       card() const
00105       {
00106         return this->exact().card_();
00107       }
00108 
00115       bool
00116       is_centered() const
00117       {
00118         return this->exact().is_centered_();
00119       }
00120 
00129       exact_type&
00130       add(const abstract::dpoint<dpoint_type>& dp)
00131       {
00132         return this->exact().add_dp(dp);
00133       }
00134 
00140       dpoint_type
00141       dp(unsigned i) const
00142       {
00143         return this->exact().at(i);
00144       }
00145 
00151       bool
00152       operator==(const self_type& win) const
00153       {
00154         return this->exact().is_equal(win.exact());
00155       }
00156 
00163       coord
00164       delta() const
00165       {
00166         return this->exact().get_delta();
00167       }
00168 
00174       const dpoint_type
00175       operator[](unsigned i) const
00176       {
00177         return this->exact().at(i);
00178       }
00179 
00185       exact_type
00186       operator-() const
00187       {
00188         exact_type win(this->exact());
00189         win.sym();
00190         return win;
00191       }
00192 
00193     protected:
00194 
00200       void
00201       sym()
00202       {
00203         return this->exact().sym_();
00204       }
00205 
00209       struct_elt()
00210       {}
00211 
00212     };
00213   } // end of abstract
00214 
00215 } // end of oln
00216 
00217 #endif // ! OLENA_CORE_STRUCT_ELT_HH

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