From e5804f2cb929083713c0082f39182a858c082587 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 26 Oct 2011 11:47:38 -0700 Subject: Protecting the IO class a bit more, and adding the raw filename paradigm for at least the Input class. --- includes/Handle.h | 7 ++++--- includes/Input.h | 2 ++ src/Input.cc | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/Handle.h b/includes/Handle.h index 96f1736..321d8db 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -63,7 +63,7 @@ class IOBase { IOBase() : m_h(NULL) { } ~IOBase() { if (m_h) m_h->delRef(); } protected: - void setHandle(Handle * h) { m_h = h; m_h->addRef(); } + void setHandle(Handle * h) { m_h = h; if (m_h) m_h->addRef(); } Handle * m_h; template friend class IO; @@ -74,11 +74,12 @@ class IO : public IOBase { public: IO() { } IO(T * h) { setHandle(h); } - IO(const IO & io) { setHandle(io.m_h); } + IO(const IO & io) { if (io.m_h) setHandle(io.m_h); } template - IO(const IO & io) { setHandle(io.m_h); } + IO(const IO & io) { if (io.m_h) setHandle(io.m_h); } IO & operator=(const IO & io) { if (m_h) m_h->delRef(); setHandle(io.m_h); return *this; } T * operator->() { Assert(m_h); return dynamic_cast(m_h); } + bool isNull() { return dynamic_cast(m_h); } }; class SeekableHandle : public Handle { diff --git a/includes/Input.h b/includes/Input.h index 518db39..9d45baa 100644 --- a/includes/Input.h +++ b/includes/Input.h @@ -14,9 +14,11 @@ class Input : public SeekableHandle { virtual const char * getName(); virtual off_t getSize(); virtual time_t getMTime(); + const char * getFName() { return m_fname.to_charp(); } private: int m_fd; String m_name; + String m_fname; off_t m_size; time_t m_mtime; }; diff --git a/src/Input.cc b/src/Input.cc index 8f16321..73a2a0a 100644 --- a/src/Input.cc +++ b/src/Input.cc @@ -9,7 +9,7 @@ #include "Printer.h" #ifdef _WIN32 -const char * strerror_r(int errorno, char * buf, size_t bufsize) { +static const char * strerror_r(int errorno, char * buf, size_t bufsize) { #ifdef _MSVC strerror_s(buf, bufsize, errorno); return buf; @@ -49,6 +49,7 @@ static int eioStatsDone(eio_req * req) { Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1), m_size(-1), m_mtime(-1) { m_name.set("Input(%s)", fname); + m_fname = fname; Printer::elog(E_INPUT, "Opening file %s", fname); -- cgit v1.2.3