|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63625 - in sandbox/SOC/2009/unicode: boost/iterator boost/iterator/detail libs/unicode/example
From: loufoque_at_[hidden]
Date: 2010-07-04 15:11:51
Author: mgaunard
Date: 2010-07-04 15:11:51 EDT (Sun, 04 Jul 2010)
New Revision: 63625
URL: http://svn.boost.org/trac/boost/changeset/63625
Log:
moving convert_output_storage in its own header + making convert_output_iterator use compressed_pair
Added:
sandbox/SOC/2009/unicode/boost/iterator/detail/
sandbox/SOC/2009/unicode/boost/iterator/detail/convert_output_storage.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2009/unicode/boost/iterator/convert_iterator_fwd.hpp | 111 +++++++--------------------------------
sandbox/SOC/2009/unicode/libs/unicode/example/convert.cpp | 4 +
2 files changed, 23 insertions(+), 92 deletions(-)
Modified: sandbox/SOC/2009/unicode/boost/iterator/convert_iterator_fwd.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/iterator/convert_iterator_fwd.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/iterator/convert_iterator_fwd.hpp 2010-07-04 15:11:51 EDT (Sun, 04 Jul 2010)
@@ -1,92 +1,14 @@
#ifndef BOOST_ITERATOR_PIPE_ITERATOR_FWD_HPP
#define BOOST_ITERATOR_PIPE_ITERATOR_FWD_HPP
-#include <boost/utility/enable_if.hpp>
-#include <boost/mpl/has_xxx.hpp>
-
#include <boost/iterator/iterator_facade.hpp>
-#include <vector>
+#include <boost/iterator/detail/convert_output_storage.hpp>
-#include <boost/iterator/converter_concept.hpp>
+#include <boost/compressed_pair.hpp>
namespace boost
{
-namespace detail
-{
- BOOST_MPL_HAS_XXX_TRAIT_DEF(max_output)
-
- template<typename P, typename Enable = void>
- struct convert_output_storage;
-
- template<typename P>
- struct convert_output_storage<P, typename ::boost::disable_if< has_max_output<P> >::type>
- {
- BOOST_CONCEPT_ASSERT((ConverterConcept<P>));
-private:
- typedef std::vector<typename P::output_type> Values;
-public:
- typedef std::back_insert_iterator<Values> output_iterator;
-
- const typename P::output_type& operator[](size_t i) const
- {
- return values[i];
- }
-
- size_t last_index() const
- {
- return values.size() - 1;
- }
-
- output_iterator out()
- {
- values.clear();
- return std::back_inserter(values);
- }
-
- void update(output_iterator)
- {
- }
-
- private:
- Values values;
- };
-
- template<typename P>
- struct convert_output_storage<P, typename boost::enable_if< has_max_output<P> >::type>
- {
- BOOST_CONCEPT_ASSERT((ConverterConcept<P>));
-private:
- typedef typename P::output_type Value;
-public:
- typedef Value* output_iterator;
-
- const Value& operator[](size_t i) const
- {
- return values[i];
- }
-
- size_t last_index() const
- {
- return last;
- }
-
- output_iterator out()
- {
- return values;
- }
-
- void update(output_iterator u)
- {
- last = u - values - 1;
- }
-
- private:
- Value values[P::max_output::value];
- size_t last;
- };
-}
-
/** Iterator adapter that wraps a range to make it appear like a converted
* one, by converting it step-by-step as it is advanced. */
template<typename It, typename Converter>
@@ -193,7 +115,7 @@
/** Output Iterator adapter that wraps an output iterator to make one
* that will convert its output before pushing it to the wrapped iterator. */
template<typename OutputIterator, typename OneManyConverter>
-struct convert_output_iterator
+struct convert_output_iterator : private boost::compressed_pair<OutputIterator, OneManyConverter>
{
BOOST_CONCEPT_ASSERT((OutputIteratorConcept<OutputIterator, typename OneManyConverter::output_type>));
BOOST_CONCEPT_ASSERT((OneManyConverterConcept<OneManyConverter>));
@@ -206,13 +128,14 @@
convert_output_iterator() {} // singular
- convert_output_iterator(OutputIterator pos_, OneManyConverter p_) : pos(pos_), p(p_)
+ convert_output_iterator(OutputIterator pos_, OneManyConverter p_)
+ : boost::compressed_pair<OutputIterator, OneManyConverter>(pos_, p_)
{
}
OutputIterator base() const
{
- return pos;
+ return get_out();
}
const convert_output_iterator& operator*() const
@@ -230,25 +153,31 @@
return *this;
}
- template<typename T>
- void operator=(T val) const
+ void operator=(const typename OneManyConverter::input_type& val) const
{
- pos = p(val, pos);
+ get_out() = get_conv()(val, get_out());
}
bool operator==(const convert_output_iterator& other) const
{
- return pos == other.pos;
+ return get_out() == other.get_out();
}
bool operator!=(const convert_output_iterator& other) const
{
- return pos != other.pos;
+ return get_out() != other.get_out();
}
-private:
- mutable OutputIterator pos;
- mutable OneManyConverter p;
+private:
+ OutputIterator& get_out() const
+ {
+ return const_cast<convert_output_iterator&>(*this).first();
+ }
+
+ OneManyConverter& get_conv() const
+ {
+ return const_cast<convert_output_iterator&>(*this).second();
+ }
};
} // namespace boost
Added: sandbox/SOC/2009/unicode/boost/iterator/detail/convert_output_storage.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/boost/iterator/detail/convert_output_storage.hpp 2010-07-04 15:11:51 EDT (Sun, 04 Jul 2010)
@@ -0,0 +1,87 @@
+#ifndef BOOST_ITERATOR_DETAIL_CONVERT_OUTPUT_STORAGE_HPP
+#define BOOST_ITERATOR_DETAIL_CONVERT_OUTPUT_STORAGE_HPP
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/has_xxx.hpp>
+#include <vector>
+
+#include <boost/iterator/converter_concept.hpp>
+
+namespace boost
+{
+namespace detail
+{
+ BOOST_MPL_HAS_XXX_TRAIT_DEF(max_output)
+
+ template<typename P, typename Enable = void>
+ struct convert_output_storage;
+
+ template<typename P>
+ struct convert_output_storage<P, typename ::boost::disable_if< has_max_output<P> >::type>
+ {
+ BOOST_CONCEPT_ASSERT((ConverterConcept<P>));
+private:
+ typedef std::vector<typename P::output_type> Values;
+public:
+ typedef std::back_insert_iterator<Values> output_iterator;
+
+ const typename P::output_type& operator[](size_t i) const
+ {
+ return values[i];
+ }
+
+ size_t last_index() const
+ {
+ return values.size() - 1;
+ }
+
+ output_iterator out()
+ {
+ values.clear();
+ return std::back_inserter(values);
+ }
+
+ void update(output_iterator)
+ {
+ }
+
+ private:
+ Values values;
+ };
+
+ template<typename P>
+ struct convert_output_storage<P, typename boost::enable_if< has_max_output<P> >::type>
+ {
+ BOOST_CONCEPT_ASSERT((ConverterConcept<P>));
+private:
+ typedef typename P::output_type Value;
+public:
+ typedef Value* output_iterator;
+
+ const Value& operator[](size_t i) const
+ {
+ return values[i];
+ }
+
+ size_t last_index() const
+ {
+ return last;
+ }
+
+ output_iterator out()
+ {
+ return values;
+ }
+
+ void update(output_iterator u)
+ {
+ last = u - values - 1;
+ }
+
+ private:
+ Value values[P::max_output::value];
+ size_t last;
+ };
+}
+}
+#endif
Modified: sandbox/SOC/2009/unicode/libs/unicode/example/convert.cpp
==============================================================================
--- sandbox/SOC/2009/unicode/libs/unicode/example/convert.cpp (original)
+++ sandbox/SOC/2009/unicode/libs/unicode/example/convert.cpp 2010-07-04 15:11:51 EDT (Sun, 04 Jul 2010)
@@ -4,6 +4,7 @@
encodings, by converting a UTF-x range into UTF-8 and printing it.
*/
#include <boost/unicode/utf.hpp>
+#include <boost/range/as_literal.hpp>
#include <boost/foreach.hpp>
#include <vector>
#include <string>
@@ -14,7 +15,8 @@
int main()
{
- wchar_t foo[] = L"hello \u00E9 world";
+ // we use boost::as_literal in order not to have the trailing null character
+ boost::iterator_range<const wchar_t*> foo = boost::as_literal(L"hello \u00E9 world");
std::vector<boost::char32> bar;
std::string baz;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk