mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
added names of features in the header added methods to access the features by name git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1819 1f5c12ca-751b-0410-a591-d2e778427230
106 lines
2.2 KiB
C++
106 lines
2.2 KiB
C++
/*
|
|
* Util.cpp
|
|
* met - Minimum Error Training
|
|
*
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
*
|
|
*/
|
|
|
|
#include <stdexcept>
|
|
#include "Util.h"
|
|
|
|
int verbose=0;
|
|
|
|
int verboselevel(){
|
|
return verbose;
|
|
}
|
|
|
|
int setverboselevel(int v){
|
|
verbose=v;
|
|
return verbose;
|
|
}
|
|
|
|
int getNextPound(std::string &theString, std::string &substring, const std::string delimiter)
|
|
{
|
|
unsigned int pos = 0;
|
|
|
|
//skip all occurrences of delimiter
|
|
while ( pos == 0 )
|
|
{
|
|
if ((pos = theString.find(delimiter)) != std::string::npos){
|
|
substring.assign(theString, 0, pos);
|
|
theString.erase(0,pos + delimiter.size());
|
|
}
|
|
else{
|
|
substring.assign(theString);
|
|
theString.assign("");
|
|
}
|
|
}
|
|
return (pos);
|
|
};
|
|
|
|
inputfilestream::inputfilestream(const std::string &filePath)
|
|
: std::istream(0),
|
|
m_streambuf(0)
|
|
{
|
|
//check if file is readable
|
|
std::filebuf* fb = new std::filebuf();
|
|
_good=(fb->open(filePath.c_str(), std::ios::in)!=NULL);
|
|
|
|
if (filePath.size() > 3 &&
|
|
filePath.substr(filePath.size() - 3, 3) == ".gz")
|
|
{
|
|
fb->close(); delete fb;
|
|
m_streambuf = new gzfilebuf(filePath.c_str());
|
|
} else {
|
|
m_streambuf = fb;
|
|
}
|
|
this->init(m_streambuf);
|
|
}
|
|
|
|
inputfilestream::~inputfilestream()
|
|
{
|
|
delete m_streambuf; m_streambuf = 0;
|
|
}
|
|
|
|
void inputfilestream::close()
|
|
{
|
|
}
|
|
|
|
outputfilestream::outputfilestream(const std::string &filePath)
|
|
: std::ostream(0),
|
|
m_streambuf(0)
|
|
{
|
|
//check if file is readable
|
|
std::filebuf* fb = new std::filebuf();
|
|
_good=(fb->open(filePath.c_str(), std::ios::out)!=NULL);
|
|
|
|
if (filePath.size() > 3 && filePath.substr(filePath.size() - 3, 3) == ".gz")
|
|
{
|
|
throw runtime_error("Output to a zipped file not supported!");
|
|
} else {
|
|
m_streambuf = fb;
|
|
}
|
|
this->init(m_streambuf);
|
|
}
|
|
|
|
outputfilestream::~outputfilestream()
|
|
{
|
|
delete m_streambuf; m_streambuf = 0;
|
|
}
|
|
|
|
void outputfilestream::close()
|
|
{
|
|
}
|
|
|
|
int swapbytes(char *p, int sz, int n)
|
|
{
|
|
char c, *l, *h;
|
|
|
|
if((n<1) || (sz<2)) return 0;
|
|
for(; n--; p+=sz) for(h=(l=p)+sz; --h>l; l++) { c=*h; *h=*l; *l=c; }
|
|
return 0;
|
|
|
|
};
|
|
|