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

general.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: general.h,v 1.15 2004/07/21 16:30:50 chrish42 Exp $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef GENERAL_INC 00049 #define GENERAL_INC 00050 00051 #if !(!defined(_MSC_VER) && !defined(_MINGW_)) 00052 #include <io.h> 00053 #include <float.h> 00054 #else 00055 #include <unistd.h> 00056 #endif 00057 00058 //#include <cstdlib> 00059 //#include <cstdio> 00060 //#include <cmath> 00061 //#include <cstring> 00062 //#include <cstdarg> 00063 //#include <cstddef> 00064 //#include <cfloat> 00065 //#include <cctype> 00066 //#include <iostream> 00067 //#include <fstream> 00068 //#include <strstream> 00069 #include <iomanip> 00070 //#include <cerrno> 00071 //#include <sys/types.h> 00072 //#include <sys/stat.h> 00073 //#include <fcntl.h> 00074 //#include <string> 00075 //#include <vector> 00076 #include <map> 00077 //#include <set> 00078 //#include <algorithm> 00079 //#include <functional> 00080 00081 #ifdef SPARC 00082 #include <ieeefp.h> 00083 #endif 00084 00085 //#include "plerror.h" 00086 #include <plearn/math/pl_math.h> 00087 //#include "pl_io.h" 00088 #include <plearn/io/pl_io_deprecated.h> 00089 //#include "plstreams.h" 00090 //#include "stringutils.h" 00091 //#include "pl_hash_fun.h" 00092 //#include "TypeTraits.h" 00093 //#include "CopiesMap.h" 00094 00095 // Include directive to be removed ultimately 00096 #include "ProgressBar.h" 00097 00098 00101 #define DATAFILE_HEADERLENGTH 64 00102 00104 #ifdef _MSC_VER 00105 #define INFINITY HUGE_VAL 00106 #endif 00107 00108 namespace std { 00109 00111 00112 inline float* copy(float* first, float* last, float* dest) 00113 { size_t n = last-first; memcpy(dest, first, n*sizeof(float)); return dest+n; } 00114 00115 inline double* copy(double* first, double* last, double* dest) 00116 { size_t n = last-first; memcpy(dest, first, n*sizeof(double)); return dest+n; } 00117 00118 inline bool* copy(bool* first, bool* last, bool* dest) 00119 { size_t n = last-first; memcpy(dest, first, n*sizeof(bool)); return dest+n; } 00120 00121 inline char* copy(char* first, char* last, char* dest) 00122 { size_t n = last-first; memcpy(dest, first, n*sizeof(char)); return dest+n; } 00123 00124 inline unsigned char* copy(unsigned char* first, unsigned char* last, unsigned char* dest) 00125 { size_t n = last-first; memcpy(dest, first, n*sizeof(unsigned char)); return dest+n; } 00126 00127 inline short* copy(short* first, short* last, short* dest) 00128 { size_t n = last-first; memcpy(dest, first, n*sizeof(short)); return dest+n; } 00129 00130 inline unsigned short* copy(unsigned short* first, unsigned short* last, unsigned short* dest) 00131 { size_t n = last-first; memcpy(dest, first, n*sizeof(unsigned short)); return dest+n; } 00132 00133 inline int* copy(int* first, int* last, int* dest) 00134 { size_t n = last-first; memcpy(dest, first, n*sizeof(int)); return dest+n; } 00135 00136 inline unsigned int* copy(unsigned int* first, unsigned int* last, unsigned int* dest) 00137 { size_t n = last-first; memcpy(dest, first, n*sizeof(unsigned int)); return dest+n; } 00138 00139 inline long* copy(long* first, long* last, long* dest) 00140 { size_t n = last-first; memcpy(dest, first, n*sizeof(long)); return dest+n; } 00141 00142 inline unsigned long* copy(unsigned long* first, unsigned long* last, unsigned long* dest) 00143 { size_t n = last-first; memcpy(dest, first, n*sizeof(unsigned long)); return dest+n; } 00144 00145 } // end of namespace std 00146 00147 00148 namespace PLearn { 00149 using namespace std; 00150 00151 #if defined(_MINGW_) || defined(WIN32) 00152 #define sleep(t) _sleep(t*1000) 00153 #endif 00154 00155 using std::min; 00156 using std::max; 00157 00159 template<class In, class Out> 00160 inline Out copy_cast(In first, In last, Out res) 00161 { 00162 typedef typename iterator_traits<Out>::value_type out_t; 00163 for(; first!=last; ++first, ++res) 00164 *res = out_t(*first); 00165 return res; 00166 } 00167 00168 00171 00174 template<class T> 00175 inline void clear_1(T& x) 00176 { x = T(); } 00177 00178 inline void clear_1(char& x) { x = 0; } 00179 inline void clear_1(unsigned char& x) { x = 0; } 00180 inline void clear_1(signed char& x) { x = 0; } 00181 inline void clear_1(short& x) { x = 0; } 00182 inline void clear_1(unsigned short& x) { x = 0; } 00183 inline void clear_1(int& x) { x = 0; } 00184 inline void clear_1(unsigned int& x) { x = 0; } 00185 inline void clear_1(long& x) { x = 0; } 00186 inline void clear_1(unsigned long& x) { x = 0; } 00187 inline void clear_1(float& x) { x = 0; } 00188 inline void clear_1(double& x) { x = 0; } 00189 inline void clear_1(bool& x) { x = false; } 00190 00192 template<class For> 00193 inline void clear_n(For begin, int n) 00194 { 00195 while(n--) 00196 { 00197 clear_1(*begin); 00198 ++begin; 00199 } 00200 } 00201 00203 inline void clear_n(float* begin, int n) 00204 { memset(begin,0,n*sizeof(float)); } 00205 00206 inline void clear_n(double* begin, int n) 00207 { memset(begin,0,n*sizeof(double)); } 00208 00209 inline void clear_n(bool* begin, int n) 00210 { memset(begin,0,n*sizeof(bool)); } 00211 00212 inline void clear_n(char* begin, int n) 00213 { memset(begin,0,n*sizeof(char)); } 00214 00215 inline void clear_n(unsigned char* begin, int n) 00216 { memset(begin,0,n*sizeof(unsigned char)); } 00217 00218 inline void clear_n(short* begin, int n) 00219 { memset(begin,0,n*sizeof(short)); } 00220 00221 inline void clear_n(unsigned short* begin, int n) 00222 { memset(begin,0,n*sizeof(unsigned short)); } 00223 00224 inline void clear_n(int* begin, int n) 00225 { memset(begin,0,n*sizeof(int)); } 00226 00227 inline void clear_n(unsigned int* begin, int n) 00228 { memset(begin,0,n*sizeof(unsigned int)); } 00229 00230 inline void clear_n(long* begin, int n) 00231 { memset(begin,0,n*sizeof(long)); } 00232 00233 inline void clear_n(unsigned long* begin, int n) 00234 { memset(begin,0,n*sizeof(unsigned long)); } 00235 00236 typedef int (*compare_function)(const void *, const void *); 00237 00238 template<class T> 00239 inline void swap(T& a, T& b) 00240 { 00241 T tmp; 00242 tmp = a; 00243 a = b; 00244 b = tmp; 00245 } 00246 00248 char* strcopy(char* s); 00249 00251 void pretty_print_number(char* buffer, real number); 00252 00254 int file_size(const string& filename); 00255 bool file_exists(const string& filename); 00256 00257 00259 bool isMapKeysAreInt(map<real,int>& m); 00260 00261 // return the name of host, e.g. with getenv("HOSTNAME") or getenv("HOST") 00262 string hostname(); 00263 00264 // static object used to perform PLearn unconditionnal initializations 00265 class PLearnInit 00266 { 00267 public: 00268 PLearnInit(); 00269 ~PLearnInit(); 00270 }; 00271 00272 //static PLearnInit _plearn_init_; 00273 00274 // set or get (if argument is "") the program name, as given by argv[0] of main 00275 string prgname(const string& setname = ""); 00276 00277 00278 } // end of namespace PLearn 00279 00280 #endif

Generated on Tue Aug 17 15:54:04 2004 for PLearn by doxygen 1.3.7