[glibmm] Gio::Resource: Add get_file_exists_nothrow(). Rename some methods
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::Resource: Add get_file_exists_nothrow(). Rename some methods
- Date: Thu, 20 Nov 2014 12:10:44 +0000 (UTC)
commit 26d5c9611cd1bf8d89fc6fd2984dfd0498fcaf71
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Nov 20 13:03:06 2014 +0100
Gio::Resource: Add get_file_exists_nothrow(). Rename some methods
* gio/src/resource.[hg|ccg]: Add get_file_exists_nothrow() and
get_file_exists_global_nothrow(). Rename the get_info() and get_info_global()
methods that only check if a file exists. Use std::string for path names.
Bug #739206.
gio/src/resource.ccg | 20 +++++++++++---
gio/src/resource.hg | 74 +++++++++++++++++++++++++++++++++----------------
2 files changed, 66 insertions(+), 28 deletions(-)
---
diff --git a/gio/src/resource.ccg b/gio/src/resource.ccg
index cd5eb8c..4a4b716 100644
--- a/gio/src/resource.ccg
+++ b/gio/src/resource.ccg
@@ -20,7 +20,7 @@
namespace Gio
{
// Hand-coded because we want ResourceFlags& instead of guint32&.
-void Resource::get_info(const Glib::ustring& path, gsize& size,
+void Resource::get_info(const std::string& path, gsize& size,
ResourceFlags& flags, ResourceLookupFlags lookup_flags) const
{
guint32 file_flags = 0;
@@ -34,7 +34,7 @@ void Resource::get_info(const Glib::ustring& path, gsize& size,
flags = static_cast<ResourceFlags>(file_flags);
}
-void Resource::get_info(const Glib::ustring& path, ResourceLookupFlags lookup_flags) const
+void Resource::get_file_exists(const std::string& path, ResourceLookupFlags lookup_flags) const
{
GError* gerror = 0;
g_resource_get_info(const_cast<GResource*>(gobj()), path.c_str(),
@@ -43,9 +43,15 @@ void Resource::get_info(const Glib::ustring& path, ResourceLookupFlags lookup_fl
::Glib::Error::throw_exception(gerror);
}
+bool Resource::get_file_exists_nothrow(const std::string& path, ResourceLookupFlags lookup_flags) const
+{
+ return g_resource_get_info(const_cast<GResource*>(gobj()), path.c_str(),
+ (GResourceLookupFlags)lookup_flags, 0, 0, 0);
+}
+
// Hand-coded because we want ResourceFlags& instead of guint32&.
//static
-void Resource::get_info_global(const Glib::ustring& path, gsize& size,
+void Resource::get_info_global(const std::string& path, gsize& size,
ResourceFlags& flags, ResourceLookupFlags lookup_flags)
{
guint32 file_flags = 0;
@@ -60,7 +66,7 @@ void Resource::get_info_global(const Glib::ustring& path, gsize& size,
}
//static
-void Resource::get_info_global(const Glib::ustring& path, ResourceLookupFlags lookup_flags)
+void Resource::get_file_exists_global(const std::string& path, ResourceLookupFlags lookup_flags)
{
GError* gerror = 0;
g_resources_get_info(path.c_str(),
@@ -69,4 +75,10 @@ void Resource::get_info_global(const Glib::ustring& path, ResourceLookupFlags lo
::Glib::Error::throw_exception(gerror);
}
+//static
+bool Resource::get_file_exists_global_nothrow(const std::string& path, ResourceLookupFlags lookup_flags)
+{
+ return g_resources_get_info(path.c_str(), (GResourceLookupFlags)lookup_flags, 0, 0, 0);
+}
+
} // namespace Gio
diff --git a/gio/src/resource.hg b/gio/src/resource.hg
index e01d9cf..a74c469 100644
--- a/gio/src/resource.hg
+++ b/gio/src/resource.hg
@@ -18,7 +18,6 @@
#include <glibmm/error.h>
#include <glibmm/refptr.h>
#include <glibmm/bytes.h>
-#include <glibmm/ustring.h>
#include <giomm/inputstream.h>
#include <vector>
#include <string>
@@ -137,75 +136,102 @@ class Resource
public:
_WRAP_METHOD(static Glib::RefPtr<Resource> create_from_data(const Glib::RefPtr<const Glib::Bytes>& data),
g_resource_new_from_data, errthrow)
_WRAP_METHOD(static Glib::RefPtr<Resource> create_from_file(const std::string& filename), g_resource_load,
errthrow)
- _WRAP_METHOD(Glib::RefPtr<InputStream> open_stream(const Glib::ustring& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_open_stream, errthrow)
- _WRAP_METHOD(Glib::RefPtr<const Glib::Bytes> lookup_data(const Glib::ustring& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_lookup_data, errthrow)
+ _WRAP_METHOD(Glib::RefPtr<InputStream> open_stream(const std::string& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_open_stream, errthrow)
+ _WRAP_METHOD(Glib::RefPtr<const Glib::Bytes> lookup_data(const std::string& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_lookup_data, errthrow)
-#m4
_CONVERSION(`char**',`std::vector<Glib::ustring>',`Glib::ArrayHandler<Glib::ustring>::array_to_vector($3,
Glib::OWNERSHIP_DEEP)')
- _WRAP_METHOD(std::vector<Glib::ustring> enumerate_children(const Glib::ustring& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_enumerate_children, errthrow)
+#m4 _CONVERSION(`char**',`std::vector<std::string>',`Glib::ArrayHandler<std::string>::array_to_vector($3,
Glib::OWNERSHIP_DEEP)')
+ _WRAP_METHOD(std::vector<std::string> enumerate_children(const std::string& path, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const, g_resource_enumerate_children, errthrow)
/** Looks for a file at the specified @a path in the resource and
* if found returns information about it.
- *
+ *
* @a lookup_flags controls the behaviour of the lookup.
- *
+ *
* @newin{2,44}
- *
+ *
* @param path A pathname inside the resource.
* @param[out] size A location to place the length of the contents of the file.
* @param[out] flags A location to place the flags about the file.
* @param lookup_flags A ResourceLookupFlags.
* @throw Gio::ResourceError if the file was not found.
*/
- void get_info(const Glib::ustring& path, gsize& size, ResourceFlags& flags, ResourceLookupFlags
lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE) const;
+ void get_info(const std::string& path, gsize& size, ResourceFlags& flags, ResourceLookupFlags lookup_flags
= RESOURCE_LOOKUP_FLAGS_NONE) const;
_IGNORE(g_resource_get_info)
/** Looks for a file at the specified @a path in the resource.
- *
+ *
* @a lookup_flags controls the behaviour of the lookup.
- *
+ *
* @newin{2,44}
- *
+ *
* @param path A pathname inside the resource.
* @param lookup_flags A ResourceLookupFlags.
* @throw Gio::ResourceError if the file was not found.
*/
- void get_info(const Glib::ustring& path, ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE)
const;
+ void get_file_exists(const std::string& path, ResourceLookupFlags lookup_flags =
RESOURCE_LOOKUP_FLAGS_NONE) const;
+
+ /** Looks for a file at the specified @a path in the resource.
+ *
+ * @a lookup_flags controls the behaviour of the lookup.
+ * This method returns a <tt>bool</tt> instead of throwing in exception in case of errors.
+ *
+ * @newin{2,44}
+ *
+ * @param path A pathname inside the resource.
+ * @param lookup_flags A ResourceLookupFlags.
+ * @return <tt>true</tt> if the file was found, <tt>false</tt> if there were errors.
+ */
+ bool get_file_exists_nothrow(const std::string& path, ResourceLookupFlags lookup_flags =
RESOURCE_LOOKUP_FLAGS_NONE) const;
// 'register' is a keyword. Can't be the name of a method.
_WRAP_METHOD(void register_global(), g_resources_register)
_WRAP_METHOD(void unregister_global(), g_resources_unregister)
- _WRAP_METHOD(static Glib::RefPtr<InputStream> open_stream_global(const Glib::ustring& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_open_stream, errthrow)
- _WRAP_METHOD(static Glib::RefPtr<const Glib::Bytes> lookup_data_global(const Glib::ustring& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_lookup_data, errthrow)
- _WRAP_METHOD(static std::vector<Glib::ustring> enumerate_children_global(const Glib::ustring& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_enumerate_children, errthrow)
+ _WRAP_METHOD(static Glib::RefPtr<InputStream> open_stream_global(const std::string& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_open_stream, errthrow)
+ _WRAP_METHOD(static Glib::RefPtr<const Glib::Bytes> lookup_data_global(const std::string& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_lookup_data, errthrow)
+ _WRAP_METHOD(static std::vector<std::string> enumerate_children_global(const std::string& path,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE), g_resources_enumerate_children, errthrow)
/** Looks for a file at the specified @a path in the set of
* globally registered resources and if found returns information about it.
- *
+ *
* @a lookup_flags controls the behaviour of the lookup.
- *
+ *
* @newin{2,44}
- *
+ *
* @param path A pathname inside the resource.
* @param[out] size A location to place the length of the contents of the file.
* @param[out] flags A location to place the flags about the file.
* @param lookup_flags A ResourceLookupFlags.
* @throw Gio::ResourceError if the file was not found.
*/
- static void get_info_global(const Glib::ustring& path, gsize& size, ResourceFlags& flags,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE);
+ static void get_info_global(const std::string& path, gsize& size, ResourceFlags& flags,
ResourceLookupFlags lookup_flags = RESOURCE_LOOKUP_FLAGS_NONE);
_IGNORE(g_resources_get_info)
/** Looks for a file at the specified @a path in the set of
* globally registered resources.
- *
+ *
* @a lookup_flags controls the behaviour of the lookup.
- *
+ *
* @newin{2,44}
- *
+ *
* @param path A pathname inside the resource.
* @param lookup_flags A ResourceLookupFlags.
* @throw Gio::ResourceError if the file was not found.
*/
- static void get_info_global(const Glib::ustring& path, ResourceLookupFlags lookup_flags =
RESOURCE_LOOKUP_FLAGS_NONE);
+ static void get_file_exists_global(const std::string& path, ResourceLookupFlags lookup_flags =
RESOURCE_LOOKUP_FLAGS_NONE);
+
+ /** Looks for a file at the specified @a path in the set of
+ * globally registered resources.
+ *
+ * @a lookup_flags controls the behaviour of the lookup.
+ * This method returns a <tt>bool</tt> instead of throwing in exception in case of errors.
+ *
+ * @newin{2,44}
+ *
+ * @param path A pathname inside the resource.
+ * @param lookup_flags A ResourceLookupFlags.
+ * @return <tt>true</tt> if the file was found, <tt>false</tt> if there were errors.
+ */
+ static bool get_file_exists_global_nothrow(const std::string& path, ResourceLookupFlags lookup_flags =
RESOURCE_LOOKUP_FLAGS_NONE);
_IGNORE(g_static_resource_init, g_static_resource_fini, g_static_resource_get_resource)dnl//Used only by
the glib-compile-resources command
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]