2008-05-14 11:57:45 +04:00
|
|
|
/*
|
|
|
|
* Util.h
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2008-05-20 18:15:30 +04:00
|
|
|
#include <stdexcept>
|
2008-05-14 11:57:45 +04:00
|
|
|
#include <limits>
|
2008-10-17 01:14:38 +04:00
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
#define US_NOSET (numeric_limits<unsigned short>::max())
|
|
|
|
|
2008-05-20 18:15:30 +04:00
|
|
|
#define MAX_LINE 1024
|
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2008-10-17 01:14:38 +04:00
|
|
|
#include <cstring>
|
2008-05-14 11:57:45 +04:00
|
|
|
|
2008-05-20 18:15:30 +04:00
|
|
|
#include <fstream>
|
|
|
|
#include "gzfilebuf.h"
|
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
#include "Types.h"
|
2008-05-14 11:57:45 +04:00
|
|
|
#include "ScoreStats.h"
|
|
|
|
#include "FeatureStats.h"
|
|
|
|
|
|
|
|
class ScoreStats;
|
|
|
|
class FeatureStats;
|
|
|
|
|
|
|
|
#ifdef TRACE_ENABLE
|
|
|
|
#define TRACE_ERR(str) { std::cerr << str; }
|
|
|
|
#else
|
|
|
|
#define TRACE_ERR(str) { }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DELIMITER_SYMBOL " "
|
|
|
|
|
2008-05-16 11:09:15 +04:00
|
|
|
int verboselevel();
|
|
|
|
int setverboselevel(int v);
|
|
|
|
|
2008-05-14 11:57:45 +04:00
|
|
|
int getNextPound(std::string &theString, std::string &substring, const std::string delimiter=DELIMITER_SYMBOL);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T Scan(const std::string &input)
|
|
|
|
{
|
2011-02-24 15:42:19 +03:00
|
|
|
std::stringstream stream(input);
|
|
|
|
T ret;
|
|
|
|
stream >> ret;
|
|
|
|
return ret;
|
2008-05-14 11:57:45 +04:00
|
|
|
};
|
|
|
|
|
2008-05-20 18:15:30 +04:00
|
|
|
class inputfilestream : public std::istream
|
2008-05-14 11:57:45 +04:00
|
|
|
{
|
2008-05-20 18:15:30 +04:00
|
|
|
protected:
|
2011-02-24 15:42:19 +03:00
|
|
|
std::streambuf *m_streambuf;
|
|
|
|
bool _good;
|
2008-05-20 18:15:30 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
inputfilestream(const std::string &filePath);
|
|
|
|
~inputfilestream();
|
|
|
|
bool good() {
|
|
|
|
return _good;
|
|
|
|
}
|
|
|
|
void close();
|
2008-05-14 11:57:45 +04:00
|
|
|
};
|
|
|
|
|
2008-05-20 18:15:30 +04:00
|
|
|
class outputfilestream : public std::ostream
|
2008-05-14 11:57:45 +04:00
|
|
|
{
|
2008-05-20 18:15:30 +04:00
|
|
|
protected:
|
2011-02-24 15:42:19 +03:00
|
|
|
std::streambuf *m_streambuf;
|
|
|
|
bool _good;
|
2008-05-20 18:15:30 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
outputfilestream(const std::string &filePath);
|
|
|
|
~outputfilestream();
|
|
|
|
bool good() {
|
|
|
|
return _good;
|
|
|
|
}
|
|
|
|
void close();
|
2008-05-14 11:57:45 +04:00
|
|
|
};
|
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
template<typename T>
|
|
|
|
inline std::string stringify(T x)
|
|
|
|
{
|
2011-02-24 15:42:19 +03:00
|
|
|
std::ostringstream o;
|
|
|
|
if (!(o << x))
|
|
|
|
throw std::runtime_error("stringify(template<typename T>)");
|
|
|
|
return o.str();
|
2008-05-27 20:50:52 +04:00
|
|
|
}
|
|
|
|
|
2009-01-07 16:30:06 +03:00
|
|
|
// Utilities to measure decoding time
|
|
|
|
void ResetUserTime();
|
|
|
|
void PrintUserTime(const std::string &message);
|
|
|
|
double GetUserTime();
|
|
|
|
|
2008-05-15 10:44:36 +04:00
|
|
|
#endif
|
|
|
|
|