diff options
author | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-02-24 15:42:19 +0300 |
---|---|---|
committer | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-02-24 15:42:19 +0300 |
commit | 148c1e8305fbcf8dc0acd021fe5825842e0b3c8d (patch) | |
tree | 04041cbc625ff61db8d94471c6d2d1c61264f653 /mert/Util.cpp | |
parent | a59ad11b58acf5dd64ec6f5990bb4ef5b74ebf28 (diff) |
run beautify.perl. Consistent formatting for .h & .cpp files
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3899 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert/Util.cpp')
-rw-r--r-- | mert/Util.cpp | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/mert/Util.cpp b/mert/Util.cpp index 93e2231b2..250455bd2 100644 --- a/mert/Util.cpp +++ b/mert/Util.cpp @@ -1,7 +1,7 @@ /* * Util.cpp * met - Minimum Error Training - * + * * Created by Nicola Bertoldi on 13/05/08. * */ @@ -18,47 +18,47 @@ Timer g_timer; int verbose=0; -int verboselevel(){ +int verboselevel() +{ return verbose; } -int setverboselevel(int v){ +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); + 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) + : 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()); + filePath.substr(filePath.size() - 3, 3) == ".gz") { + fb->close(); + delete fb; + m_streambuf = new gzfilebuf(filePath.c_str()); } else { m_streambuf = fb; } @@ -67,7 +67,8 @@ m_streambuf(0) inputfilestream::~inputfilestream() { - delete m_streambuf; m_streambuf = 0; + delete m_streambuf; + m_streambuf = 0; } void inputfilestream::close() @@ -75,16 +76,15 @@ void inputfilestream::close() } outputfilestream::outputfilestream(const std::string &filePath) -: std::ostream(0), -m_streambuf(0) + : 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!"); + _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; } @@ -93,7 +93,8 @@ m_streambuf(0) outputfilestream::~outputfilestream() { - delete m_streambuf; m_streambuf = 0; + delete m_streambuf; + m_streambuf = 0; } void outputfilestream::close() @@ -103,10 +104,14 @@ 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; + for(; n--; p+=sz) for(h=(l=p)+sz; --h>l; l++) { + c=*h; + *h=*l; + *l=c; + } + return 0; }; @@ -116,12 +121,12 @@ void ResetUserTime() }; void PrintUserTime(const std::string &message) -{ - g_timer.check(message.c_str()); +{ + g_timer.check(message.c_str()); } double GetUserTime() { - return g_timer.get_elapsed_time(); + return g_timer.get_elapsed_time(); } |