00001
00002
00003 #ifndef IRSTLM_UTIL_H
00004 #define IRSTLM_UTIL_H
00005
00006 #include <string>
00007 #include <fstream>
00008 #include "gzfilebuf.h"
00009 #include "n_gram.h"
00010
00011
00012 #define MAX(a,b) (((a)>(b))?(a):(b))
00013 #define MIN(a,b) (((a)<(b))?(a):(b))
00014
00015 #define UNUSED(x) { (void) x; }
00016
00017 #define _DEBUG_LEVEL 2
00018
00021 #ifdef TRACE_ENABLE
00022 #define TRACE_ERR(str) { std::cerr << str; }
00023 #define VERBOSE(level,str) { if (_DEBUG_LEVEL){ if (_DEBUG_LEVEL >= level) { TRACE_ERR("DEBUG_LEVEL:" <<_DEBUG_LEVEL << " "); TRACE_ERR(str); } } }
00024 #define IFVERBOSE(level) if (_DEBUG_LEVEL) if (_DEBUG_LEVEL >= level)
00025
00026 #else
00027 #define VERBOSE(level,str) { }
00028 #define IFVERBOSE(level) { }
00029 #endif
00030
00031
00032
00033 #define LMTMAXLEV 20
00034 #define MAX_LINE 100000
00035
00036
00037
00038
00039
00040
00041
00042 #define UPPER_SINGLE_PRECISION_OF_0 0.000001
00043 #define UPPER_DOUBLE_PRECISION_OF_0 0.000000000001
00044 #define UPPER_SINGLE_PRECISION_OF_1 1.000001
00045 #define LOWER_SINGLE_PRECISION_OF_1 0.999999
00046 #define UPPER_DOUBLE_PRECISION_OF_1 1.000000000001
00047 #define LOWER_DOUBLE_PRECISION_OF_1 0.999999999999
00048
00049 std::string gettempfolder();
00050 std::string createtempName();
00051 void createtempfile(mfstream &fileStream, std::string &filePath, std::ios_base::openmode flags);
00052
00053 void removefile(const std::string &filePath);
00054
00055 class inputfilestream : public std::istream
00056 {
00057 protected:
00058 std::streambuf *m_streambuf;
00059 bool _good;
00060 public:
00061
00062 inputfilestream(const std::string &filePath);
00063 ~inputfilestream();
00064 bool good() {
00065 return _good;
00066 }
00067 void close();
00068 };
00069
00070 void *MMap(int fd, int access, off_t offset, size_t len, off_t *gap);
00071 int Munmap(void *p,size_t len,int sync);
00072
00073
00074
00075 void ResetUserTime();
00076 void PrintUserTime(const std::string &message);
00077 double GetUserTime();
00078
00079
00080 int parseWords(char *, const char **, int);
00081 int parseline(istream& inp, int Order,ngram& ng,float& prob,float& bow);
00082
00083 #endif
00084