From: Mikko Rasa Date: Sat, 2 Dec 2017 14:41:22 +0000 (+0200) Subject: Make certain functions pure virtual so I won't forget to implement them X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=481b844ed7d180ffbf70223075f2fc1ffdb5b444;p=libs%2Fcore.git Make certain functions pure virtual so I won't forget to implement them --- diff --git a/source/io/base.cpp b/source/io/base.cpp index 95a3685..9c2b40a 100644 --- a/source/io/base.cpp +++ b/source/io/base.cpp @@ -59,11 +59,6 @@ void Base::set_eof() } } -const Handle &Base::get_handle(Mode) -{ - throw logic_error("Base::get_handle"); -} - Base::Synchronize::Synchronize(Base &i): io(i) diff --git a/source/io/base.h b/source/io/base.h index 8d29caf..1fe143e 100644 --- a/source/io/base.h +++ b/source/io/base.h @@ -57,7 +57,7 @@ public: was done. Blocking is enabled by default. */ - virtual void set_block(bool) { } + virtual void set_block(bool) = 0; /** Returns the current mode flags. */ Mode get_mode() const { return mode; } @@ -105,7 +105,7 @@ public: /** Returns the system-level handle for the object. Used by Console to perform redirections. */ - virtual const Handle &get_handle(Mode); + virtual const Handle &get_handle(Mode) = 0; }; } // namespace IO diff --git a/source/io/buffered.cpp b/source/io/buffered.cpp index 53f8391..6567fff 100644 --- a/source/io/buffered.cpp +++ b/source/io/buffered.cpp @@ -32,6 +32,11 @@ Buffered::~Buffered() delete[] buf; } +void Buffered::set_block(bool) +{ + throw logic_error("Buffered::set_block"); +} + void Buffered::flush() { if(cur_op==M_WRITE) @@ -168,6 +173,11 @@ int Buffered::get() return static_cast(c); } +const Handle &Buffered::get_handle(Mode) +{ + throw logic_error("Buffered::get_handle"); +} + void Buffered::set_op(Mode op) { if(op!=cur_op) diff --git a/source/io/buffered.h b/source/io/buffered.h index bda2318..c88f0f8 100644 --- a/source/io/buffered.h +++ b/source/io/buffered.h @@ -21,6 +21,8 @@ public: Buffered(Base &, unsigned =8192); ~Buffered(); + virtual void set_block(bool); + void flush(); protected: @@ -32,6 +34,8 @@ public: bool getline(std::string &); int get(); + virtual const Handle &get_handle(Mode); + private: void set_op(Mode); public: diff --git a/source/io/file.cpp b/source/io/file.cpp index d44dad3..ab957c9 100644 --- a/source/io/file.cpp +++ b/source/io/file.cpp @@ -91,6 +91,11 @@ BufferedFile::BufferedFile(const string &fn, Mode m, File::CreateMode cm): file.signal_end_of_file.connect(sigc::mem_fun(this, &BufferedFile::set_eof)); } +void BufferedFile::set_block(bool b) +{ + file.set_block(b); +} + unsigned BufferedFile::do_write(const char *buf, unsigned size) { unsigned ret = buffer.write(buf, size); @@ -128,6 +133,11 @@ int BufferedFile::get() return ret; } +const Handle &BufferedFile::get_handle(Mode) +{ + throw logic_error("BufferedFile::get_handle"); +} + SeekOffset BufferedFile::seek(SeekOffset offset, SeekType type) { if(type==S_CUR) diff --git a/source/io/file.h b/source/io/file.h index d342734..ececa8d 100644 --- a/source/io/file.h +++ b/source/io/file.h @@ -57,7 +57,7 @@ private: public: virtual ~File(); - void set_block(bool); + virtual void set_block(bool); protected: virtual unsigned do_write(const char *, unsigned); @@ -92,6 +92,8 @@ private: public: BufferedFile(const std::string &, Mode = M_READ, File::CreateMode = File::C_OVERWRITE); + virtual void set_block(bool); + protected: virtual unsigned do_write(const char *, unsigned); virtual unsigned do_read(char *, unsigned); @@ -101,6 +103,8 @@ public: virtual bool getline(std::string &); virtual int get(); + virtual const Handle &get_handle(Mode); + virtual SeekOffset seek(SeekOffset, SeekType); virtual SeekOffset tell() const { return position; } }; diff --git a/source/io/memory.cpp b/source/io/memory.cpp index 37954cc..c5aee1e 100644 --- a/source/io/memory.cpp +++ b/source/io/memory.cpp @@ -37,6 +37,11 @@ void Memory::init(char *b, char *e, Mode m) mode = m; } +void Memory::set_block(bool) +{ + throw logic_error("Memory::set_block"); +} + unsigned Memory::do_write(const char *buf, unsigned size) { check_access(M_WRITE); @@ -103,6 +108,11 @@ int Memory::get() return static_cast(*pos++); } +const Handle &Memory::get_handle(Mode) +{ + throw logic_error("Memory::get_handle"); +} + SeekOffset Memory::seek(SeekOffset off, SeekType type) { char *new_pos; diff --git a/source/io/memory.h b/source/io/memory.h index 4ae8eec..4df2aa3 100644 --- a/source/io/memory.h +++ b/source/io/memory.h @@ -21,6 +21,10 @@ public: private: void init(char *, char *, Mode); +public: + virtual void set_block(bool); + +private: virtual unsigned do_write(const char *, unsigned); virtual unsigned do_read(char *, unsigned); public: @@ -28,6 +32,8 @@ public: virtual bool getline(std::string &); virtual int get(); + virtual const Handle &get_handle(Mode); + virtual SeekOffset seek(SeekOffset, SeekType); virtual SeekOffset tell() const { return pos-begin; } }; diff --git a/source/io/pipe.h b/source/io/pipe.h index 3f964f4..2b2b76e 100644 --- a/source/io/pipe.h +++ b/source/io/pipe.h @@ -23,7 +23,7 @@ public: ~Pipe(); void set_mode(Mode); - void set_block(bool); + virtual void set_block(bool); protected: virtual unsigned do_write(const char *, unsigned); diff --git a/source/io/slice.cpp b/source/io/slice.cpp index 9b7ba54..d53a63b 100644 --- a/source/io/slice.cpp +++ b/source/io/slice.cpp @@ -21,6 +21,11 @@ Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l): below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush)); } +void Slice::set_block(bool) +{ + throw logic_error("Slice::set_block"); +} + void Slice::flush() { sync_position = true; @@ -98,6 +103,11 @@ int Slice::get() return c; } +const Handle &Slice::get_handle(Mode) +{ + throw logic_error("Slice::get_handle"); +} + SeekOffset Slice::seek(SeekOffset off, SeekType type) { Base::Synchronize sync(below); diff --git a/source/io/slice.h b/source/io/slice.h index bcfef50..fb45014 100644 --- a/source/io/slice.h +++ b/source/io/slice.h @@ -28,6 +28,8 @@ private: public: Slice(Seekable &, SeekOffset, SeekOffset); + virtual void set_block(bool); + private: void flush(); @@ -40,6 +42,8 @@ public: virtual unsigned put(char); virtual int get(); + virtual const Handle &get_handle(Mode); + virtual SeekOffset seek(SeekOffset, SeekType); virtual SeekOffset tell() const { return position; } }; diff --git a/source/io/zlibcompressed.cpp b/source/io/zlibcompressed.cpp index ffb08c5..99ae7f8 100644 --- a/source/io/zlibcompressed.cpp +++ b/source/io/zlibcompressed.cpp @@ -113,6 +113,11 @@ ZlibCompressed::~ZlibCompressed() delete priv; } +void ZlibCompressed::set_block(bool) +{ + throw logic_error("ZlibCompressed::set_block"); +} + void ZlibCompressed::flush() { #ifdef WITH_ZLIB @@ -268,5 +273,10 @@ unsigned ZlibCompressed::do_read(char *data, unsigned size) return processed; } +const Handle &ZlibCompressed::get_handle(Mode) +{ + throw logic_error("ZlibCompressed::get_handle"); +} + } // namespace IO } // namespace Msp diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index 30894cb..fc559fe 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -56,6 +56,8 @@ private: public: virtual ~ZlibCompressed(); + virtual void set_block(bool); + void flush(); protected: @@ -70,6 +72,8 @@ private: public: virtual unsigned do_read(char *, unsigned); + + virtual const Handle &get_handle(Mode); }; } // namespace IO