00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
#include <iomanip>
00070
00071
00072
00073
00074
00075
00076
#include <map>
00077
00078
00079
00080
00081
#ifdef SPARC
00082
#include <ieeefp.h>
00083
#endif
00084
00085
00086
#include <plearn/math/pl_math.h>
00087
00088
#include <plearn/io/pl_io_deprecated.h>
00089
00090
00091
00092
00093
00094
00095
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 }
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
00262
string hostname();
00263
00264
00265 class PLearnInit
00266 {
00267
public:
00268
PLearnInit();
00269
~PLearnInit();
00270 };
00271
00272
00273
00274
00275
string prgname(
const string& setname =
"");
00276
00277
00278 }
00279
00280
#endif