]> git.tdb.fi Git - libs/core.git/commitdiff
Style update: spaces around assignments
authorMikko Rasa <tdb@tdb.fi>
Thu, 9 Jun 2011 10:21:27 +0000 (13:21 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 9 Jun 2011 10:21:27 +0000 (13:21 +0300)
13 files changed:
source/base.cpp
source/buffered.cpp
source/console.cpp
source/eventdispatcher.cpp
source/file.cpp
source/file.h
source/filtered.h
source/memory.cpp
source/mode.h
source/pipe.cpp
source/poll.cpp
source/poll.h
source/utils.cpp

index 4556b7303aa669da514ef344d2bd2cdb3662b847..3c9923dd504a728dc1a2f17c2887ff32cc911553 100644 (file)
@@ -21,10 +21,10 @@ bool Base::getline(string &line)
 
        while(1)
        {
-               int c=get();
+               int c = get();
                if(c==-1 || c=='\n')
                        break;
-               line+=c;
+               line += c;
        }
 
        return !eof_flag || !line.empty();
@@ -59,7 +59,7 @@ Base::Base():
 
 void Base::set_events(PollEvent e)
 {
-       events=e;
+       events = e;
        signal_events_changed.emit(events);
 }
 
index 32688db83618d874652fd0926a8d556648e765d7..b8a2dbee7255628fa899c691cac3b041e94f164a 100644 (file)
@@ -22,7 +22,7 @@ Buffered::Buffered(Base &b, unsigned s):
        end(buf),
        cur_op(M_NONE)
 {
-       mode=below.get_mode();
+       mode = below.get_mode();
        below.signal_flush_required.connect(sigc::mem_fun(this, &Buffered::flush));
 }
 
@@ -32,7 +32,7 @@ unsigned Buffered::put(char c)
 
        if(end<buf+buf_size)
        {
-               *end++=c;
+               *end++ = c;
                return 1;
        }
        else
@@ -43,19 +43,19 @@ void Buffered::flush()
 {
        if(cur_op==M_WRITE)
        {
-               unsigned used=end-begin;
+               unsigned used = end-begin;
                if(used)
                {
-                       unsigned len=below.write(begin, used);
+                       unsigned len = below.write(begin, used);
 
-                       begin=end=buf;
+                       begin=end = buf;
 
                        if(len<used)
                                throw Exception("Couldn't flush all data");
                }
        }
        else if(cur_op==M_READ)
-               begin=end=buf;
+               begin=end = buf;
 }
 
 bool Buffered::getline(std::string &line)
@@ -66,7 +66,7 @@ bool Buffered::getline(std::string &line)
                if(*i=='\n')
                {
                        line.assign(begin, i-begin);
-                       begin=i+1;
+                       begin = i+1;
                        return true;
                }
 
@@ -112,7 +112,7 @@ void Buffered::set_op(Mode op)
 {
        if(op!=cur_op)
                flush();
-       cur_op=op;
+       cur_op = op;
 }
 
 unsigned Buffered::do_write(const char *data, unsigned size)
@@ -123,7 +123,7 @@ unsigned Buffered::do_write(const char *data, unsigned size)
        {
                // All data fits in buffer with whatever is already there
                memcpy(end, data, size);
-               end+=size;
+               end += size;
 
                return size;
        }
@@ -136,7 +136,7 @@ unsigned Buffered::do_write(const char *data, unsigned size)
                {
                        // Put new data in the buffer to wait for more
                        memcpy(end, data, size);
-                       end+=size;
+                       end += size;
 
                        return size;
                }
@@ -154,9 +154,9 @@ unsigned Buffered::do_read(char *data, unsigned size)
        {
                // The request can be served from the buffer
                memcpy(data, begin, size);
-               begin+=size;
+               begin += size;
 
-               eof_flag=(below.eof() && begin==end);
+               eof_flag = (below.eof() && begin==end);
 
                return size;
        }
@@ -164,28 +164,28 @@ unsigned Buffered::do_read(char *data, unsigned size)
        {
                // Give out whatever is in the buffer already
                memcpy(data, begin, end-begin);
-               unsigned ret=end-begin;
-               begin=end=buf;
+               unsigned ret = end-begin;
+               begin=end = buf;
 
-               data+=ret;
-               size-=ret;
+               data += ret;
+               size -= ret;
 
                if(size<buf_size)
                {
                        // Fill the buffer and serve the rest of the request from it
-                       unsigned len=below.read(end, buf+buf_size-end);
-                       end+=len;
+                       unsigned len = below.read(end, buf+buf_size-end);
+                       end += len;
 
-                       len=min(static_cast<unsigned>(end-begin), size);
+                       len = min(static_cast<unsigned>(end-begin), size);
                        memcpy(data, begin, len);
-                       begin+=len;
-                       ret+=len;
+                       begin += len;
+                       ret += len;
                }
                else
                        // Read the rest directly from the underlying object
-                       ret+=below.read(data, size);
+                       ret += below.read(data, size);
 
-               eof_flag=(below.eof() && begin==end);
+               eof_flag = (below.eof() && begin==end);
 
                return ret;
        }
index f606a09fcceb64406500dac6c00d9b532b108244..e860436bc4ea6c8b7150b5634ebb805c5a390010 100644 (file)
@@ -30,17 +30,17 @@ Console::Console(unsigned n)
        if(n>2)
                throw InvalidParameterValue("Invalid parameter for Console::Console");
 
-       mode=(n==0 ? M_READ : M_WRITE);
+       mode = (n==0 ? M_READ : M_WRITE);
 
 #ifdef WIN32
        switch(n)
        {
-       case 0: handle=GetStdHandle(STD_INPUT_HANDLE); break;
-       case 1: handle=GetStdHandle(STD_OUTPUT_HANDLE); break;
-       case 2: handle=GetStdHandle(STD_ERROR_HANDLE); break;
+       case 0: handle = GetStdHandle(STD_INPUT_HANDLE); break;
+       case 1: handle = GetStdHandle(STD_OUTPUT_HANDLE); break;
+       case 2: handle = GetStdHandle(STD_ERROR_HANDLE); break;
        }
 #else
-       handle=n;
+       handle = n;
 
        if(handle==0)
                tcgetattr(handle, &orig_attr);
@@ -64,8 +64,8 @@ void Console::set_block(bool b)
        // XXX Dunno how to do this in win32
        (void)b;
 #else
-       int flags=fcntl(0, F_GETFL);
-       flags=(flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
+       int flags = fcntl(0, F_GETFL);
+       flags = (flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
        fcntl(0, F_SETFL, flags);
 #endif
 }
@@ -82,7 +82,7 @@ void Console::set_local_echo(bool e)
 #else
        termios t;
        tcgetattr(0, &t);
-       t.c_lflag=(t.c_lflag&~ECHO) | (e?ECHO:0);
+       t.c_lflag = (t.c_lflag&~ECHO) | (e?ECHO:0);
        tcsetattr(0, TCSADRAIN, &t);
 #endif
 }
@@ -100,7 +100,7 @@ void Console::set_line_buffer(bool l)
        // XXX ICANON does more than just set line buffering, may need a bit more thought
        termios t;
        tcgetattr(0, &t);
-       t.c_lflag=(t.c_lflag&~ICANON) | (l?ICANON:0);
+       t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0);
        tcsetattr(0, TCSADRAIN, &t);
 #endif
 }
@@ -112,13 +112,13 @@ void Console::get_size(unsigned &rows, unsigned &cols)
 
 #ifdef WIN32
        // XXX Figure out how to do this
-       rows=24;
-       cols=80;
+       rows = 24;
+       cols = 80;
 #else
        struct winsize wsz;
        ioctl(handle, TIOCGWINSZ, &wsz);
-       rows=wsz.ws_row;
-       cols=wsz.ws_col;
+       rows = wsz.ws_row;
+       cols = wsz.ws_col;
 #endif
 }
 
@@ -137,7 +137,7 @@ unsigned Console::do_write(const char *buf, unsigned len)
        if(!WriteFile(handle, buf, len, &ret, 0))
                throw SystemError("Writing to console failed", GetLastError());
 #else
-       int ret=::write(handle, buf, len);
+       int ret = ::write(handle, buf, len);
        if(ret==-1)
                throw SystemError("Writing to console failed", errno);
 #endif
@@ -155,7 +155,7 @@ unsigned Console::do_read(char *buf, unsigned len)
        if(!ReadFile(handle, buf, len, &ret, 0))
                throw SystemError("Reading from console failed", GetLastError());
 #else
-       int ret=::read(handle, buf, len);
+       int ret = ::read(handle, buf, len);
        if(ret==-1)
        {
                if(errno==EAGAIN)
@@ -164,7 +164,7 @@ unsigned Console::do_read(char *buf, unsigned len)
                        throw SystemError("Reading from console failed", errno);
        }
        else if(ret==0)
-               eof_flag=true;
+               eof_flag = true;
 #endif
 
        return ret;
@@ -186,9 +186,9 @@ Console &Console::instance(unsigned n)
        throw InvalidParameterValue("Unknown Console instance requested");
 }
 
-Console &cin=Console::instance(0);
-Console &cout=Console::instance(1);
-Console &cerr=Console::instance(2);
+Console &cin = Console::instance(0);
+Console &cout = Console::instance(1);
+Console &cerr = Console::instance(2);
 
 } // namespace IO
 } // namespace Msp
index d7e367c67e7141e34d213a607d3d00c859aa4b71..02330ec11fd7db97e7025703b57b246380daab5f 100644 (file)
@@ -17,12 +17,12 @@ EventDispatcher::EventDispatcher()
 
 void EventDispatcher::add(Base &obj)
 {
-       SlotMap::iterator i=objects.find(&obj);
+       SlotMap::iterator i = objects.find(&obj);
        if(i==objects.end())
        {
-               i=objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
-               i->second.evch_conn=obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
-               i->second.del_conn=obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
+               i = objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
+               i->second.evch_conn = obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
+               i->second.del_conn = obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
 
                if(obj.get_events())
                        poller.set_object(obj, obj.get_events());
@@ -31,7 +31,7 @@ void EventDispatcher::add(Base &obj)
 
 void EventDispatcher::remove(Base &obj)
 {
-       SlotMap::iterator i=objects.find(&obj);
+       SlotMap::iterator i = objects.find(&obj);
        if(i!=objects.end())
        {
                i->second.evch_conn.disconnect();
@@ -72,7 +72,7 @@ void EventDispatcher::object_deleted(Base *obj)
 
 void EventDispatcher::dispatch()
 {
-       const Poller::SlotSeq &result=poller.get_result();
+       const Poller::SlotSeq &result = poller.get_result();
        for(Poller::SlotSeq::const_iterator i=result.begin(); i!=result.end(); ++i)
                i->object->event(i->events);
 }
index 6ef338888b24b610b0d61f7bcaa06d9fec2594fa..0b153cf44b08460a42338decd2918faccb9f166e 100644 (file)
@@ -34,62 +34,62 @@ File::File(const string &fn, Mode m, CreateMode cm)
        if(cm&~(C_CREATE|C_TRUNCATE))
                throw InvalidParameterValue("Invalid create mode");
 
-       mode=m;
+       mode = m;
 
 #ifdef WIN32
-       int flags=0;
-       int create_flags=OPEN_EXISTING;
+       int flags = 0;
+       int create_flags = OPEN_EXISTING;
 
        if(mode&M_READ)
-               flags|=GENERIC_READ;
+               flags |= GENERIC_READ;
        else if(mode&M_WRITE)
        {
-               flags|=GENERIC_WRITE;
+               flags |= GENERIC_WRITE;
 
                switch(static_cast<int>(cm))
                {
-               case C_NONE:     create_flags=OPEN_EXISTING; break;
-               case C_CREATE:   create_flags=OPEN_ALWAYS; break;
-               case C_TRUNCATE: create_flags=TRUNCATE_EXISTING; break;
-               case C_CREATE+C_TRUNCATE: create_flags=CREATE_ALWAYS; break;
+               case C_NONE:     create_flags = OPEN_EXISTING; break;
+               case C_CREATE:   create_flags = OPEN_ALWAYS; break;
+               case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break;
+               case C_CREATE+C_TRUNCATE: create_flags = CREATE_ALWAYS; break;
                }
        }
 
-       handle=CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0);
+       handle = CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0);
        if(handle==INVALID_HANDLE_VALUE)
        {
-               int err=GetLastError();
+               int err = GetLastError();
                if(err==ERROR_FILE_NOT_FOUND)
                        throw FileNotFound("Can't find file "+fn, fn);
                else
                        throw SystemError(format("Can't open file '%s'", fn), GetLastError());
        }
 #else
-       int flags=0;
+       int flags = 0;
        switch(mode&M_RDWR)
        {
-       case M_READ:  flags|=O_RDONLY; break;
-       case M_WRITE: flags|=O_WRONLY; break;
-       case M_RDWR:  flags|=O_RDWR; break;
+       case M_READ:  flags |= O_RDONLY; break;
+       case M_WRITE: flags |= O_WRONLY; break;
+       case M_RDWR:  flags |= O_RDWR; break;
        default:;
        }
 
        if(mode&M_WRITE)
        {
                if(cm&C_CREATE)
-                       flags|=O_CREAT;
+                       flags |= O_CREAT;
                if(cm&C_TRUNCATE)
-                       flags|=O_TRUNC;
+                       flags |= O_TRUNC;
        }
        if(mode&M_APPEND)
-               flags|=O_APPEND;
+               flags |= O_APPEND;
        if(mode&M_NONBLOCK)
-               flags|=O_NONBLOCK;
+               flags |= O_NONBLOCK;
 
-       handle=::open(fn.c_str(), flags, 0666);
+       handle = ::open(fn.c_str(), flags, 0666);
        if(handle==-1)
        {
-               int err=errno;
+               int err = errno;
                if(err==ENOENT)
                        throw FileNotFound("Can't find file "+fn, fn);
                else
@@ -119,7 +119,7 @@ void File::close()
        ::close(handle);
 #endif
 
-       handle=MSP_IO_INVALID_HANDLE;
+       handle = MSP_IO_INVALID_HANDLE;
        signal_closed.emit();
 }
 
@@ -131,11 +131,11 @@ void File::set_block(bool b)
 {
        check_access(M_NONE);
 
-       mode=(mode&~M_NONBLOCK);
+       mode = (mode&~M_NONBLOCK);
        if(b)
-               mode=(mode|M_NONBLOCK);
+               mode = (mode|M_NONBLOCK);
 #ifndef WIN32
-       int flags=fcntl(handle, F_GETFD);
+       int flags = fcntl(handle, F_GETFD);
        fcntl(handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
 #endif
 }
@@ -163,18 +163,18 @@ int File::seek(int off, SeekType st)
 
        signal_flush_required.emit();
 
-       int type=sys_seek_type(st);
+       int type = sys_seek_type(st);
 #ifdef WIN32
-       DWORD ret=SetFilePointer(handle, off, 0, type);
+       DWORD ret = SetFilePointer(handle, off, 0, type);
        if(ret==INVALID_SET_FILE_POINTER)
                throw SystemError("Seek failed", GetLastError());
 #else
-       int ret=lseek(handle, off, type);
+       int ret = lseek(handle, off, type);
        if(ret==-1)
                throw SystemError("Seek failed", errno);
 #endif
 
-       eof_flag=false;
+       eof_flag = false;
 
        return ret;
 }
@@ -187,11 +187,11 @@ int File::tell() const
        check_access(M_NONE);
 
 #ifdef WIN32
-       DWORD ret=SetFilePointer(handle, 0, 0, FILE_CURRENT);
+       DWORD ret = SetFilePointer(handle, 0, 0, FILE_CURRENT);
        if(ret==INVALID_SET_FILE_POINTER)
                throw SystemError("Tell failed", GetLastError());
 #else
-       int ret=lseek(handle, 0, SEEK_CUR);
+       int ret = lseek(handle, 0, SEEK_CUR);
        if(ret==-1)
                throw SystemError("Tell failed", errno);
 #endif
@@ -236,7 +236,7 @@ unsigned File::do_write(const char *buf, unsigned size)
        if(WriteFile(handle, buf, size, &ret, 0)==0)
                throw SystemError("Writing to file failed", GetLastError());
 #else
-       int ret=::write(handle, buf, size);
+       int ret = ::write(handle, buf, size);
        if(ret==-1)
        {
                if(errno==EAGAIN)
@@ -269,7 +269,7 @@ unsigned File::do_read(char *buf, unsigned size)
        if(ReadFile(handle, buf, size, &ret, 0)==0)
                throw SystemError("Reading from file failed", GetLastError());
 #else
-       int ret=::read(handle, buf, size);
+       int ret = ::read(handle, buf, size);
        if(ret==-1)
        {
                if(errno==EAGAIN)
@@ -281,7 +281,7 @@ unsigned File::do_read(char *buf, unsigned size)
 
        if(ret==0)
        {
-               eof_flag=true;
+               eof_flag = true;
                signal_end_of_file.emit();
        }
 
index 4e86e29642c47dd35b52b0978b6b7be7b38d05f8..16f2dcbe4b5490da384006982f56be6dbc728065 100644 (file)
@@ -26,12 +26,12 @@ class File: public Base
 public:
        enum CreateMode
        {
-               C_NONE=0,
-               C_CREATE=1,
-               C_TRUNCATE=2
+               C_NONE = 0,
+               C_CREATE = 1,
+               C_TRUNCATE = 2
        };
 
-       File(const std::string &, Mode=M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE));
+       File(const std::string &, Mode = M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE));
 
        void close();
 
index e3ff219834aac6641260b58abb324353b0bd041a..ff8577acb77386bae2f438e89bd84ee98b06b124 100644 (file)
@@ -19,8 +19,8 @@ private:
        {
                Filtered &f;
 
-               Activator(Filtered &f_): f(f_) { f.active=true; }
-               ~Activator() { f.active=false; }
+               Activator(Filtered &f_): f(f_) { f.active = true; }
+               ~Activator() { f.active = false; }
        };
 
        F filter;
@@ -28,7 +28,7 @@ private:
 
 public:
        Filtered(): filter(*this), active(false) { }
-       ~Filtered() { active=true; }
+       ~Filtered() { active = true; }
 
        template<typename A0>
        Filtered(A0 a0): B(a0), filter(*this), active(false) { }
index c44554ae5a4f9b59f7347befabc552c3fe190bf8..80dde272625a25ed2a7b644460e7f576c853f7aa 100644 (file)
@@ -27,7 +27,7 @@ Memory::Memory(char *b, char *e)
 
 Memory::Memory(const char *cd, unsigned s)
 {
-       char *d=const_cast<char *>(cd);
+       char *d = const_cast<char *>(cd);
        init(d, d+s, M_READ);
 }
 
@@ -38,25 +38,25 @@ Memory::Memory(const char *b, const char *e)
 
 void Memory::init(char *b, char *e, Mode m)
 {
-       begin=b;
-       end=e;
-       pos=begin;
-       mode=m;
+       begin = b;
+       end = e;
+       pos = begin;
+       mode = m;
 }
 
 unsigned Memory::put(char c)
 {
        check_mode(M_WRITE);
-       *pos++=c;
+       *pos++ = c;
        return 1;
 }
 
 bool Memory::getline(string &line)
 {
-       char *nl=find(pos, end, '\n');
+       char *nl = find(pos, end, '\n');
        line.assign(pos, nl);
-       bool result=(nl!=pos);
-       pos=nl;
+       bool result = (nl!=pos);
+       pos = nl;
        return result;
 }
 
@@ -64,7 +64,7 @@ int Memory::get()
 {
        if(pos==end)
        {
-               eof_flag=true;
+               eof_flag = true;
                return -1;
        }
 
@@ -75,18 +75,18 @@ unsigned Memory::seek(int off, SeekType type)
 {
        char *new_pos;
        if(type==S_BEG)
-               new_pos=begin+off;
+               new_pos = begin+off;
        else if(type==S_CUR)
-               new_pos=pos+off;
+               new_pos = pos+off;
        else if(type==S_END)
-               new_pos=end+off;
+               new_pos = end+off;
        else
                throw InvalidParameterValue("Invalid seek type");
 
        if(new_pos<begin || new_pos>end)
                throw InvalidParameterValue("Invalid seek offset");
 
-       pos=new_pos;
+       pos = new_pos;
        return pos-begin;
 }
 
@@ -99,9 +99,9 @@ unsigned Memory::do_write(const char *buf, unsigned size)
 {
        check_mode(M_WRITE);
 
-       size=min<unsigned>(size, end-pos);
+       size = min<unsigned>(size, end-pos);
        memcpy(pos, buf, size);
-       pos+=size;
+       pos += size;
        return size;
 }
 
@@ -109,13 +109,13 @@ unsigned Memory::do_read(char *buf, unsigned size)
 {
        if(pos==end)
        {
-               eof_flag=true;
+               eof_flag = true;
                return 0;
        }
 
-       size=min<unsigned>(size, end-pos);
+       size = min<unsigned>(size, end-pos);
        memcpy(buf, pos, size);
-       pos+=size;
+       pos += size;
        return size;
 }
 
index c58ecb0bd55894474b5b828859a7ea9939d5bef0..d807e5f7b7a865eaad8017c165284c816f6bd49c 100644 (file)
@@ -12,12 +12,12 @@ namespace IO {
 
 enum Mode
 {
-       M_NONE=0,
-       M_READ=1,
-       M_WRITE=2,
-       M_RDWR=M_READ|M_WRITE,
-       M_APPEND=4,
-       M_NONBLOCK=8
+       M_NONE = 0,
+       M_READ = 1,
+       M_WRITE = 2,
+       M_RDWR = M_READ|M_WRITE,
+       M_APPEND = 4,
+       M_NONBLOCK = 8
 };
 
 inline Mode operator|(Mode m, Mode n)
index 696abe5c5695c89d45c048ec2af2946b68a23c1b..bd905271c07c54be62e07c57aecbdc4b063d2d51 100644 (file)
@@ -20,25 +20,25 @@ namespace IO {
 Pipe::Pipe()
 {
 #ifdef WIN32
-       string name=format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
-       handle[0]=CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
+       string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
+       handle[0] = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
        if(handle[0]==INVALID_HANDLE_VALUE)
                throw SystemError("Unable to create pipe", GetLastError());
 
-       handle[1]=CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+       handle[1] = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
        if(handle[1]==INVALID_HANDLE_VALUE)
        {
-               unsigned err=GetLastError();
+               unsigned err = GetLastError();
                CloseHandle(handle[0]);
                throw SystemError("Unable to create pipe", err);
        }
 
-       overlapped=0;
-       event=CreateEvent(0, true, false, 0);
-       buf_size=1024;
-       buffer=new char[buf_size];
-       buf_avail=0;
-       buf_next=buffer;
+       overlapped = 0;
+       event = CreateEvent(0, true, false, 0);
+       buf_size = 1024;
+       buffer = new char[buf_size];
+       buf_avail = 0;
+       buf_next = buffer;
 #else
        if(pipe(handle)==-1)
                throw SystemError("Unable to create pipe", errno);
@@ -49,14 +49,14 @@ Pipe::Pipe()
 
 void Pipe::set_block(bool b)
 {
-       mode=(mode&~M_NONBLOCK);
+       mode = (mode&~M_NONBLOCK);
        if(b)
-               mode=(mode|M_NONBLOCK);
+               mode = (mode|M_NONBLOCK);
 
 #ifndef WIN32
-       int flags=fcntl(handle[0], F_GETFD);
+       int flags = fcntl(handle[0], F_GETFD);
        fcntl(handle[0], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
-       flags=fcntl(handle[1], F_GETFD);
+       flags = fcntl(handle[1], F_GETFD);
        fcntl(handle[1], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
 #endif
 }
@@ -81,23 +81,23 @@ Handle Pipe::get_event_handle()
 #ifdef WIN32
        if(!overlapped && !buf_avail)
        {
-               overlapped=new OVERLAPPED;
+               overlapped = new OVERLAPPED;
                memset(overlapped, 0, sizeof(OVERLAPPED));
-               overlapped->hEvent=event;
+               overlapped->hEvent = event;
 
                DWORD ret;
-               buf_next=buffer;
+               buf_next = buffer;
                if(!ReadFile(handle[0], buffer, buf_size, &ret, overlapped))
                {
-                       unsigned err=GetLastError();
+                       unsigned err = GetLastError();
                        if(err!=ERROR_IO_PENDING)
                                throw SystemError("Failed to start an overlapped read", err);
                }
                else
                {
-                       buf_avail=ret;
+                       buf_avail = ret;
                        delete overlapped;
-                       overlapped=0;
+                       overlapped = 0;
                        SetEvent(event);
                }
        }
@@ -123,7 +123,7 @@ unsigned Pipe::do_write(const char *buf, unsigned size)
        if(!WriteFile(handle[1], buf, size, &ret, 0))
                throw SystemError("Writing to pipe failed", GetLastError());
 #else
-       int ret=::write(handle[1], buf, size);
+       int ret = ::write(handle[1], buf, size);
        if(ret==-1)
        {
                if(errno==EAGAIN)
@@ -152,21 +152,21 @@ unsigned Pipe::do_read(char *buf, unsigned size)
                        throw SystemError("Reading from pipe failed", GetLastError());
                else
                {
-                       buf_avail+=ret;
+                       buf_avail += ret;
                        delete overlapped;
-                       overlapped=0;
+                       overlapped = 0;
                }
        }
 
-       unsigned ret=min(buf_avail, size);
+       unsigned ret = min(buf_avail, size);
        memcpy(buf, buf_next, ret);
-       buf_next+=ret;
-       buf_avail-=ret;
+       buf_next += ret;
+       buf_avail -= ret;
 
        // Initiate another overlapped read in case someone is polling us
        get_event_handle();
 #else
-       int ret=::read(handle[0], buf, size);
+       int ret = ::read(handle[0], buf, size);
        if(ret==-1)
        {
                if(errno==EAGAIN)
@@ -178,7 +178,7 @@ unsigned Pipe::do_read(char *buf, unsigned size)
 
        if(ret==0)
        {
-               eof_flag=true;
+               eof_flag = true;
                signal_end_of_file.emit();
        }
 
index 659e2385ff5c5c3dadf0ffea2bde277e1bdfb711..49e48870a071f48f44c13ce5c4da67fa5f91a5e0 100644 (file)
@@ -18,18 +18,18 @@ using namespace Msp::IO;
 
 inline int sys_poll_event(PollEvent event)
 {
-       int result=0;
+       int result = 0;
 
        if(event&~(P_INPUT|P_PRIO|P_OUTPUT))
                throw InvalidParameterValue("Invalid poll events");
 
 #ifndef WIN32
        if(event&P_INPUT)
-               result|=POLLIN;
+               result |= POLLIN;
        if(event&P_PRIO)
-               result|=POLLPRI;
+               result |= POLLPRI;
        if(event&P_OUTPUT)
-               result|=POLLOUT;
+               result |= POLLOUT;
 #endif
 
        return result;
@@ -37,20 +37,20 @@ inline int sys_poll_event(PollEvent event)
 
 inline PollEvent poll_event_from_sys(int event)
 {
-       PollEvent result=P_NONE;
+       PollEvent result = P_NONE;
 
 #ifdef WIN32
        // Stop the compiler from complaining about unused parameter
-       event=event;
+       event = event;
 #else
        if(event&POLLIN)
-               result=result|P_INPUT;
+               result = result|P_INPUT;
        if(event&POLLPRI)
-               result=result|P_PRIO;
+               result = result|P_PRIO;
        if(event&POLLOUT)
-               result=result|P_OUTPUT;
+               result = result|P_OUTPUT;
        if(event&POLLERR)
-               result=result|P_ERROR;
+               result = result|P_ERROR;
 #endif
 
        return result;
@@ -60,9 +60,9 @@ inline PollEvent do_poll(Base &obj, PollEvent pe, int timeout)
 {
 #ifdef WIN32
        if(timeout<0)
-               timeout=INFINITE;
+               timeout = INFINITE;
 
-       DWORD ret=WaitForSingleObject(obj.get_event_handle(), timeout);
+       DWORD ret = WaitForSingleObject(obj.get_event_handle(), timeout);
        if(ret==WAIT_OBJECT_0)
                return pe;
        else if(ret==WAIT_FAILED)
@@ -70,9 +70,9 @@ inline PollEvent do_poll(Base &obj, PollEvent pe, int timeout)
 
        return P_NONE;
 #else
-       pollfd pfd={obj.get_event_handle(), sys_poll_event(pe), 0};
+       pollfd pfd = {obj.get_event_handle(), sys_poll_event(pe), 0};
 
-       int ret=::poll(&pfd, 1, timeout);
+       int ret = ::poll(&pfd, 1, timeout);
        if(ret==-1)
        {
                if(errno==EINTR)
@@ -100,15 +100,15 @@ void Poller::set_object(Base &obj, PollEvent ev)
        if(ev)
                obj.get_event_handle();
 
-       SlotMap::iterator i=objects.find(&obj);
+       SlotMap::iterator i = objects.find(&obj);
        if(i!=objects.end())
        {
                if(ev)
-                       i->second.events=ev;
+                       i->second.events = ev;
                else
                        objects.erase(i);
 
-               pfd_dirty=true;
+               pfd_dirty = true;
        }
        else if(ev)
        {
@@ -118,7 +118,7 @@ void Poller::set_object(Base &obj, PollEvent ev)
 #endif
                objects.insert(SlotMap::value_type(&obj, Slot(&obj, ev)));
 
-               pfd_dirty=true;
+               pfd_dirty = true;
        }
 }
 
@@ -143,14 +143,14 @@ void Poller::rebuild_pfd()
 
        for(SlotMap::iterator i=objects.begin(); i!=objects.end(); ++i)
        {
-               p.fd=i->second.object->get_event_handle();
+               p.fd = i->second.object->get_event_handle();
 #ifndef WIN32
-               p.events=sys_poll_event(i->second.events);
+               p.events = sys_poll_event(i->second.events);
 #endif
                pfd.push_back(p);
        }
 
-       pfd_dirty=false;
+       pfd_dirty = false;
 }
 
 int Poller::do_poll(int timeout)
@@ -162,12 +162,12 @@ int Poller::do_poll(int timeout)
 
 #ifdef WIN32
        if(timeout<0)
-               timeout=INFINITE;
+               timeout = INFINITE;
 
-       DWORD ret=WaitForMultipleObjects(pfd.size(), &pfd.front().fd, false, timeout);
+       DWORD ret = WaitForMultipleObjects(pfd.size(), &pfd.front().fd, false, timeout);
        if(/*ret>=WAIT_OBJECT_0 &&*/ ret<WAIT_OBJECT_0+pfd.size())
        {
-               SlotMap::iterator i=objects.begin();
+               SlotMap::iterator i = objects.begin();
                advance(i, ret-WAIT_OBJECT_0);
                poll_result.push_back(Slot(i->second.object, i->second.events));
 
@@ -178,7 +178,7 @@ int Poller::do_poll(int timeout)
 
        return 0;
 #else
-       int ret=::poll(&pfd.front(), pfd.size(), timeout);
+       int ret = ::poll(&pfd.front(), pfd.size(), timeout);
        if(ret==-1)
        {
                if(errno==EINTR)
@@ -187,8 +187,8 @@ int Poller::do_poll(int timeout)
                        throw SystemError("Poll failed", errno);
        }
 
-       int n=ret;
-       SlotMap::iterator j=objects.begin();
+       int n = ret;
+       SlotMap::iterator j = objects.begin();
        for(std::vector<pollfd>::iterator i=pfd.begin(); (i!=pfd.end() && n>0); ++i,++j)
                if(i->revents)
                {
index 3bc14701d487ffccad35e4d8740996642595346b..3566b92569c6103ffa502599fb9aded1210ba631 100644 (file)
@@ -23,11 +23,11 @@ class Base;
 
 enum PollEvent
 {
-       P_NONE=0,
-       P_INPUT=1,
-       P_PRIO=2,
-       P_OUTPUT=4,
-       P_ERROR=8
+       P_NONE = 0,
+       P_INPUT = 1,
+       P_PRIO = 2,
+       P_OUTPUT = 4,
+       P_ERROR = 8
 };
 
 inline PollEvent operator|(PollEvent e, PollEvent f)
index 8ce5bf327edb21b76a1f5874cb3dcb28c3a314f5..1905fe0cf2254594f5e06d7abd8271877a087766 100644 (file)
@@ -12,9 +12,9 @@ namespace IO {
 
 unsigned read_all(Base &obj, char *buf, unsigned size)
 {
-       unsigned pos=0;
+       unsigned pos = 0;
        while(pos<size)
-               pos+=obj.read(buf+pos, size-pos);
+               pos += obj.read(buf+pos, size-pos);
 
        return pos;
 }