diff options
Diffstat (limited to 'project2/files/fileRows.cpp')
-rw-r--r-- | project2/files/fileRows.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/project2/files/fileRows.cpp b/project2/files/fileRows.cpp index af11f55..4afbbb3 100644 --- a/project2/files/fileRows.cpp +++ b/project2/files/fileRows.cpp @@ -1,5 +1,6 @@ #include "fileRows.h" #include "logger.h" +#include "scopeObject.h" #include "rowProcessor.h" #include "xmlObjectLoader.h" #include "exceptions.h" @@ -26,22 +27,23 @@ FileRows::setFilter(const Glib::ustring &) void FileRows::execute(const Glib::ustring &, const RowProcessor * rp) const { - FileStarChannel c(doOpen()); - c.set_encoding(encoding); + Glib::RefPtr<Glib::IOChannel> c(doOpen()); + ScopeObject so(boost::bind(&FileRows::doClose, this, c)); + c->set_encoding(encoding); gunichar ch; ParseState ps(this, rp); - while (c.read(ch) == Glib::IO_STATUS_NORMAL) { + while (c->read(ch) == Glib::IO_STATUS_NORMAL) { this->pushChar(ch, ps); } } -FileStarChannel +Glib::RefPtr<Glib::IOChannel> FileRows::doOpen() const { - FILE * f = fopen(path(), "r"); - if (!f) { - throw FileNotReadable(path()); - } - return FileStarChannel(f, true, fclose); + return Glib::IOChannel::create_from_file(path(), "r"); } +void +FileRows::doClose(Glib::RefPtr<Glib::IOChannel> c) const { + c->close(); +} |