diff options
author | Murray Cumming <murrayc@murrayc.com> | 2008-01-23 09:21:24 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2008-01-23 09:21:24 +0000 |
commit | 05f93d80001fb857bd1844854481ef2a5f6959ed (patch) | |
tree | 507f84cc1ed7326847fa283892d97502cf71d1a0 /gio | |
parent | 9ba22fdf516d978654d2f7796185b1f792d43bf2 (diff) | |
download | glibmm-05f93d80001fb857bd1844854481ef2a5f6959ed.tar.gz |
Added a read() method overload with no cancellable parameter. Try loading
2008-01-23 Murray Cumming <murrayc@murrayc.com>
* gio/src/file.ccg:
* gio/src/file.hg: Added a read() method overload with no
cancellable parameter.
* tests/giomm_simple/main.cc: Try loading the contents of a file.
Seems to work, though there is an unknown GError domain when the file
does not exist.
svn path=/trunk/; revision=536
Diffstat (limited to 'gio')
-rw-r--r-- | gio/src/file.ccg | 21 | ||||
-rw-r--r-- | gio/src/file.hg | 19 |
2 files changed, 37 insertions, 3 deletions
diff --git a/gio/src/file.ccg b/gio/src/file.ccg index fea3f4ff..de79b19b 100644 --- a/gio/src/file.ccg +++ b/gio/src/file.ccg @@ -1146,4 +1146,25 @@ Glib::RefPtr<FileMonitor> File::monitor_file(FileMonitorFlags flags, std::auto_ return retvalue; } +#ifdef GLIBMM_EXCEPTIONS_ENABLED +Glib::RefPtr<FileInputStream> File::read() +#else +Glib::RefPtr<FileInputStream> File::read(std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED +{ + GError* gerror = 0; + Glib::RefPtr<FileInputStream> retvalue = Glib::wrap(g_file_read(gobj(), NULL, &(gerror))); +#ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) + ::Glib::Error::throw_exception(gerror); +#else + if(gerror) + error = ::Glib::Error::throw_exception(gerror); +#endif //GLIBMM_EXCEPTIONS_ENABLED + + if(retvalue) + retvalue->reference(); //The function does not do a ref for us. + return retvalue; +} + } // namespace Gio diff --git a/gio/src/file.hg b/gio/src/file.hg index cbf2cd9c..693aff58 100644 --- a/gio/src/file.hg +++ b/gio/src/file.hg @@ -160,12 +160,25 @@ public: g_file_has_uri_scheme) _WRAP_METHOD(std::string get_uri_scheme() const, g_file_get_uri_scheme) + + //TODO: We don't have both const and unconst versions because a FileInputStream can't really change the File. _WRAP_METHOD(Glib::RefPtr<FileInputStream> read(const Glib::RefPtr<Cancellable>& cancellable), g_file_read, refreturn, errthrow) - _WRAP_METHOD(Glib::RefPtr<const FileInputStream> read(const Glib::RefPtr<Cancellable>& cancellable) const, - g_file_read, - refreturn, constversion, errthrow) + + /** Opens a file for reading. The result is a FileInputStream that + * can be used to read the contents of the file. + * + * If the file does not exist, the IO_ERROR_NOT_FOUND error will be returned. + * If the file is a directory, theIO_ERROR_IS_DIRECTORY error will be returned. + * Other errors are possible too, and depend on what kind of filesystem the file is on. + * @return FileInputStream or an empty RefPtr on error. + */ + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::RefPtr<FileInputStream> read(); + #else + Glib::RefPtr<FileInputStream> read(std::auto_ptr<Glib::Error>& error); + #endif //GLIBMM_EXCEPTIONS_ENABLED /** Asynchronously opens the file for reading. * For more details, see read() which is the synchronous version of this call. |