[glibmm] Gio::Resolver: Use std::vector instead of Glib::ListHandle<>.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::Resolver: Use std::vector instead of Glib::ListHandle<>.
- Date: Mon, 20 Mar 2017 08:52:37 +0000 (UTC)
commit 79b20cd2d2c83ac52d8a2c385b2674fa3c514d99
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Mar 17 12:43:13 2017 +0100
Gio::Resolver: Use std::vector instead of Glib::ListHandle<>.
Using Glib::ListHandler<>::list_to_array() and
Glib::ListHandler<>::list_to_vector() instead, and only in the
implementation instead of in the API.
examples/network/resolver.cc | 8 +-
gio/src/resolver.ccg | 16 ++
gio/src/resolver.hg | 12 +-
gio/src/srvtarget.hg | 23 ---
glib/glibmm/listhandle.h | 413 ------------------------------------------
glib/glibmm/slisthandle.h | 411 -----------------------------------------
6 files changed, 25 insertions(+), 858 deletions(-)
---
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index 97dc4d7..106f60a 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -89,7 +89,7 @@ print_resolved_name(const Glib::ustring& phys, const Glib::ustring& name)
static void
print_resolved_addresses(
- const Glib::ustring& name, const std::list<Glib::RefPtr<Gio::InetAddress>>& addresses)
+ const Glib::ustring& name, const std::vector<Glib::RefPtr<Gio::InetAddress>>& addresses)
{
std::lock_guard<std::mutex> lock_guard(response_mutex);
std::cout << Glib::ustring::compose("Name: %1\n", name);
@@ -103,7 +103,7 @@ print_resolved_addresses(
}
static void
-print_resolved_service(const Glib::ustring& service, const std::list<Gio::SrvTarget>& targets)
+print_resolved_service(const Glib::ustring& service, const std::vector<Gio::SrvTarget>& targets)
{
std::lock_guard<std::mutex> lock_guard(response_mutex);
std::cout << Glib::ustring::compose("Service: %1\n", service);
@@ -174,11 +174,9 @@ lookup_one_sync(const Glib::ustring& arg)
}
else
{
- std::list<Glib::RefPtr<Gio::InetAddress>> addresses;
-
try
{
- addresses = resolver->lookup_by_name(arg, cancellable);
+ const auto addresses = resolver->lookup_by_name(arg, cancellable);
print_resolved_addresses(arg, addresses);
}
catch (const Gio::ResolverError& err)
diff --git a/gio/src/resolver.ccg b/gio/src/resolver.ccg
index 093f698..df3e0df 100644
--- a/gio/src/resolver.ccg
+++ b/gio/src/resolver.ccg
@@ -19,6 +19,22 @@
#include <glibmm/error.h>
#include "slot_async.h"
+namespace {
+
+struct SrvTargetListTraits
+{
+ using CppType = Gio::SrvTarget;
+ using CType = const GSrvTarget*;
+ using CTypeNonConst = GSrvTarget*;
+
+ static CType to_c_type(const CppType& item) { return item.gobj(); }
+ static CType to_c_type(CType ptr) { return ptr; }
+ static CppType to_cpp_type(CType item) { return CppType(const_cast<CTypeNonConst>(item), true /* take_copy
*/); }
+ static void release_c_type(CType item) { g_srv_target_free(const_cast<CTypeNonConst>(item)); }
+};
+
+} // anonymous namespace
+
namespace Gio
{
diff --git a/gio/src/resolver.hg b/gio/src/resolver.hg
index 67258e5..3b16224 100644
--- a/gio/src/resolver.hg
+++ b/gio/src/resolver.hg
@@ -67,8 +67,8 @@ public:
// g_resolver_free_addresses is just a C convenience function
_IGNORE(g_resolver_free_addresses)
-#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<InetAddress> >',`$2($3, Glib::OWNERSHIP_DEEP)')
- _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<InetAddress> > lookup_by_name(const Glib::ustring& hostname,
const Glib::RefPtr<Cancellable>& cancellable{?}), g_resolver_lookup_by_name, errthrow)
+#m4
_CONVERSION(`GList*',`std::vector<Glib::RefPtr<InetAddress>>',`Glib::ListHandler<Glib::RefPtr<InetAddress>>::list_to_vector($3,
Glib::OWNERSHIP_DEEP)')
+ _WRAP_METHOD(std::vector<Glib::RefPtr<InetAddress>> lookup_by_name(const Glib::ustring& hostname, const
Glib::RefPtr<Cancellable>& cancellable{?}), g_resolver_lookup_by_name, errthrow)
/** Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually
calls @a slot, which must call
* lookup_by_name_finish() to get the result. See lookup_by_name() for more details.
@@ -88,7 +88,7 @@ public:
void lookup_by_name_async(const Glib::ustring& hostname, const SlotAsyncReady& slot);
_IGNORE(g_resolver_lookup_by_name_async)
- _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<InetAddress> > lookup_by_name_finish(const
Glib::RefPtr<AsyncResult>& result), g_resolver_lookup_by_name_finish, errthrow)
+ _WRAP_METHOD(std::vector<Glib::RefPtr<InetAddress>> lookup_by_name_finish(const Glib::RefPtr<AsyncResult>&
result), g_resolver_lookup_by_name_finish, errthrow)
_WRAP_METHOD(Glib::ustring lookup_by_address(const Glib::RefPtr<InetAddress>& address, const
Glib::RefPtr<Cancellable>& cancellable{?}), g_resolver_lookup_by_address, errthrow)
@@ -112,8 +112,8 @@ public:
_WRAP_METHOD(Glib::ustring lookup_by_address_finish(const Glib::RefPtr<AsyncResult>& result),
g_resolver_lookup_by_address_finish, errthrow)
-#m4 _CONVERSION(`GList*',`ListHandle_SrvTarget',`$2($3, Glib::OWNERSHIP_DEEP)')
- _WRAP_METHOD(ListHandle_SrvTarget lookup_service(const Glib::ustring& service, const Glib::ustring&
protocol, const Glib::ustring& domain, const Glib::RefPtr<Cancellable>& cancellable{?}),
g_resolver_lookup_service, errthrow)
+#m4 _CONVERSION(`GList*',`std::vector<SrvTarget>',`Glib::ListHandler<SrvTarget,
SrvTargetListTraits>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
+ _WRAP_METHOD(std::vector<SrvTarget> lookup_service(const Glib::ustring& service, const Glib::ustring&
protocol, const Glib::ustring& domain, const Glib::RefPtr<Cancellable>& cancellable{?}),
g_resolver_lookup_service, errthrow)
/** Begins asynchronously performing a DNS SRV lookup for the given service and protocol in the given
domain, and eventually calls callback,
* which must call lookup_service_finish() to get the final result. See glookup_service() for more details.
@@ -137,7 +137,7 @@ public:
void lookup_service_async(const Glib::ustring& service, const Glib::ustring& protocol, const
Glib::ustring& domain, const SlotAsyncReady& slot);
_IGNORE(g_resolver_lookup_service_async)
- _WRAP_METHOD(ListHandle_SrvTarget lookup_service_finish(const Glib::RefPtr<AsyncResult>& result),
g_resolver_lookup_service_finish, errthrow)
+ _WRAP_METHOD(std::vector<SrvTarget> lookup_service_finish(const Glib::RefPtr<AsyncResult>& result),
g_resolver_lookup_service_finish, errthrow)
#m4
_CONVERSION(`GList*',`std::vector<Glib::VariantContainerBase>',`Glib::ListHandler<Glib::VariantContainerBase>::list_to_vector($3,
Glib::OWNERSHIP_DEEP)')
diff --git a/gio/src/srvtarget.hg b/gio/src/srvtarget.hg
index edaf02f..f5d7960 100644
--- a/gio/src/srvtarget.hg
+++ b/gio/src/srvtarget.hg
@@ -15,12 +15,6 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <glibmm/listhandle.h>
-
-// unfortunately we need to include the C header for the type traits
-// implementation
-#include <gio/gio.h>
-
_DEFS(giomm,gio)
namespace Gio
@@ -59,23 +53,6 @@ public:
};
-#ifndef DOXYGEN_SHOULD_SKIP_THIS
-
-struct SrvTargetListTraits
-{
- using CppType = Gio::SrvTarget;
- using CType = const GSrvTarget*;
- using CTypeNonConst = GSrvTarget*;
-
- static CType to_c_type(const CppType& item) { return item.gobj(); }
- static CType to_c_type(CType ptr) { return ptr; }
- static CppType to_cpp_type(CType item) { return CppType(const_cast<CTypeNonConst>(item), true /* take_copy
*/); }
- static void release_c_type(CType item) { g_srv_target_free(const_cast<CTypeNonConst>(item)); }
-};
-
-#endif // DOXYGEN_SHOULD_SKIP_THIS
-
-using ListHandle_SrvTarget = Glib::ListHandle<Gio::SrvTarget, SrvTargetListTraits>;
} // namespace Gio
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]