[pangomm] Context::itemize(): Use std::vector instead of ListHandle<>.



commit 0500cb5908ccb350e14a8b6b31443cf63457e708
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Mar 17 12:55:24 2017 +0100

    Context::itemize(): Use std::vector instead of ListHandle<>.
    
    Using Glib::ListHandler<>::list_to_vector() and
    Glib::ListHandler<>::vector_to_list() instead, and only in the
    implementation instead of in the API.

 pango/src/context.ccg |   22 ++++++++++++++++++----
 pango/src/context.hg  |    4 ++--
 pango/src/item.hg     |   14 --------------
 3 files changed, 20 insertions(+), 20 deletions(-)
---
diff --git a/pango/src/context.ccg b/pango/src/context.ccg
index 1f0922b..57f7ddd 100644
--- a/pango/src/context.ccg
+++ b/pango/src/context.ccg
@@ -43,19 +43,33 @@ Pango::FontMetrics Context::get_metrics(const FontDescription& desc) const
   return FontMetrics(pango_context_get_metrics(const_cast<PangoContext*>(gobj()), desc.gobj(), 0));
 }
 
-ListHandle_Item Context::itemize(const Glib::ustring& text, const AttrList& attrs) const
+struct ItemTraits
 {
-  return ListHandle_Item(
+  typedef Pango::Item       CppType;
+  typedef const PangoItem*  CType;
+  typedef PangoItem*        CTypeNonConst;
+
+  static CType   to_c_type      (const CppType& obj) { return obj.gobj(); }
+  static CType   to_c_type      (CType ptr) { return ptr; }
+  static CppType to_cpp_type    (CType ptr) { return CppType(const_cast<CTypeNonConst>(ptr), true); }
+  static void    release_c_type (CType ptr) { pango_item_free(const_cast<CTypeNonConst>(ptr)); }
+};
+
+using ListHandler_Item = Glib::ListHandler<Item, ItemTraits>;
+
+std::vector<Item> Context::itemize(const Glib::ustring& text, const AttrList& attrs) const
+{
+  return ListHandler_Item::list_to_vector(
       pango_itemize(const_cast<PangoContext*>(gobj()),
                     text.c_str(), 0, text.bytes(),
                     const_cast<PangoAttrList*>(attrs.gobj()), 0),
       Glib::OWNERSHIP_DEEP);
 }
 
-ListHandle_Item Context::itemize(const Glib::ustring& text, int start_index, int length,
+std::vector<Item> Context::itemize(const Glib::ustring& text, int start_index, int length,
                                  const AttrList& attrs, AttrIter& cached_iter) const
 {
-  return ListHandle_Item(
+  return ListHandler_Item::list_to_vector(
       pango_itemize(const_cast<PangoContext*>(gobj()),
                     text.c_str(), start_index, length,
                     const_cast<PangoAttrList*>(attrs.gobj()), cached_iter.gobj()),
diff --git a/pango/src/context.hg b/pango/src/context.hg
index 9027cbb..d64eb48 100644
--- a/pango/src/context.hg
+++ b/pango/src/context.hg
@@ -133,7 +133,7 @@ public:
    * @param attrs The set of attributes that apply.
    * @return A list of Pango::Item objects.
    */
-  ListHandle_Item itemize(const Glib::ustring& text, const AttrList& attrs) const;
+  std::vector<Item> itemize(const Glib::ustring& text, const AttrList& attrs) const;
 
   /** Breaks a piece of text into segments with consistent directional level and shaping engine.
    * Each byte of @a text will be contained in exactly one of the items in the returned list. 
@@ -152,7 +152,7 @@ public:
    * @param cached_iter Cached attribute iterator.
    * @return A list of Pango::Item structures.
    */
-  ListHandle_Item itemize(const Glib::ustring& text, int start_index, int length,
+  std::vector<Item> itemize(const Glib::ustring& text, int start_index, int length,
                           const AttrList& attrs, AttrIter& cached_iter) const;
 
   /** Updates a Pango Context previously created for use with Cairo to
diff --git a/pango/src/item.hg b/pango/src/item.hg
index 4331286..2eddbe6 100644
--- a/pango/src/item.hg
+++ b/pango/src/item.hg
@@ -150,20 +150,6 @@ protected:
   PangoItem* gobject_;
 };
 
-struct ItemTraits
-{
-  typedef Pango::Item       CppType;
-  typedef const PangoItem*  CType;
-  typedef PangoItem*        CTypeNonConst;
-
-  static CType   to_c_type      (const CppType& obj) { return obj.gobj(); }
-  static CType   to_c_type      (CType ptr) { return ptr; }
-  static CppType to_cpp_type    (CType ptr) { return CppType(const_cast<CTypeNonConst>(ptr), true); }
-  static void    release_c_type (CType ptr) { pango_item_free(const_cast<CTypeNonConst>(ptr)); }
-};
-
-typedef Glib::ListHandle<Item, ItemTraits> ListHandle_Item;
-
 } // namespace Pango
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]