Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/tl/defop.h

Go to the documentation of this file.
00001 /*
00002  * lib/tl/defop.h 
00003  * 
00004  * C++ operator template used by several other templates to access 
00005  * relational operators as well as constructors/destructors. 
00006  * 
00007  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00008  * 
00009  * This file may be distributed and/or modified under the terms of the 
00010  * GNU General Public License version 2 as published by the Free Software 
00011  * Foundation. (See COPYING.GPL for details.)
00012  * 
00013  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00014  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00015  * 
00016  */
00017 
00018 #ifndef _TemplateLibrary_DefaultOperators_H_
00019 #define _TemplateLibrary_DefaultOperators_H_ 1
00020 
00030 #include <lib/sconfig.h>    /* MUST be first */
00031 
00032 
00039 template<typename T>struct TLDefaultOperators_Relational
00040 {
00051     template<typename T2>static inline bool lt(T const &a,T2 const &b)  {  return(a<b);   }
00052     template<typename T2>static inline bool le(T const &a,T2 const &b)  {  return(a<=b);  }
00053     template<typename T2>static inline bool gt(T const &a,T2 const &b)  {  return(a>b);   }
00054     template<typename T2>static inline bool ge(T const &a,T2 const &b)  {  return(a>=b);  }
00055     template<typename T2>static inline bool eq(T const &a,T2 const &b)  {  return(a==b);  }
00056     template<typename T2>static inline bool ne(T const &a,T2 const &b)  {  return(a!=b);  }
00057 };
00058 
00066 template<typename T,typename T2>struct TLDefaultOperators_Relational2
00067 {
00078     static inline bool lt(T const &a,T2 const &b)  {  return(a<b);   }
00079     static inline bool le(T const &a,T2 const &b)  {  return(a<=b);  }
00080     static inline bool gt(T const &a,T2 const &b)  {  return(a>b);   }
00081     static inline bool ge(T const &a,T2 const &b)  {  return(a>=b);  }
00082     static inline bool eq(T const &a,T2 const &b)  {  return(a==b);  }
00083     static inline bool ne(T const &a,T2 const &b)  {  return(a!=b);  }
00084 };
00085 
00086 
00098 template<typename T,typename ORD,typename T2,typename ORD2>
00099     struct TLDefaultOperators_OrdRel2
00100 {
00101     static inline bool lt(T const &a,T2 const &b)
00102         {  return(ORD::ord(a)<ORD2::ord(b));   }
00103     static inline bool le(T const &a,T2 const &b)
00104         {  return(ORD::ord(a)<=ORD2::ord(b));  }
00105     static inline bool gt(T const &a,T2 const &b)
00106         {  return(ORD::ord(a)>ORD2::ord(b));   }
00107     static inline bool ge(T const &a,T2 const &b)
00108         {  return(ORD::ord(a)>=ORD2::ord(b));  }
00109     static inline bool eq(T const &a,T2 const &b)
00110         {  return(ORD::ord(a)==ORD2::ord(b));  }
00111     static inline bool ne(T const &a,T2 const &b)
00112         {  return(ORD::ord(a)!=ORD2::ord(b));  }
00113 };
00114 
00123 template<typename T,typename ORD,typename T2,typename ORD2>
00124     struct TLDefaultOperators_OrdRel2_Rev
00125 {
00126     static inline bool lt(T const &a,T2 const &b)
00127         {  return(ORD::ord(a)>ORD2::ord(b));   }
00128     static inline bool le(T const &a,T2 const &b)
00129         {  return(ORD::ord(a)>=ORD2::ord(b));  }
00130     static inline bool gt(T const &a,T2 const &b)
00131         {  return(ORD::ord(a)<ORD2::ord(b));   }
00132     static inline bool ge(T const &a,T2 const &b)
00133         {  return(ORD::ord(a)<=ORD2::ord(b));  }
00134     static inline bool eq(T const &a,T2 const &b)
00135         {  return(ORD::ord(a)==ORD2::ord(b));  }
00136     static inline bool ne(T const &a,T2 const &b)
00137         {  return(ORD::ord(a)!=ORD2::ord(b));  }
00138 };
00139 
00140 
00150 template<typename T,typename ORD,typename T2>
00151     struct TLDefaultOperators_OrdRel2D
00152 {
00153     static inline bool lt(T const &a,T2 const &b)  {  return(ORD::ord(a)<b);   }
00154     static inline bool le(T const &a,T2 const &b)  {  return(ORD::ord(a)<=b);  }
00155     static inline bool gt(T const &a,T2 const &b)  {  return(ORD::ord(a)>b);   }
00156     static inline bool ge(T const &a,T2 const &b)  {  return(ORD::ord(a)>=b);  }
00157     static inline bool eq(T const &a,T2 const &b)  {  return(ORD::ord(a)==b);  }
00158     static inline bool ne(T const &a,T2 const &b)  {  return(ORD::ord(a)!=b);  }
00159 };
00160 
00161 
00169 template<typename T>struct TLDefaultOperators_Construct_PDT
00170 {
00174     static const bool pdt=1;
00175     
00177     static inline _constfn_ size_t size()
00178         {  return(sizeof(T));  }
00179     
00181     static inline T &ass(T &l,T const &r)  {  return(l=r);  }
00182     
00202     static inline _constfn_ void ini(T *) {}
00203     static inline void ini(T *p,T const &a)  {  *p=a;  }
00204     static inline _constfn_ void clr(T *) {}
00205 };
00206 
00214 template<typename T>struct TLDefaultOperators_Construct_CDT
00215 {
00216     static const bool pdt=0;
00217     static inline _constfn_ size_t size()  {  return(sizeof(T));  }
00218     static inline T & ass(T &l,T const &r)  {  return(l=r);  }
00219     static inline void ini(T *p)  {  new(p) T();  }
00220     static inline void ini(T *p,T const &a)  {  new(p) T(a);  }
00221     static inline void clr(T *p)  {  p->~T();  }
00222 };
00223 
00224 
00231 template<typename T>struct TLDefaultOperators_Index
00232 {
00234     template<typename I>static inline T &idx(T *array,I i)
00235         {  return(array[i]);  }
00236     template<typename I>static inline const T &idx(const T *array,I i)
00237         {  return(array[i]);  }
00238 };
00239 
00240 
00247 struct TLDefaultOperators_Allocation
00248 {
00254     static inline void *alloc(size_t size)  {  return(ALLOC<char>(size));  }
00255     static inline void *free(void *ptr)  {  return(FREE(ptr));  }
00256     static inline void *realloc(void *ptr,size_t size)
00257         {  return(REALLOC((char*)ptr,size));  }
00258 };
00259 
00260 
00273 template<typename T>struct TLDefaultOperators_PDT : 
00274     TLDefaultOperators_Relational<T>,
00275     TLDefaultOperators_Construct_PDT<T>,
00276     TLDefaultOperators_Index<T>,
00277     TLDefaultOperators_Allocation
00278 {
00279     // All provided in base classses. 
00280 };
00281 
00288 template<typename T>struct TLDefaultOperators_CDT : 
00289     TLDefaultOperators_Relational<T>,
00290     TLDefaultOperators_Construct_CDT<T>,
00291     TLDefaultOperators_Index<T>,
00292     TLDefaultOperators_Allocation
00293 {
00294     // All provided in base classses. 
00295 };
00296 
00297 #endif  /* _TemplateLibrary_DefaultOperators_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5