Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieu@hoang.co.uk>2013-05-29 21:16:15 +0400
committerHieu Hoang <hieu@hoang.co.uk>2013-05-29 21:16:15 +0400
commit6249432407af8730c10bccc7894c0725fcaf5e47 (patch)
tree3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /mert/Fdstream.h
parent59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff)
beautify
Diffstat (limited to 'mert/Fdstream.h')
-rw-r--r--mert/Fdstream.h72
1 files changed, 29 insertions, 43 deletions
diff --git a/mert/Fdstream.h b/mert/Fdstream.h
index 6dbdb40a6..c59052f02 100644
--- a/mert/Fdstream.h
+++ b/mert/Fdstream.h
@@ -13,27 +13,27 @@
#define BUFFER_SIZE (32768)
-namespace MosesTuning
+namespace MosesTuning
{
class _fdstream
{
protected:
_fdstream() :
- _file_descriptor(-1), _filebuf(NULL)
+ _file_descriptor(-1), _filebuf(NULL)
{ }
_fdstream(int file_descriptor, std::ios_base::openmode openmode) :
- _file_descriptor(file_descriptor), _openmode(openmode)
- {
+ _file_descriptor(file_descriptor), _openmode(openmode) {
_filebuf = NULL;
open(file_descriptor, openmode);
}
- std::ios_base::openmode openmode() const { return _openmode; }
+ std::ios_base::openmode openmode() const {
+ return _openmode;
+ }
- void open(int file_descriptor, std::ios_base::openmode openmode)
- {
+ void open(int file_descriptor, std::ios_base::openmode openmode) {
if (!_filebuf)
// We create a C++ stream from a file descriptor
// stdio_filebuf is not synced with stdio.
@@ -41,11 +41,10 @@ protected:
// You can also create the filebuf from a FILE* with
// FILE* f = fdopen(file_descriptor, mode);
_filebuf = new __gnu_cxx::stdio_filebuf<char> (file_descriptor,
- openmode);
+ openmode);
}
- virtual ~_fdstream()
- {
+ virtual ~_fdstream() {
close(_file_descriptor);
delete _filebuf;
_filebuf = NULL;
@@ -60,59 +59,51 @@ class ifdstream : public _fdstream
{
public:
ifdstream() :
- _fdstream(), _stream(NULL)
+ _fdstream(), _stream(NULL)
{ }
ifdstream(int file_descriptor) :
- _fdstream(file_descriptor, std::ios_base::in)
- {
+ _fdstream(file_descriptor, std::ios_base::in) {
_stream = new std::istream(_filebuf);
}
- void open(int file_descriptor)
- {
- if (!_stream)
- {
- _fdstream::open(file_descriptor, std::ios_base::in);
- _stream = new std::istream(_filebuf);
- }
+ void open(int file_descriptor) {
+ if (!_stream) {
+ _fdstream::open(file_descriptor, std::ios_base::in);
+ _stream = new std::istream(_filebuf);
+ }
}
- ifdstream& operator>> (std::string& str)
- {
+ ifdstream& operator>> (std::string& str) {
(*_stream) >> str;
return *this;
}
- std::size_t getline(std::string& str)
- {
+ std::size_t getline(std::string& str) {
char tmp[BUFFER_SIZE];
std::size_t ret = getline(tmp, BUFFER_SIZE);
str = tmp;
return ret;
}
- std::size_t getline(char* s, std::streamsize n)
- {
+ std::size_t getline(char* s, std::streamsize n) {
return (getline(s, n, '\n'));
}
- std::size_t getline(char* s, std::streamsize n, char delim)
- {
+ std::size_t getline(char* s, std::streamsize n, char delim) {
int i = 0;
- do{
+ do {
s[i] = _stream->get();
i++;
- }while(i < n-1 && s[i-1] != delim && s[i-1] != '\0');
+ } while(i < n-1 && s[i-1] != delim && s[i-1] != '\0');
s[i-1] = '\0'; // overwrite the delimiter given with string end
return i-1;
}
- ~ifdstream()
- {
+ ~ifdstream() {
//this->~_fdstream();
delete _stream;
}
@@ -125,27 +116,23 @@ class ofdstream : public _fdstream
{
public:
ofdstream() :
- _fdstream(), _stream(NULL)
+ _fdstream(), _stream(NULL)
{ }
ofdstream(int file_descriptor) :
- _fdstream(file_descriptor, std::ios_base::out)
- {
+ _fdstream(file_descriptor, std::ios_base::out) {
_stream = new std::ostream(_filebuf);
}
- void open(int file_descriptor)
- {
- if (!_stream)
- {
+ void open(int file_descriptor) {
+ if (!_stream) {
_fdstream::open(file_descriptor, std::ios_base::out);
_stream = new std::ostream(_filebuf);
}
}
- ofdstream& operator<< (const std::string& str)
- {
+ ofdstream& operator<< (const std::string& str) {
if (_stream->good())
(*_stream) << str;
@@ -153,8 +140,7 @@ public:
return *this;
}
- ~ofdstream()
- {
+ ~ofdstream() {
//this->~_fdstream();
delete _stream;
}