BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Tools/utility_macros.h
Go to the documentation of this file.
00001 // Copyright (c) 2007 (USA).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/trunk/Kinetic_data_structures/include/CGAL/Tools/Log.h $
00016 // $Id: Log.h 39016 2007-06-11 00:08:13Z drussel $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 
00022 #ifndef CGAL_UTILITY_MACROS_H
00023 #define CGAL_UTILITY_MACROS_H
00024 
00025 #define CGAL_SUBSCRIPT(type, expr) type& operator[](unsigned int i){ expr;} \
00026   const type& operator[](unsigned int i) const { expr;} 
00027 
00028 #define CGAL_COPY_CONSTRUCTOR(TC) TC(const TC &o){copy_from(o);}\
00029   TC& operator=(const TC &o) {copy_from(o); return *this;}  
00030 
00031 // 
00032 #define CGAL_GET(type, name, expr) const type & name() const{expr;} 
00033 #define CGAL_GETOBJECT(UC, lc, expr) const UC& lc##_object() const {expr;} 
00034 #define CGAL_GETNR(type, name, expr) type name() const{expr;} 
00035 //#define CGAL_GET(type, name, expr) typename boost::call_traits<type>::param_type name() const {expr;}
00036 
00037 #define CGAL_IS(name, expr) bool is_##name() const {expr;} 
00038 #define CGAL_SET_IS(name, expr) void set_is_##name(bool tf) {expr;} 
00039 
00040 #define CGAL_SET(type, name, expr) void set_##name(const type &k) {expr;} 
00041 
00042 #define CGAL_GETSET(type, name, var)            \
00043   CGAL_GET(type, name, return var)              \
00044   CGAL_SET(type, name, var = k)
00045 
00046 #define CGAL_OUTPUT(type)                                               \
00047   inline std::ostream& operator<<(std::ostream&out, const type &t){     \
00048     return t.write(out);                                                \
00049   }
00050 
00051 #define CGAL_OUTPUT1(type)                                              \
00052   template <class A>                                                    \
00053   inline std::ostream& operator<<(std::ostream&out, const type<A> &t){  \
00054     return t.write(out);                                                \
00055   }
00056 
00057 #define CGAL_OUTPUT2(T)                                                 \
00058   template <class A, class B>                                           \
00059   inline std::ostream& operator<<(std::ostream&out, const T<A,B> &t){   \
00060     return t.write(out);                                                \
00061   }
00062 
00063 #define CGAL_ITERATOR(uc_name, lc_name, const_it_type,it_type, bexpr, eexpr) \
00064   typedef boost::iterator_range< it_type > uc_name##s;                  \
00065   uc_name##s lc_name##s() {                                             \
00066     return uc_name##s(it_type(bexpr), it_type(eexpr));                  \
00067   }                                                                     \
00068   typedef boost::iterator_range< const_it_type > uc_name##_consts;      \
00069   uc_name##_consts lc_name##s() const {                                 \
00070     return uc_name##_consts(const_it_type(bexpr), const_it_type(eexpr)); \
00071   }
00072 
00073 
00074 #define CGAL_CONST_ITERATOR(uc_name, lc_name, it_type, bexpr, eexpr)    \
00075   typedef boost::iterator_range< it_type > uc_name##s;                  \
00076   uc_name##s lc_name##s() const {                                       \
00077     return uc_name##s(bexpr, eexpr);                                    \
00078   }
00079 
00080 
00081 
00082 #define CGAL_CONST_FIND(ucname, fexpr, expr)                       \
00083   bool contains(ucname##_key k) const {                            \
00084     return fexpr != eexpr;                                         \
00085   }                                                                \
00086   std::iterator_traits<ucname##s::iterator>::value_type get(ucname##_key k) const {      \
00087     CGAL_assertion(contains(k));                                   \
00088     return *fexpr;                                                 \
00089   }                                                                \
00090   ucname##s::const_iterator find(ucname##_key k) {                 \
00091     return fexpr;                                                  \
00092   }
00093 
00094 #define CGAL_FIND(ucname, fexpr, eexpr)                         \
00095   bool contains(ucname##_key k) const {                         \
00096     return fexpr != eexpr;                                      \
00097   }                                                             \
00098   std::iterator_traits< ucname##s::iterator >::reference get(ucname##_key k) { \
00099     CGAL_assertion(contains(k));                                \
00100     return *fexpr;                                              \
00101   }                                                             \
00102   ucname##s::iterator find(ucname##_key k) {                    \
00103     return fexpr;                                               \
00104   }                                                             \
00105   std::iterator_traits< ucname##s::const_iterator >::value_type get(ucname##_key k) const {      \
00106     CGAL_assertion(contains(k));                                   \
00107     return *fexpr;                                                 \
00108   }                                                                \
00109   ucname##_consts::const_iterator find(ucname##_key k) const {           \
00110     return fexpr;                                                  \
00111   }
00112 
00113 
00114 
00115 #define CGAL_INSERT(ucname, expr)                                       \
00116   void insert(ucname##_key k, const ucname &m) {expr;} 
00117 
00118 #define CGAL_INSERTNK(ucname, expr)                     \
00119   void insert(const ucname &m) {expr;} 
00120 
00121 #define CGAL_SWAP(type)                         \
00122   inline void swap(type &a, type &b) {          \
00123     a.swap_with(b);                             \
00124   }
00125 
00126 #define CGAL_SWAP1(type)                        \
00127   template <class A>                            \
00128  inline void swap(type<A> &a, type<A> &b) {     \
00129     a.swap_with(b);                             \
00130   }
00131 
00132 #define CGAL_SWAP2(type)                        \
00133 template <class A, class B>                     \
00134  inline void swap(type<A,B> &a, type<A,B> &b) { \
00135     a.swap_with(b);                             \
00136   }
00137 
00138 #define CGAL_ISWAP(name)                        \
00139   std::swap(name, o.name)
00140 
00141 
00142 #define CGAL_IFNONEQUAL(a,b,cmp) if (a cmp b) return true;      \
00143   else if (b cmp a) return false
00144 
00145 #define CGAL_COMPARISONS bool operator==(const This &o) const {         \
00146     return compare(o) == CGAL::EQUAL;                                   \
00147   }                                                                     \
00148   bool operator!=(const This &o) const {                                \
00149     return compare(o) != CGAL::EQUAL;                                   \
00150   }                                                                     \
00151   bool operator<(const This &o) const {                                 \
00152     return compare(o) == CGAL::SMALLER;                                 \
00153   }                                                                     \
00154   bool operator>(const This &o) const {                                 \
00155     return compare(o) == CGAL::LARGER;                                  \
00156   }                                                                     \
00157   bool operator>=(const This &o) const {                                \
00158     return compare(o) != CGAL::SMALLER;                                 \
00159   }                                                                     \
00160   bool operator<=(const This &o) const {                                \
00161     return compare(o) != CGAL::LARGER;                                  \
00162   } 
00163 
00164 #define CGAL_COMPARISONS_COMPARE bool operator==(const This &o) const { \
00165     return compare(o)==0;                                               \
00166   }                                                                     \
00167   bool operator!=(const This &o) const {                                \
00168     return compare(o)!=0;                                               \
00169   }                                                                     \
00170   bool operator<(const This &o) const {                                 \
00171     return compare(o) < 0;                                              \
00172   }                                                                     \
00173   bool operator>(const This &o) const {                                 \
00174     return compare(o) > 0;                                              \
00175   }                                                                     \
00176   bool operator>=(const This &o) const {                                \
00177     return compare(o) >=0;                                              \
00178   }                                                                     \
00179   bool operator<=(const This &o) const {                                \
00180     return compare(o) <= 0;                                             \
00181   } 
00182 
00183 
00184 #define CGAL_COMPARISONS1(field) bool operator==(const This &o) const { \
00185     return (field== o.field);                                           \
00186   }                                                                     \
00187   bool operator!=(const This &o) const {                                \
00188     return (field!= o.field);                                           \
00189   }                                                                     \
00190   bool operator<(const This &o) const {                                 \
00191     return (field< o.field);                                            \
00192   }                                                                     \
00193   bool operator>(const This &o) const {                                 \
00194     return (field> o.field);                                            \
00195   }                                                                     \
00196   bool operator>=(const This &o) const {                                \
00197     return (field>= o.field);                                           \
00198   }                                                                     \
00199   bool operator<=(const This &o) const {                                \
00200     return (field<= o.field);                                           \
00201   } 
00202 
00203 
00204 
00205 #define CGAL_COMPARISONS2(a, b) bool operator==(const This &o) const {  \
00206     return (a== o.a && b== o.b);                                        \
00207   }                                                                     \
00208   bool operator!=(const This &o) const {                                \
00209     return (a!= o.a || b != o.b);                                       \
00210   }                                                                     \
00211   bool operator<(const This &o) const {                                 \
00212     if (a< o.a ) return true;                                           \
00213     else if (a > o.a) return false;                                     \
00214     else return b < o.b;                                                \
00215   }                                                                     \
00216   bool operator>(const This &o) const {                                 \
00217     if (a> o.a ) return true;                                           \
00218     else if (a < o.a) return false;                                     \
00219     else return b > o.b;                                                \
00220   }                                                                     \
00221   bool operator>=(const This &o) const {                                \
00222     return !operator<(o);                                               \
00223   }                                                                     \
00224   bool operator<=(const This &o) const {                                \
00225     return !operator>(o);                                               \
00226   } 
00227 
00228 #define CGAL_COMPARISONS3(a, b, c)                                      \
00229   bool operator==(const This &o) const {                                \
00230     return (a== o.a && b== o.b && c == o.c);                            \
00231   }                                                                     \
00232   bool operator!=(const This &o) const {                                \
00233     return (a!= o.a || b != o.b || c != o.c);                           \
00234   }                                                                     \
00235   bool operator<(const This &o) const {                                 \
00236     if (a < o.a ) return true;                                          \
00237     else if (a > o.a) return false;                                     \
00238     else if (b < o.b) return true;                                      \
00239     else if (b > o.b) return false;                                     \
00240     else return c < o.c;                                                \
00241   }                                                                     \
00242   bool operator>(const This &o) const {                                 \
00243     if (a > o.a ) return true;                                          \
00244     else if (a < o.a) return false;                                     \
00245     else if (b > o.b) return true;                                      \
00246     else if (b < o.b) return false;                                     \
00247     else return c > o.c;                                                \
00248   }                                                                     \
00249   bool operator>=(const This &o) const {                                \
00250     return !operator<(o);                                               \
00251   }                                                                     \
00252   bool operator<=(const This &o) const {                                \
00253     return !operator>(o);                                               \
00254   }
00255 
00256 #define CGAL_REAL_EMBEDDABLE_BODY                                       \
00257   class Abs                                                             \
00258     : public std::unary_function< Type, Type > {                        \
00259   public:                                                               \
00260     Type operator()( const Type& x ) const {                            \
00261       if (x < Type(0)) return -x;                                       \
00262       else return x;                                                    \
00263     }                                                                   \
00264   };                                                                    \
00265                                                                         \
00266   class Sgn                                                             \
00267     : public std::unary_function< Type, ::CGAL::Sign > {                \
00268   public:                                                               \
00269     ::CGAL::Sign operator()( const Type& x ) const {                    \
00270       return static_cast<CGAL::Sign>(x.compare(0));                     \
00271     }                                                                   \
00272   };                                                                    \
00273                                                                         \
00274   class Compare                                                         \
00275     : public std::binary_function< Type, Type,                          \
00276                               Comparison_result > {                     \
00277   public:                                                               \
00278       Comparison_result operator()( const Type& x,                      \
00279                                     const Type& y ) const {             \
00280         return x.compare(y);                                            \
00281       }                                                                 \
00282                                                                         \
00283     CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type,          \
00284                                                          Comparison_result ); \
00285                                                                         \
00286   };                                                                    \
00287                                                                         \
00288   class To_double                                                       \
00289     : public std::unary_function< Type, double > {                      \
00290   public:                                                               \
00291     double operator()( const Type& x ) const {                          \
00292       return x.approximation(.00000001);                                \
00293     }                                                                   \
00294   };                                                                    \
00295                                                                         \
00296   class To_interval                                                     \
00297     : public std::unary_function< Type, std::pair< double, double > > { \
00298   public:                                                               \
00299     std::pair<double, double> operator()( const Type& x ) const {       \
00300                                                                         \
00301       return x.approximating_interval(.00001);                          \
00302     }                                                                   \
00303   }                     
00304 
00305 #define CGAL_HAS_INFINITY_BODY                                          \
00306   static const bool is_specialized = true;                              \
00307   static T min BOOST_PREVENT_MACRO_SUBSTITUTION () throw ()             \
00308   {return -T::infinity();}                                              \
00309   static T max BOOST_PREVENT_MACRO_SUBSTITUTION () throw ()             \
00310   {return T::infinity();}                                               \
00311   static const int digits =0;                                           \
00312   static const int digits10 =0;                                         \
00313   static const bool is_signed = true;                                   \
00314   static const bool is_integer = false;                                 \
00315   static const bool is_exact = true;                                    \
00316   static const int radix =0;                                            \
00317   static T epsilon() throw(){return T(0);}                              \
00318   static T round_error() throw(){return T(0);}                          \
00319   static const int min_exponent=0;                                      \
00320   static const int min_exponent10=0;                                    \
00321   static const int max_exponent=0;                                      \
00322   static const int max_exponent10=0;                                    \
00323   static const bool has_infinity=true;                                  \
00324   static const bool has_quiet_NaN = true;                               \
00325   static const bool has_signaling_NaN= false;                           \
00326   static const float_denorm_style has_denorm= denorm_absent;            \
00327   static const bool has_denorm_loss = false;                            \
00328   static T infinity() throw() {return T::infinity();}                   \
00329   static T quiet_NaN() throw(){return T();}                             \
00330   static T denorm_min() throw() {return T(0);}                          \
00331   static const bool is_iec559=false;                                    \
00332   static const bool is_bounded =false;                                  \
00333   static const bool is_modulo= false;                                   \
00334   static const bool traps = false;                                      \
00335   static const bool tinyness_before =false;                             \
00336   static const float_round_style round_stype = round_toward_zero        \
00337     
00338 
00339 #define CGAL_REAL_EMBEDDABLE1(name)                                     \
00340   CGAL_BEGIN_NAMESPACE                                                  \
00341   template <class T>                                                    \
00342   class Real_embeddable_traits< name<T> >                               \
00343     : public INTERN_RET::Real_embeddable_traits_base<name<T>, Tag_true>{ \
00344   public:                                                               \
00345     typedef name<T>  Type;                                              \
00346     CGAL_REAL_EMBEDDABLE_BODY;                                          \
00347   };                                                                    \
00348   CGAL_END_NAMESPACE                                                    
00349 
00350 
00351 #define CGAL_REAL_EMBEDDABLE2(name)                                     \
00352   CGAL_BEGIN_NAMESPACE                                                  \
00353   template <class T, class A>                                           \
00354   class Real_embeddable_traits< name<T, A> >                            \
00355     : public INTERN_RET::Real_embeddable_traits_base< name<T, A>, Tag_true>{ \
00356   public:                                                               \
00357     typedef name<T, A>  Type;                                           \
00358     CGAL_REAL_EMBEDDABLE_BODY;                                          \
00359   };                                                                    \
00360   CGAL_END_NAMESPACE                                                    
00361 
00362 
00363 #define CGAL_HAS_INFINITY1(name)                                        \
00364   namespace std                                                         \
00365   {                                                                     \
00366     template <class Tr>                                                 \
00367       class numeric_limits<name<Tr> >                                   \
00368     {                                                                   \
00369     public:                                                             \
00370       typedef name<Tr> T;                                               \
00371       CGAL_HAS_INFINITY_BODY;                                           \
00372     };                                                                  \
00373   };
00374 
00375 
00376 
00377 
00378 #define CGAL_REAL_EMBEDABLE2(name)                                      \
00379   CGAL_BEGIN_NAMESPACE                                                  \
00380   template <class T,class U>                                            \
00381   class Real_embeddable_traits< name<T, U> >                            \
00382     : public INTERN_RET::Real_embeddable_traits_base< name<T, U> , Tag_true>{ \
00383   public:                                                               \
00384     typedef name<T, U>  Type;                                           \
00385     CGAL_REAL_EMBEDDABLE_BODY                                           \
00386   };                                                                    \
00387   CGAL_END_NAMESPACE                                                    
00388 
00389 #define CGAL_HAS_INFINITY2(name)                                        \
00390   namespace std                                                         \
00391   {                                                                     \
00392     template <class Tr, class Ur>                                       \
00393       class numeric_limits<name<Tr, Ur> >                               \
00394     {                                                                   \
00395     public:                                                             \
00396       typedef name<Tr, Ur> T;                                           \
00397       CGAL_HAS_INFINITY_BODY;                                           \
00398     };                                                                  \
00399   };
00400 
00401 #endif
00402 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines