image_with_type_with_dim.hh

00001 // Copyright (C) 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, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, 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_IMAGE_WITH_TYPE_WITH_DIM_HH
00029 # define OLENA_CORE_ABSTRACT_IMAGE_WITH_TYPE_WITH_DIM_HH
00030 
00031 # include <mlc/bool.hh>
00032 # include <ntg/basics.hh>
00033 
00034 # include <oln/core/abstract/image_with_type.hh>
00035 # include <oln/core/abstract/image_with_dim.hh>
00036 
00037 // oln_label_image_(Name, Super)
00038 // Define a type label image This macro create two classes,
00039 // Name<Exact> and Name##_with_dim<N, Exact>.  Super is used to
00040 // determine the parent class of Name##_with_dim and is suffixed with
00041 // _with_dim.
00042 
00043 
00044 # define oln_label_image_(Name, Super)                          \
00045   template <class Exact>                                        \
00046   class Name                                                    \
00047     : virtual public Super<Exact>                               \
00048   {                                                             \
00049   public:                                                       \
00050     typedef Name<Exact> self_type;                              \
00051     typedef Exact exact_type;                                   \
00052                                                                 \
00053     exact_type&                                                 \
00054     operator=(self_type rhs)                                    \
00055     {                                                           \
00056       return this->exact().assign(rhs.exact());                 \
00057     }                                                           \
00058                                                                 \
00059     static std::string                                          \
00060     name()                                                      \
00061     {                                                           \
00062       return                                                    \
00063         std::string(#Name "<")                                  \
00064         + Exact::name() + ">";                                  \
00065     }                                                           \
00066   };                                                            \
00067                                                                 \
00068   template <unsigned Dim, class Exact>                          \
00069   class Name##_with_dim                                         \
00070     : virtual public Name<Exact>,                               \
00071       virtual public Super##_with_dim<Dim, Exact>               \
00072   {                                                             \
00073   public:                                                       \
00074     typedef Name##_with_dim<Dim, Exact> self_type;              \
00075     typedef Exact exact_type;                                   \
00076                                                                 \
00077     exact_type&                                                 \
00078     operator=(self_type rhs)                                    \
00079     {                                                           \
00080       return this->exact().assign(rhs.exact());                 \
00081     }                                                           \
00082                                                                 \
00083     static std::string                                          \
00084     name()                                                      \
00085     {                                                           \
00086       std::ostringstream s;                                     \
00087       s << #Name "_with_dim<"                                   \
00088         << Dim << ", "                                          \
00089         << Exact::name() << ">";                                \
00090       return s.str();                                           \
00091     }                                                           \
00092   };
00093 
00094 namespace oln {
00095 
00096   namespace abstract {
00097 
00098 
00099     // The label images here were defined because they appeared to be
00100     // quite handy. They are different than using image_with_type<T>,
00101     // because it handle categories of types, not only one.
00102     //
00103     // With each label image, another label_with_dim<Dim, Exact> class
00104     // is defined.
00105     //
00106     // Proxy towards image_with_type
00107 
00114     template <class Exact>
00115     struct data_type_image
00116       : virtual public image_with_type<typename image_id<Exact>::value_type, Exact>
00117     {
00118     public:
00119 
00120       typedef data_type_image<Exact> self_type;
00121       typedef Exact exact_type;
00122 
00131       exact_type&
00132       operator=(self_type rhs)
00133       {
00134         return this->exact().assign(rhs.exact());
00135       }
00136 
00137       static std::string
00138       name()
00139       {
00140         return
00141           std::string("abstract::data_type_image<")
00142           + Exact::name() + ">";
00143       }
00144     };
00145 
00155     template <unsigned Dim, class Exact>
00156     struct data_type_image_with_dim :
00157       virtual public data_type_image<Exact>,
00158       virtual public image_with_dim<Dim, Exact>
00159     {
00160     public:
00161 
00162       typedef data_type_image<Exact> self_type;
00163       typedef Exact exact_type;
00164 
00172       exact_type&
00173       operator=(self_type rhs)
00174       {
00175         return this->exact().assign(rhs.exact());
00176       }
00177 
00178       static std::string
00179       name()
00180       {
00181         return
00182           std::string("abstract::data_type_image<")
00183           + Exact::name() + ">";
00184       }
00185     };
00186 
00191     oln_label_image_(vectorial_image, data_type_image)
00192 
00193     
00205     oln_label_image_(non_vectorial_image, data_type_image)
00206 
00221     oln_label_image_(binary_image, non_vectorial_image)
00222 
00237     oln_label_image_(integer_image, non_vectorial_image)
00238 
00253     oln_label_image_(decimal_image, non_vectorial_image)
00254 
00271     template<class Exact>
00272     struct image_with_type_with_dim_switch
00273     {
00274       enum { Dim = image_id<Exact>::dim };
00275 
00276       typedef typename image_id<Exact>::value_type T;
00277 
00278 
00279 
00280       typedef typename mlc::bool_switch_<
00281 
00282         mlc::bool_case_<ntg_is_a(T, ntg::binary)::ret,
00283                         binary_image_with_dim<Dim, Exact>,
00284 
00285         mlc::bool_case_<ntg_is_a(T, ntg::integer)::ret,
00286                         integer_image_with_dim<Dim, Exact>,
00287 
00288         mlc::bool_case_<ntg_is_a(T, ntg::decimal)::ret,
00289                         decimal_image_with_dim<Dim, Exact>,
00290 
00291         mlc::bool_case_<ntg_is_a(T, ntg::vectorial)::ret,
00292                         vectorial_image_with_dim<Dim, Exact>,
00293 
00294         mlc::bool_case_<ntg_is_a(T, ntg::non_vectorial)::ret,
00295                         non_vectorial_image_with_dim<Dim, Exact>,
00296 
00297         mlc::bool_case_<true,
00298                         data_type_image_with_dim<Dim, Exact> >
00299 
00300       > > > > > >::ret ret; 
00309     };
00310 
00311   } // end of namespace abstract
00312 
00313 } // end of namespace oln
00314 
00315 #endif // ! OLENA_CORE_ABSTRACT_IMAGE_WITH_TYPE_WITH_DIM_HH

Generated on Tue Feb 20 20:19:57 2007 for Olena by  doxygen 1.5.1