cc.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00037 #ifndef BASE_CC_H
00038 #define BASE_CC_H
00039 
00040 #include "fastlib/base/common.h"
00041 
00042 #include <algorithm>
00043 #include <limits>
00044 
00046 using std::min;
00048 using std::max;
00049 
00051 extern const double DBL_NAN;
00053 extern const float FLT_NAN;
00055 extern const double DBL_INF;
00057 extern const float FLT_INF;
00058 
00081 #define FORBID_ACCIDENTAL_COPIES(C) \
00082    private: \
00083     C (const C &src); \
00084     const C &operator=(const C &src);
00085 
00098 #define ASSIGN_VIA_COPY_CONSTRUCTION(C) \
00099     const C &operator=(const C &src) { \
00100       if (likely(this != &src)) { \
00101         this->~C(); \
00102         new(this) C(src); \
00103       } \
00104       return *this; \
00105     }
00106 
00120 #define ASSIGN_VIA_RECURSION_SAFE_COPY_CONSTRUCTION(C) \
00121     const C &operator=(const C &src) { \
00122       if (likely(this != &src)) { \
00123         char buf[sizeof(C)]; \
00124         memcpy(buf, this, sizeof(C)); \
00125         new(this) C(src); \
00126         reinterpret_cast<C *>(buf)->~C(); \
00127       } \
00128       return *this; \
00129     }
00130 
00148 #define EXPAND_LESS_THAN(C) \
00149     friend bool operator>(C const &b, C const &a) {return a < b;} \
00150     friend bool operator<=(C const &b, C const &a) {return !(a < b);} \
00151     friend bool operator>=(C const &a, C const &b) {return !(a < b);}
00152 
00170 #define EXPAND_GREATER_THAN(C) \
00171     friend bool operator<(C const &b, C const &a) {return a > b;} \
00172     friend bool operator>=(C const &b, C const &a) {return !(a > b);} \
00173     friend bool operator<=(C const &a, C const &b) {return !(a > b);}
00174 
00192 #define EXPAND_EQUALS(C) \
00193     friend bool operator!=(C const &a, C const &b) {return !(a == b);}
00194 
00220 #define EXPAND_HETERO_LESS_THAN(C, T) \
00221     friend bool operator>(T const &b, C const &a) {return a < b;} \
00222     friend bool operator<=(T const &b, C const &a) {return !(a < b);} \
00223     friend bool operator>=(C const &a, T const &b) {return !(a < b);}
00224 
00250 #define EXPAND_HETERO_GREATER_THAN(C, T) \
00251     friend bool operator<(T const &b, C const &a) {return a > b;} \
00252     friend bool operator>=(T const &b, C const &a) {return !(a > b);} \
00253     friend bool operator<=(C const &a, T const &b) {return !(a > b);}
00254 
00273 #define EXPAND_HETERO_EQUALS(C, T) \
00274     friend bool operator==(T const &b, C const &a) {return a == b;} \
00275     friend bool operator!=(C const &a, T const &b) {return !(a == b);} \
00276     friend bool operator!=(T const &b, C const &a) {return !(a == b);}
00277 
00286 #define FOR_ALL_PRIMITIVES_DO(macro) \
00287     macro(char, "%c") \
00288     macro(short, "%d") \
00289     macro(int, "%d") \
00290     macro(long, "%ld") \
00291     macro(long long, "%lld") \
00292     macro(unsigned char, "%u") \
00293     macro(unsigned short, "%u") \
00294     macro(unsigned int, "%u") \
00295     macro(unsigned long, "%lu") \
00296     macro(unsigned long long, "%llu") \
00297     macro(float, "%g") \
00298     macro(double, "%g") \
00299     macro(long double, "%Lg")
00300 
00302 class Empty {};
00303 
00304 #endif /* BASE_CC_H */
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3