[glibmm/vector] Remove commented code in vectorhandler.h.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/vector] Remove commented code in vectorhandler.h.
- Date: Tue, 18 Jan 2011 22:42:47 +0000 (UTC)
commit 861cbdacb3947bcde4c4c9a718637e0d7159dc9d
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Tue Jan 18 23:40:51 2011 +0100
Remove commented code in vectorhandler.h.
Also reserve memory for vector when creating it from GList or SList.
glib/glibmm/vectorutils.h | 296 ++-------------------------------------------
1 files changed, 8 insertions(+), 288 deletions(-)
---
diff --git a/glib/glibmm/vectorutils.h b/glib/glibmm/vectorutils.h
index e1a81d8..cafeb9d 100644
--- a/glib/glibmm/vectorutils.h
+++ b/glib/glibmm/vectorutils.h
@@ -61,6 +61,10 @@ namespace Container_Helpers
#ifndef DOXYGEN_SHOULD_SKIP_THIS
+// TODO: remove `2' from the function names after getting rid of *Handle
+// classes - krnowak
+// TODO: docs!
+
/* Count the number of elements in a 0-terminated sequence.
*/
template <class T> inline
@@ -132,74 +136,6 @@ GSList* create_gslist2(Bi pbegin, Bi pend)
return head;
}
-
-/* Convert from any container that supports forward
- * iterators and has a size() method.
- */
- /*
-template <class Tr, class Cont>
-struct ArraySourceTraits
-{
- typedef typename Tr::CType CType;
-
- static size_t get_size(const Cont& cont)
- { return cont.size(); }
-
- static const CType* get_data(const Cont& cont, size_t size)
- { return Glib::Container_Helpers::create_array(cont.begin(), size, Tr()); }
-
- static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_SHALLOW;
-};
-*/
-
-/* Convert from a 0-terminated array. The Cont argument must be a pointer
- * to the first element. Note that only arrays of the C type are supported.
- */
- /*
-template <class Tr, class Cont>
-struct ArraySourceTraits<Tr,Cont*>
-{
- typedef typename Tr::CType CType;
-
- static size_t get_size(const CType* array)
- { return (array) ? Glib::Container_Helpers::compute_array_size(array) : 0; }
-
- static const CType* get_data(const CType* array, size_t)
- { return array; }
-
- static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_NONE;
-};
-
-template <class Tr, class Cont>
-struct ArraySourceTraits<Tr,const Cont*> : ArraySourceTraits<Tr,Cont*>
-{};
-*/
-
-/* Convert from a 0-terminated array. The Cont argument must be a pointer
- * to the first element. Note that only arrays of the C type are supported.
- * For consistency, the array must be 0-terminated, even though the array
- * size is known at compile time.
- */
- /*
-template <class Tr, class Cont, size_t N>
-struct ArraySourceTraits<Tr,Cont[N]>
-{
- typedef typename Tr::CType CType;
-
- static size_t get_size(const CType*)
- { return (N - 1); }
-
- static const CType* get_data(const CType* array, size_t)
- { return array; }
-
- static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_NONE;
-};
-
-template <class Tr, class Cont, size_t N>
-struct ArraySourceTraits<Tr,const Cont[N]> : ArraySourceTraits<Tr,Cont[N]>
-{};
-*/
-
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
@@ -383,6 +319,7 @@ public:
typedef typename Glib::Container_Helpers::ListIterator<Tr> ListIteratorType;
typedef typename Glib::Container_Helpers::SListIterator<Tr> SListIteratorType;
+// maybe think about using C++0x move constructors?
static VectorType array_to_vector (const CType* array, size_t array_size, Glib::OwnershipType ownership);
static VectorType array_to_vector (const CType* array, Glib::OwnershipType ownership);
static VectorType list_to_vector (GList* glist, Glib::OwnershipType ownership);
@@ -392,72 +329,6 @@ public:
static GSListKeeperType vector_to_slist (const VectorType& vector, Glib::OwnershipType ownership);
};
-/** If a method takes this as an argument, or has this as a return type, then you can use a standard
- * container such as std::list or std::vector.
- * @ingroup ContHandles
- */
-/*
-template < class T, class Tr = Glib::Container_Helpers::TypeTraits<T> >
-class ArrayHandle
-{
-public:
- typedef typename Tr::CppType CppType;
- typedef typename Tr::CType CType;
-
- typedef CppType value_type;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
-
- typedef Glib::Container_Helpers::ArrayIterator<Tr> const_iterator;
- typedef Glib::Container_Helpers::ArrayIterator<Tr> iterator;
-
- template <class Cont> inline
- ArrayHandle(const Cont& container);
-
- // Take over ownership of an array created by GTK+ functions.
- inline ArrayHandle(const CType* array, size_t array_size, Glib::OwnershipType ownership);
- inline ArrayHandle(const CType* array, Glib::OwnershipType ownership);
-
- // Copying clears the ownership flag of the source handle.
- inline ArrayHandle(const ArrayHandle<T,Tr>& other);
-
- ~ArrayHandle();
-
- inline const_iterator begin() const;
- inline const_iterator end() const;
-
- template <class U> inline operator std::vector<U>() const;
- template <class U> inline operator std::deque<U>() const;
- template <class U> inline operator std::list<U>() const;
-
- template <class Cont> inline
- void assign_to(Cont& container) const;
-
- template <class Out> inline
- void copy(Out pdest) const;
-
- inline const CType* data() const;
- inline size_t size() const;
- inline bool empty() const;
-
-private:
- size_t size_;
- const CType* parray_;
- mutable Glib::OwnershipType ownership_;
-
- // No copy assignment.
- ArrayHandle<T, Tr>& operator=(const ArrayHandle<T,Tr>&);
-};
-*/
-
-/** If a method takes this as an argument, or has this as a return type, then you can use a standard
- * container such as std::list<Glib::ustring> or std::vector<Glib::ustring>.
- * @ingroup ContHandles
- */
- /*
-typedef ArrayHandle<Glib::ustring> StringArrayHandle;
-*/
-
/***************************************************************************/
/* Inline implementation */
/***************************************************************************/
@@ -787,158 +658,7 @@ inline GSListKeeper<Tr>::operator GSList* () const
} // namespace Container_Helpers
-
-/**** Glib::ArrayHandle<> **************************************************/
-/*
-template <class T, class Tr>
- template <class Cont>
-inline
-ArrayHandle<T,Tr>::ArrayHandle(const Cont& container)
-:
- size_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::get_size(container)),
- parray_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::get_data(container, size_)),
- ownership_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::initial_ownership)
-{}
-
-template <class T, class Tr> inline
-ArrayHandle<T,Tr>::ArrayHandle(const typename ArrayHandle<T,Tr>::CType* array, size_t array_size,
- Glib::OwnershipType ownership)
-:
- size_ (array_size),
- parray_ (array),
- ownership_ (ownership)
-{}
-
-template <class T, class Tr> inline
-ArrayHandle<T,Tr>::ArrayHandle(const typename ArrayHandle<T,Tr>::CType* array,
- Glib::OwnershipType ownership)
-:
- size_ ((array) ? Glib::Container_Helpers::compute_array_size(array) : 0),
- parray_ (array),
- ownership_ (ownership)
-{}
-
-template <class T, class Tr> inline
-ArrayHandle<T,Tr>::ArrayHandle(const ArrayHandle<T,Tr>& other)
-:
- size_ (other.size_),
- parray_ (other.parray_),
- ownership_ (other.ownership_)
-{
- other.ownership_ = Glib::OWNERSHIP_NONE;
-}
-
-template <class T, class Tr>
-ArrayHandle<T,Tr>::~ArrayHandle()
-{
- if(ownership_ != Glib::OWNERSHIP_NONE)
- {
- if(ownership_ != Glib::OWNERSHIP_SHALLOW)
- {
- // Deep ownership: release each container element.
- const CType *const pend = parray_ + size_;
- for(const CType* p = parray_; p != pend; ++p)
- Tr::release_c_type(*p);
- }
- g_free(const_cast<CType*>(parray_));
- }
-}
-
-template <class T, class Tr> inline
-typename ArrayHandle<T,Tr>::const_iterator ArrayHandle<T,Tr>::begin() const
-{
- return Glib::Container_Helpers::ArrayIterator<Tr>(parray_);
-}
-
-template <class T, class Tr> inline
-typename ArrayHandle<T,Tr>::const_iterator ArrayHandle<T,Tr>::end() const
-{
- return Glib::Container_Helpers::ArrayIterator<Tr>(parray_ + size_);
-}
-
-template <class T, class Tr>
- template <class U>
-inline
-ArrayHandle<T,Tr>::operator std::vector<U>() const
-{
-#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
- return std::vector<U>(this->begin(), this->end());
-#else
- std::vector<U> temp;
- temp.reserve(this->size());
- Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
- return temp;
-#endif
-}
-
-template <class T, class Tr>
- template <class U>
-inline
-ArrayHandle<T,Tr>::operator std::deque<U>() const
-{
-#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
- return std::deque<U>(this->begin(), this->end());
-#else
- std::deque<U> temp;
- Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
- return temp;
-#endif
-}
-
-template <class T, class Tr>
- template <class U>
-inline
-ArrayHandle<T,Tr>::operator std::list<U>() const
-{
-#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
- return std::list<U>(this->begin(), this->end());
-#else
- std::list<U> temp;
- Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
- return temp;
-#endif
-}
-
-template <class T, class Tr>
- template <class Cont>
-inline
-void ArrayHandle<T,Tr>::assign_to(Cont& container) const
-{
-#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
- container.assign(this->begin(), this->end());
-#else
- Cont temp;
- Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
- container.swap(temp);
-#endif
-}
-
-template <class T, class Tr>
- template <class Out>
-inline
-void ArrayHandle<T,Tr>::copy(Out pdest) const
-{
- std::copy(this->begin(), this->end(), pdest);
-}
-
-template <class T, class Tr> inline
-const typename ArrayHandle<T,Tr>::CType* ArrayHandle<T,Tr>::data() const
-{
- return parray_;
-}
-
-template <class T, class Tr> inline
-size_t ArrayHandle<T,Tr>::size() const
-{
- return size_;
-}
-
-template <class T, class Tr> inline
-bool ArrayHandle<T,Tr>::empty() const
-{
- return (size_ == 0);
-}
-*/
+/**** Glib::VectorHandler<> ************************/
template <typename T, class Tr>
typename VectorHandler<T, Tr>::VectorType
@@ -973,7 +693,7 @@ VectorHandler<T, Tr>::list_to_vector (GList* glist, Glib::OwnershipType ownershi
return VectorType (ListIteratorType (glist), ListIteratorType (0));
#else
VectorType temp;
- //temp.reserve (???);
+ temp.reserve (g_list_length (glist));
Glib::Container_Helpers::fill_container (temp, ListIteratorType (glist), ListIteratorType (0));
return temp;
#endif
@@ -989,7 +709,7 @@ VectorHandler<T, Tr>::slist_to_vector (GSList* gslist, Glib::OwnershipType owner
return VectorType (SListIteratorType (gslist), SListIteratorType (0));
#else
VectorType temp;
- //temp.reserve (???);
+ temp.reserve (g_slist_length (gslist));
Glib::Container_Helpers::fill_container (temp, SListIteratorType (gslist), SListIteratorType (0));
return temp;
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]