X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Fbase.cpp;h=b8c13d2193060f94f957178f8f01052c62593d41;hb=991fabc1956b73a4007859058fb44171000b452e;hp=926440a9c4575da477b37e4ad60eea3593ef86a4;hpb=c21ab7e49852585df01b4cc19599e25a918b581b;p=libs%2Fcore.git diff --git a/source/io/base.cpp b/source/io/base.cpp index 926440a..b8c13d2 100644 --- a/source/io/base.cpp +++ b/source/io/base.cpp @@ -6,14 +6,19 @@ using namespace std; namespace Msp { namespace IO { -Base::Base(): - mode(M_READ), - eof_flag(false) +Base::Base() { } Base::~Base() { signal_deleted.emit(); + delete mutex; +} + +void Base::check_access(Mode m) const +{ + if(!(mode&m)) + throw invalid_access(m); } bool Base::getline(string &line) @@ -23,7 +28,7 @@ bool Base::getline(string &line) if(eof_flag) return false; - while(1) + while(!eof()) { int c = get(); if(c==-1 || c=='\n') @@ -42,5 +47,28 @@ int Base::get() return static_cast(c); } +void Base::set_eof() +{ + if(!eof_flag) + { + eof_flag = true; + signal_end_of_file.emit(); + } +} + + +Base::Synchronize::Synchronize(Base &i): + io(i) +{ + if(!io.mutex) + io.mutex = new Mutex; + io.mutex->lock(); +} + +Base::Synchronize::~Synchronize() +{ + io.mutex->unlock(); +} + } // namespace IO } // namespace Msp