libidx
/home/rex/ebltrunk/core/libidx/include/defines.h
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Yann LeCun   *
00003  *   yann@cs.nyu.edu   *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source
00014  *       Initiative (http://www.opensource.org) must display the
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef LIBIDX_DEFINES_H_
00034 #define LIBIDX_DEFINES_H_
00035 
00036 #ifdef __ANDROID__
00037 #define __NOSTL__
00038 #endif
00039 
00040 #include "config.h"
00041 
00042 #if !defined(__WINDOWS__) && !defined(__ANDROID__)
00043 #include <execinfo.h>
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <limits.h>
00049 
00050 #ifndef NULL
00051 #define NULL (void*)0
00052 #endif
00053 
00054 #define MATRIX_EXTENSION ".mat"
00055 #define MAT_PATTERN ".*[.](mat|MAT)"
00056 #define IMAGE_PATTERN \
00057   ".*[.](png|jpg|jpeg|PNG|JPG|JPEG|bmp|BMP|ppm|PPM|pnm|PNM|pgm|PGM|gif|GIF)"
00058 #define IMAGE_PATTERN_MAT \
00059   ".*[.](png|jpg|jpeg|PNG|JPG|JPEG|bmp|BMP|ppm|PPM|pnm|PNM|pgm|PGM|gif|GIF|mat|MAT)"
00060 
00061 // official names for dataset files
00062 #define DATA_NAME "data"
00063 #define LABELS_NAME "labels"
00064 #define JITTERS_NAME "jitters"
00065 #define CLASSES_NAME "classes"
00066 #define SCALES_NAME "scales"
00067 #define CLASSPAIRS_NAME "classpairs"
00068 #define DEFORMPAIRS_NAME "deformpairs"
00069 
00070 // low-level debug
00071 #define DEBUG_LOW(s) //std::cout << s << std::endl;
00072 
00073 // debug message
00074 #ifdef __DEBUG__
00075 #define __DEBUG_PRINT__
00076 #define EDEBUG(s) std::cout << s << std::endl;
00077 #define MEDEBUG(s) mout << s << std::endl;
00078 #else
00079 #define EDEBUG(s)
00080 #define MEDEBUG(s)
00081 #endif
00082 
00084 // library export macros
00085 
00086 #ifdef __WINDOWS__
00087 #define EXPORT __declspec(dllexport)
00088 #define IMPORT __declspec(dllimport)
00089 // disable dllexport warnings
00090 #pragma warning(disable:4251)
00091 #else
00092 #define EXPORT
00093 #define IMPORT
00094 #endif
00095 
00097 // error reporting macros
00098 
00099 #ifdef __ANDROID__ // no exceptions
00100 #define eblthrow(s) {                                   \
00101     eblerror(s);                                        \
00102   }
00103 #else
00104 #define eblthrow(s) {                                   \
00105     std::string eblthrow_error;                         \
00106     eblthrow_error << s;                                \
00107     throw ebl::eblexception(eblthrow_error);            \
00108   }
00109 #endif
00110 
00111 #define eblcatch()                                      \
00112   catch(ebl::eblexception &e) {                         \
00113     cerr << "exception: " << e << endl;                 \
00114   }                                                     \
00115   catch(std::string &e) {                               \
00116     cerr << "exception: " << e << endl;                 \
00117   }
00118 
00119 #define eblcatcherror()                                 \
00120   catch(ebl::eblexception &e) {                         \
00121     eblerror(e);                                        \
00122   }                                                     \
00123   catch(std::string &e) {                               \
00124     eblerror(e);                                        \
00125   }
00126 
00127 #define not_implemented() {                     \
00128     eblerror("not implemented"); }
00129 
00130 #if defined(__ANDROID__) ///////////////////////////////////////////////////
00131 
00132 #include <android/log.h>
00133 
00134 #define LOG_TAG    "eblearn"
00135 #define LOGI(info) {                                            \
00136     std::string s; s << info;                                   \
00137     __android_log_print(ANDROID_LOG_INFO,LOG_TAG,s.c_str()); }
00138 #define LOGE(info) {                                            \
00139     std::string s; s << info;                                   \
00140     __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,s.c_str()); }
00141 #define eblerror(s) LOGE(s)
00142 #define eblwarn(s) LOGE(s)
00143 
00144 #elif defined(__WINDOWS__) ///////////////////////////////////////////////////
00145 
00146 #define eblerror(s) {                                                   \
00147     std::cerr << "Error: " << s;                                        \
00148     std::cerr << ", in " << __FUNCTION__ << " at " << __FILE__;         \
00149     std::cerr << ":" << __LINE__ << std::endl;                          \
00150     abort();                                                            \
00151   }
00152 
00153 #define trace()
00154 
00155 #else ///////////////////////////////////////////////////
00156 
00157 #define trace() {                               \
00158     void *array[10];                                                    \
00159     size_t size;                                                        \
00160     size = backtrace(array, 10);                                        \
00161     backtrace_symbols_fd(array, size, 2);                               \
00162   }
00163 
00164 #define eblerror(s) {                                                   \
00165     std::cerr << "\033[1;31mError:\033[0m " << s;                       \
00166     std::cerr << ", in " << __FUNCTION__ << " at " << __FILE__;         \
00167     std::cerr << ":" << __LINE__ << std::endl;                          \
00168     std::cerr << "\033[1;31mStack:\033[0m" << std::endl;                \
00169     trace();                                                            \
00170     abort();                                                            \
00171   }
00172 #endif /* __WINDOWS__ */
00173 
00174 #define eblwarn(s) { std::cerr << "Warning: " << s << "." << std::endl; }
00175 
00176 /* #ifndef MAX */
00177 /* # define MAX(a, b) (((a) > (b)) ? (a) : (b)) */
00178 /* #endif */
00179 #ifndef MIN
00180 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
00181 #endif
00182 
00183 typedef unsigned int uint; // not defined on MAC
00184 
00185 namespace ebl {
00186 
00187   // intg is used for array indexing, hence should be
00188   // defined as long if you want very large arrays
00189   // on 64 bit machines.
00190   typedef long intg;
00191 #if __LP64__ == 1 //intg size is 64bits
00192   #define SIZEOFINTG 64
00193 #else //else, assume that intg size is 32bits
00194   #define SIZEOFINTG 32
00195 #endif
00196 #ifdef __IPP__
00197   #include <ipp.h>
00198   typedef Ipp8u ubyte;
00199   typedef Ipp8s byte;
00200   typedef Ipp16u uint16;
00201   typedef Ipp16s int16;
00202   typedef Ipp32u uint32;
00203   typedef Ipp32s int32;
00204   typedef long int64;
00205   typedef unsigned long uint64;
00206   typedef Ipp32f float32;
00207   typedef Ipp64f float64;
00208 #else
00209   typedef unsigned char ubyte;
00210   typedef signed char byte;
00211   typedef unsigned short int uint16;
00212   typedef signed short int int16;
00213   typedef unsigned int uint32;
00214   typedef signed int int32;
00215   typedef unsigned long uint64;
00216   typedef signed long int64;
00217   typedef float float32;
00218   typedef double float64;
00219 #endif
00220 
00221   // iterators
00222 #define USING_FAST_ITERS 1
00223   
00224 #ifdef LIBIDX // we are inside the library
00225 #define IDXEXPORT EXPORT
00226 #else // we are outside
00227 #define IDXEXPORT IMPORT
00228 #endif
00229 
00230 } // end namespace ebl
00231 
00232 #endif /* LIBIDX_DEFINES_H_ */