aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-28 19:27:02 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-28 19:27:02 +0000
commit4a4d8760dbbbdd23d1da2bd5c09ac998ed9dd45e (patch)
tree58804c87dea9134e4163dbbd73d7e422894e4e8d
parent1945bc4f10d16e53392a945fd39f87e435256a45 (diff)
downloadpaludis-4a4d8760dbbbdd23d1da2bd5c09ac998ed9dd45e.tar.gz
paludis-4a4d8760dbbbdd23d1da2bd5c09ac998ed9dd45e.tar.xz
Convert over output iterators too
-rw-r--r--paludis/environments/no_config/no_config_environment.cc4
-rw-r--r--paludis/util/map-fwd.hh3
-rw-r--r--paludis/util/map-impl.hh6
-rw-r--r--paludis/util/map.hh2
-rw-r--r--paludis/util/sequence-fwd.hh3
-rw-r--r--paludis/util/sequence-impl.hh13
-rw-r--r--paludis/util/sequence.hh3
-rw-r--r--paludis/util/set-fwd.hh3
-rw-r--r--paludis/util/set-impl.hh6
-rw-r--r--paludis/util/set.hh4
-rw-r--r--paludis/util/wrapped_output_iterator-fwd.hh7
-rw-r--r--paludis/util/wrapped_output_iterator-impl.hh115
-rw-r--r--paludis/util/wrapped_output_iterator.hh17
13 files changed, 117 insertions, 69 deletions
diff --git a/paludis/environments/no_config/no_config_environment.cc b/paludis/environments/no_config/no_config_environment.cc
index a54273d..086ef0d 100644
--- a/paludis/environments/no_config/no_config_environment.cc
+++ b/paludis/environments/no_config/no_config_environment.cc
@@ -22,14 +22,14 @@
#include <paludis/util/log.hh>
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
-#include <paludis/util/map.hh>
+#include <paludis/util/map-impl.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/create_iterator-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/config_file.hh>
-#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/wrapped_output_iterator-impl.hh>
#include <paludis/util/tribool.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/graph-impl.hh>
diff --git a/paludis/util/map-fwd.hh b/paludis/util/map-fwd.hh
index bc92a0b..5da54f6 100644
--- a/paludis/util/map-fwd.hh
+++ b/paludis/util/map-fwd.hh
@@ -36,6 +36,9 @@ namespace paludis
template <typename K_, typename V_, typename C_ = DefaultMapComparator<K_> >
struct MapConstIteratorTag;
+
+ template <typename K_, typename V_, typename C_ = DefaultMapComparator<K_> >
+ struct MapInserterTag;
}
#endif
diff --git a/paludis/util/map-impl.hh b/paludis/util/map-impl.hh
index df6dfa4..901ca1e 100644
--- a/paludis/util/map-impl.hh
+++ b/paludis/util/map-impl.hh
@@ -67,6 +67,12 @@ namespace paludis
{
typedef typename std::map<K_, V_, C_>::const_iterator UnderlyingIterator;
};
+
+ template <typename K_, typename V_, typename C_>
+ struct WrappedOutputIteratorTraits<MapInserterTag<K_, V_, C_> >
+ {
+ typedef std::insert_iterator<std::map<K_, V_, C_> > UnderlyingIterator;
+ };
}
template <typename K_, typename V_, typename C_>
diff --git a/paludis/util/map.hh b/paludis/util/map.hh
index f49622c..0febf69 100644
--- a/paludis/util/map.hh
+++ b/paludis/util/map.hh
@@ -75,7 +75,7 @@ namespace paludis
ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
ConstIterator find(const K_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
- struct InserterTag;
+ typedef MapInserterTag<K_, V_, C_> InserterTag;
typedef WrappedOutputIterator<InserterTag, std::pair<const K_, V_> > Inserter;
Inserter inserter() PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/util/sequence-fwd.hh b/paludis/util/sequence-fwd.hh
index 4df8906..67a7d42 100644
--- a/paludis/util/sequence-fwd.hh
+++ b/paludis/util/sequence-fwd.hh
@@ -36,6 +36,9 @@ namespace paludis
template <typename T_>
struct SequenceReverseConstIteratorTag;
+
+ template <typename T_>
+ struct SequenceInserterTag;
}
#endif
diff --git a/paludis/util/sequence-impl.hh b/paludis/util/sequence-impl.hh
index ee748be..116377c 100644
--- a/paludis/util/sequence-impl.hh
+++ b/paludis/util/sequence-impl.hh
@@ -61,6 +61,12 @@ namespace paludis
{
typedef typename std::list<T_>::const_reverse_iterator UnderlyingIterator;
};
+
+ template <typename T_>
+ struct WrappedOutputIteratorTraits<SequenceInserterTag<T_> >
+ {
+ typedef std::back_insert_iterator<std::list<T_> > UnderlyingIterator;
+ };
}
template <typename T_>
@@ -117,13 +123,6 @@ paludis::Sequence<T_>::back_inserter()
}
template <typename T_>
-typename paludis::Sequence<T_>::Inserter
-paludis::Sequence<T_>::front_inserter()
-{
- return Inserter(std::front_inserter(_imp->list));
-}
-
-template <typename T_>
void
paludis::Sequence<T_>::push_back(const T_ & t)
{
diff --git a/paludis/util/sequence.hh b/paludis/util/sequence.hh
index 5b8b74d..d9fc012 100644
--- a/paludis/util/sequence.hh
+++ b/paludis/util/sequence.hh
@@ -86,10 +86,9 @@ namespace paludis
ReverseConstIterator rbegin() const PALUDIS_ATTRIBUTE((warn_unused_result));
ReverseConstIterator rend() const PALUDIS_ATTRIBUTE((warn_unused_result));
- struct InserterTag;
+ typedef SequenceInserterTag<T_> InserterTag;
typedef WrappedOutputIterator<InserterTag, T_> Inserter;
Inserter back_inserter();
- Inserter front_inserter();
///\}
diff --git a/paludis/util/set-fwd.hh b/paludis/util/set-fwd.hh
index 692ebcb..4a6193f 100644
--- a/paludis/util/set-fwd.hh
+++ b/paludis/util/set-fwd.hh
@@ -36,6 +36,9 @@ namespace paludis
template <typename T_, typename C_>
struct SetConstIteratorTag;
+
+ template <typename T_, typename C_>
+ struct SetInsertIteratorTag;
}
#endif
diff --git a/paludis/util/set-impl.hh b/paludis/util/set-impl.hh
index 5e49ab3..f3b0e80 100644
--- a/paludis/util/set-impl.hh
+++ b/paludis/util/set-impl.hh
@@ -69,6 +69,12 @@ namespace paludis
{
typedef typename std::set<T_, C_>::const_iterator UnderlyingIterator;
};
+
+ template <typename T_, typename C_>
+ struct WrappedOutputIteratorTraits<SetInsertIteratorTag<T_, C_> >
+ {
+ typedef std::insert_iterator<std::set<T_, C_> > UnderlyingIterator;
+ };
}
template <typename T_, typename C_>
diff --git a/paludis/util/set.hh b/paludis/util/set.hh
index f1b8b5d..ebcd8a7 100644
--- a/paludis/util/set.hh
+++ b/paludis/util/set.hh
@@ -56,6 +56,8 @@ namespace paludis
using PrivateImplementationPattern<Set<T_, C_> >::_imp;
public:
+ typedef T_ Tag;
+
///\name Standard library typedefs
///\{
@@ -82,7 +84,7 @@ namespace paludis
ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
ConstIterator find(const T_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
- struct InserterTag;
+ typedef SetInsertIteratorTag<T_, C_> InserterTag;
typedef WrappedOutputIterator<InserterTag, T_> Inserter;
Inserter inserter();
diff --git a/paludis/util/wrapped_output_iterator-fwd.hh b/paludis/util/wrapped_output_iterator-fwd.hh
index 9f15449..d978bfd 100644
--- a/paludis/util/wrapped_output_iterator-fwd.hh
+++ b/paludis/util/wrapped_output_iterator-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -24,6 +24,11 @@ namespace paludis
{
template <typename Tag_, typename Value_>
struct WrappedOutputIterator;
+
+ template <typename Tag_>
+ struct WrappedOutputIteratorTraits;
+
+ struct WrappedOutputIteratorUnderlyingIteratorHolder;
}
#endif
diff --git a/paludis/util/wrapped_output_iterator-impl.hh b/paludis/util/wrapped_output_iterator-impl.hh
index 101a9a9..26e1569 100644
--- a/paludis/util/wrapped_output_iterator-impl.hh
+++ b/paludis/util/wrapped_output_iterator-impl.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -21,80 +21,88 @@
#define PALUDIS_GUARD_PALUDIS_UTIL_WRAPPED_OUTPUT_ITERATOR_IMPL_HH 1
#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/checked_delete.hh>
namespace paludis
{
- template <typename Tag_, typename Value_>
- struct WrappedOutputIterator<Tag_, Value_>::Base
+ template <typename WrappedIter_>
+ typename WrappedOutputIteratorTraits<typename WrappedIter_::Tag>::UnderlyingIterator *
+ wrapped_underlying_iterator_real_type(const WrappedIter_ &, void * i)
{
- virtual Base * clone() const = 0;
- virtual void increment() = 0;
- virtual void assign(const Value_ &) = 0;
+ return reinterpret_cast<typename WrappedOutputIteratorTraits<typename WrappedIter_::Tag>::UnderlyingIterator *>(i);
+ }
- virtual ~Base()
- {
- }
- };
+ template <typename WrappedIter_>
+ WrappedOutputIteratorUnderlyingIteratorHolder *
+ wrapped_underlying_iterator_hide_real_type(const WrappedIter_ &,
+ typename WrappedOutputIteratorTraits<typename WrappedIter_::Tag>::UnderlyingIterator * const i)
+ {
+ return reinterpret_cast<WrappedOutputIteratorUnderlyingIteratorHolder *>(i);
+ }
template <typename Tag_, typename Value_>
- template <typename Iter_>
- struct WrappedOutputIterator<Tag_, Value_>::BaseImpl :
- WrappedOutputIterator<Tag_, Value_>::Base
+ WrappedOutputIterator<Tag_, Value_>::~WrappedOutputIterator()
{
- Iter_ i;
+ checked_delete(wrapped_underlying_iterator_real_type(*this, _iter));
+ }
- BaseImpl(const Iter_ & ii) :
- i(ii)
+ template <typename Tag_, typename Value_, typename Iter_>
+ struct WrappedOutputIteratorGetBase
+ {
+ template <typename Traits_>
+ static typename Traits_::UnderlyingIterator real_get_iter(const typename Traits_::UnderlyingIterator & i)
{
+ return i;
}
- Base * clone() const
+ template <typename Traits_>
+ static typename Traits_::UnderlyingIterator
+ real_get_iter(const typename Traits_::EquivalentNonConstIterator & i)
{
- return new BaseImpl(i);
+ return typename Traits_::UnderlyingIterator(
+ i.template underlying_iterator<typename WrappedOutputIteratorTraits<
+ typename WrappedOutputIteratorTraits<Tag_>::EquivalentNonConstIterator::Tag
+ >::UnderlyingIterator>()
+ );
}
- void increment()
+ static typename WrappedOutputIteratorTraits<Tag_>::UnderlyingIterator get_iter(const Iter_ & i)
{
- ++i;
+ return real_get_iter<WrappedOutputIteratorTraits<Tag_> >(i);
}
+ };
- void assign(const Value_ & v)
+ template <typename Tag_, typename Value_>
+ struct WrappedOutputIteratorGetBase<Tag_, Value_, WrappedOutputIterator<Tag_, Value_> >
+ {
+ static WrappedOutputIterator<Tag_, Value_> get_iter(const WrappedOutputIterator<Tag_, Value_> & i)
{
- *i = v;
+ return i.template underlying_iterator<typename WrappedOutputIteratorTraits<Tag_>::UnderlyingIterator>();
}
};
template <typename Tag_, typename Value_>
- WrappedOutputIterator<Tag_, Value_>::WrappedOutputIterator() :
- _base(0)
- {
- }
+ template <typename T_>
+ WrappedOutputIterator<Tag_, Value_>::WrappedOutputIterator(const T_ & iter) :
+ _iter(wrapped_underlying_iterator_hide_real_type(*this, new typename WrappedOutputIteratorTraits<Tag_>::UnderlyingIterator(
+ WrappedOutputIteratorGetBase<Tag_, Value_, T_>::get_iter(iter))
+ ))
- template <typename Tag_, typename Value_>
- WrappedOutputIterator<Tag_, Value_>::~WrappedOutputIterator()
{
- delete _base;
}
template <typename Tag_, typename Value_>
WrappedOutputIterator<Tag_, Value_>::WrappedOutputIterator(const WrappedOutputIterator & other) :
- _base(other._base ? other._base->clone() : other._base)
- {
- }
-
- template <typename Tag_, typename Value_>
- template <typename T_>
- WrappedOutputIterator<Tag_, Value_>::WrappedOutputIterator(const T_ & base) :
- _base(new BaseImpl<T_>(base))
+ _iter(wrapped_underlying_iterator_hide_real_type(*this, new typename WrappedOutputIteratorTraits<Tag_>::UnderlyingIterator(
+ *wrapped_underlying_iterator_real_type(other, other._iter))))
{
}
template <typename Tag_, typename Value_>
WrappedOutputIterator<Tag_, Value_> &
- WrappedOutputIterator<Tag_, Value_>::operator= (const WrappedOutputIterator<Tag_, Value_> & other)
+ WrappedOutputIterator<Tag_, Value_>::operator= (const WrappedOutputIterator & other)
{
- if (this != &other)
- _base = other._base ? other._base->clone() : other._base;
+ *wrapped_underlying_iterator_real_type(*this, _iter) = *wrapped_underlying_iterator_real_type(other, other._iter);
return *this;
}
@@ -102,7 +110,7 @@ namespace paludis
WrappedOutputIterator<Tag_, Value_> &
WrappedOutputIterator<Tag_, Value_>::operator= (const Value_ & value)
{
- _base->assign(value);
+ *wrapped_underlying_iterator_real_type(*this, _iter) = value;
return *this;
}
@@ -110,7 +118,7 @@ namespace paludis
WrappedOutputIterator<Tag_, Value_> &
WrappedOutputIterator<Tag_, Value_>::operator++ ()
{
- _base->increment();
+ ++*wrapped_underlying_iterator_real_type(*this, _iter);
return *this;
}
@@ -119,22 +127,31 @@ namespace paludis
WrappedOutputIterator<Tag_, Value_>::operator++ (int)
{
WrappedOutputIterator result(*this);
- _base->increment();
+ operator++ ();
return result;
}
template <typename Tag_, typename Value_>
- typename WrappedOutputIterator<Tag_, Value_>::pointer
- WrappedOutputIterator<Tag_, Value_>::operator-> ()
+ typename WrappedOutputIterator<Tag_, Value_>::reference
+ WrappedOutputIterator<Tag_, Value_>::operator* ()
{
- return this;
+ return *this;
}
template <typename Tag_, typename Value_>
- typename WrappedOutputIterator<Tag_, Value_>::reference
- WrappedOutputIterator<Tag_, Value_>::operator* ()
+ template <typename T_>
+ T_ &
+ WrappedOutputIterator<Tag_, Value_>::underlying_iterator()
{
- return *this;
+ return *wrapped_underlying_iterator_real_type(*this, _iter);
+ }
+
+ template <typename Tag_, typename Value_>
+ template <typename T_>
+ const T_ &
+ WrappedOutputIterator<Tag_, Value_>::underlying_iterator() const
+ {
+ return *wrapped_underlying_iterator_real_type(*this, _iter);
}
}
diff --git a/paludis/util/wrapped_output_iterator.hh b/paludis/util/wrapped_output_iterator.hh
index 0be9994..1e12f4b 100644
--- a/paludis/util/wrapped_output_iterator.hh
+++ b/paludis/util/wrapped_output_iterator.hh
@@ -37,16 +37,14 @@ namespace paludis
class PALUDIS_VISIBLE WrappedOutputIterator
{
private:
- struct Base;
- template <typename T_> struct BaseImpl;
-
- Base * _base;
+ WrappedOutputIteratorUnderlyingIteratorHolder * _iter;
public:
+ typedef Tag_ Tag;
+
///\name Basic operations
///\{
- WrappedOutputIterator();
~WrappedOutputIterator();
WrappedOutputIterator(const WrappedOutputIterator &);
@@ -80,10 +78,17 @@ namespace paludis
///\name Dereference
///\{
- pointer operator-> ();
reference operator* ();
///\}
+
+ ///\name Underlying iterator
+ ///\{
+
+ template <typename T_> T_ & underlying_iterator();
+ template <typename T_> const T_ & underlying_iterator() const;
+
+ ///\}
};
}