|
From: <za...@us...> - 2008-10-06 11:42:58
|
Revision: 496
http://libmage.svn.sourceforge.net/libmage/?rev=496&view=rev
Author: zaufi
Date: 2008-10-06 11:42:44 +0000 (Mon, 06 Oct 2008)
Log Message:
-----------
temp
Modified Paths:
--------------
libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh
libMAGE/branches/version-0-1/libmage/iterator/mapping_functor.hh
libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am
libMAGE/branches/version-0-1/libmage/iterator/tests/mapping_iterator_o2m_tester.cc
libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc
Added Paths:
-----------
libMAGE/branches/version-0-1/libmage/iterator/details/iteration_controller_o2m.hh
libMAGE/branches/version-0-1/libmage/iterator/mapping_iterator_o2m.hh
Modified: libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh 2008-10-04 02:16:29 UTC (rev 495)
+++ libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh 2008-10-06 11:42:44 UTC (rev 496)
@@ -48,7 +48,12 @@
namespace mage { namespace details {
/**
- * \brief [Type brief class description here]
+ * \brief Bit selection transformation
+ * Transform input sequence of elements of type \c SrcType in the following way:
+ * \li select low \c BitsIn bits in element
+ * \li slice valued bits by groups of \b BitsOut bits and from an output element
+ * \li if remaining bits count after last read is not enough to form a next output element
+ * read next input element...
*/
template <
int BitsIn
@@ -77,7 +82,6 @@
));
typedef typename boost::make_unsigned<SrcType>::type source_type;
-// typedef typename boost::make_unsigned<SrcType> internal_source_type;
typedef DstType target_type;
typedef typename boost::uint_t<BitsIn>::least remainder_int;
@@ -100,10 +104,11 @@
assert("Sanity check" && (0 == m_bits_remain));
m_current = c;
m_bits_remain = BitsIn - BitsOut;
-// std::cout << THIS_LOCATION() << ": " << OUT_ANY_VAR(m_bits_remain) << std::endl;
+// std::cout << THIS_LOCATION() << ": " << OUT_ANY_VAR(int(m_bits_remain)) << std::endl;
it.overflow();
return select_bits(m_current, m_bits_remain, BitsOut);
}
+
template <typename MapIter>
result_type operator()(MapIter& it)
{
@@ -120,6 +125,7 @@
return select_bits(m_current, m_bits_remain = 0, BitsOut);
}
// m_bits_remain < BitsOut -- means that next element needed to fill external bits from it
+ assert("The only invariant remain..." && (m_bits_remain < BitsOut));
if (it.has_next())
{
source_type next = it.next();
@@ -130,11 +136,17 @@
result_type r = (select_bits(next, 0, bits_remain) << m_bits_remain)
| select_bits(m_current, BitsIn - m_bits_remain, m_bits_remain)
;
- m_bits_remain -= BitsIn;
+ m_bits_remain = BitsIn - m_bits_remain;
return r;
}
throw std::runtime_error("Incomplete sequence of elements");
}
+ /// It makes \c bits_shrink_transform equal comparable to take its state into account
+ /// when \c mapping_iterators are compared.
+ bool operator==(const bits_shrink_transform& other) const
+ {
+ return m_current == other.m_current && m_bits_remain == other.m_bits_remain;
+ }
};
}} // namespace details, mage
Added: libMAGE/branches/version-0-1/libmage/iterator/details/iteration_controller_o2m.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/details/iteration_controller_o2m.hh (rev 0)
+++ libMAGE/branches/version-0-1/libmage/iterator/details/iteration_controller_o2m.hh 2008-10-06 11:42:44 UTC (rev 496)
@@ -0,0 +1,99 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class iteration_controller_o2m (interface)
+ *
+ * \date Sat Oct 4 19:35:12 MSD 2008 -- Initial design
+ */
+/*
+ *
+ * libMAGE is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libMAGE is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __LIBMAGE__ITERATOR__DETAILS__ITERATION_CONTROLLER_O2M_HH__
+# define __LIBMAGE__ITERATOR__DETAILS__ITERATION_CONTROLLER_O2M_HH__
+
+// Project specific includes
+# include <libmage-config.h>
+
+// Standard includes
+
+namespace mage {
+
+template <
+ typename ForwardInputIter
+ , typename Transformer
+ >
+class mapping_iterator_o2m;
+
+namespace details {
+
+/**
+ * \brief [Type brief class description here]
+ *
+ * [More detailed description here]
+ *
+ */
+template <
+ typename ForwardInputIter
+ , typename Transformer
+ >
+class iteration_controller_o2m
+{
+ friend class mapping_iterator_o2m<ForwardInputIter, Transformer>;
+
+ typedef mapping_iterator_o2m<ForwardInputIter, Transformer> controlled_iterator_type;
+ typedef ForwardInputIter iterator_type;
+ typedef Transformer transformer_type;
+
+ bool m_is_overflow;
+
+ /// \note The only exceptions unsafe function... but it is Ok, or even good that user's
+ /// functors may throw exceptions to indicate errors
+ typename transformer_type::result_type operator()(controlled_iterator_type& iter, transformer_type& f)
+ {
+ return is_overflow() ? f(*this) : f(*this, *iter.m_cur);
+ }
+ bool is_overflow() const
+ {
+ return m_is_overflow;
+ }
+ bool operator==(const iteration_controller_o2m& other) const
+ {
+ return m_is_overflow == other.m_is_overflow;
+ }
+
+public:
+ /// Default constructor
+ iteration_controller_o2m()
+ {
+ underflow();
+ }
+
+ void overflow()
+ {
+ m_is_overflow = true;
+ }
+ void underflow()
+ {
+ m_is_overflow = false;
+ }
+};
+
+}} // namespace details, mage
+#endif // __LIBMAGE__ITERATOR__DETAILS__ITERATION_CONTROLLER_O2M_HH__
Property changes on: libMAGE/branches/version-0-1/libmage/iterator/details/iteration_controller_o2m.hh
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
Modified: libMAGE/branches/version-0-1/libmage/iterator/mapping_functor.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/mapping_functor.hh 2008-10-04 02:16:29 UTC (rev 495)
+++ libMAGE/branches/version-0-1/libmage/iterator/mapping_functor.hh 2008-10-06 11:42:44 UTC (rev 496)
@@ -35,7 +35,6 @@
namespace mage {
-struct one2one_mapper_tag {};
struct many2one_mapper_tag {};
struct one2many_mapper_tag {};
struct many2many_mapper_tag {};
Added: libMAGE/branches/version-0-1/libmage/iterator/mapping_iterator_o2m.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/mapping_iterator_o2m.hh (rev 0)
+++ libMAGE/branches/version-0-1/libmage/iterator/mapping_iterator_o2m.hh 2008-10-06 11:42:44 UTC (rev 496)
@@ -0,0 +1,149 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class mapping_iterator_o2m (interface)
+ *
+ * \date Fri Oct 3 14:23:12 MSD 2008 -- Initial design
+ */
+/*
+ *
+ * libMAGE is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libMAGE is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __LIBMAGE__ITERATOR__MAPPING_ITERATOR_O2M_HH__
+# define __LIBMAGE__ITERATOR__MAPPING_ITERATOR_O2M_HH__
+
+// Project specific includes
+# include <libmage-config.h>
+# include <libmage/iterator/details/iteration_controller_o2m.hh>
+# include <libmage/iterator/details/transformation_functor_equal_compare.hh>
+
+// Standard includes
+# include <boost/call_traits.hpp>
+# include <boost/iterator/iterator_facade.hpp>
+# include <boost/optional.hpp>
+# include <boost/mpl/assert.hpp>
+# include <cassert>
+# include <stdexcept>
+
+namespace mage {
+
+/**
+ * \brief Transform sequence of elements to another one possible with more elements
+ */
+template <
+ typename ForwardInputIter
+ , typename Transformer
+ >
+class mapping_iterator_o2m : public boost::iterator_facade<
+ mapping_iterator_o2m<ForwardInputIter, Transformer>
+ , typename Transformer::result_type // Iterator value type is a result of transform functor
+ , boost::forward_traversal_tag
+ , typename boost::call_traits< // Reference type can be only const due 'view'
+ typename Transformer::result_type // nature of this iterator
+ >::param_type
+ >
+{
+ friend class boost::iterator_core_access;
+ friend class details::iteration_controller_o2m<ForwardInputIter, Transformer>;
+
+ typedef mapping_iterator_o2m<ForwardInputIter, Transformer> self_type;
+ typedef details::iteration_controller_o2m<ForwardInputIter, Transformer> controller_impl;
+ typedef ForwardInputIter iterator_type;
+ typedef Transformer transformer_type;
+ typedef typename Transformer::result_type result_type;
+
+ iterator_type m_cur; //!< Current position in a sequence
+ boost::optional<transformer_type> m_tr; //!< Transformation functor
+ boost::optional<result_type> m_cur_res; //!< Result of transformation of the current element
+ controller_impl m_ctl;
+
+ /// Obtain result of transformation of current element
+ void update_from_current()
+ {
+ assert("Transformer function is not initialized. Attempt to dereference 'end' iterator?" && !!m_tr);
+ m_cur_res = m_ctl(*this, m_tr.get());
+ }
+
+ void increment()
+ {
+ if (!m_ctl.is_overflow()) // Do real increment only when we've done with current element
+ ++m_cur;
+ update_from_current(); // Get next element from functor
+ }
+ /**
+ * \brief Equality check
+ * Check if both iterators are initialized in the same way (i.e. both r 'end' or 'normal')
+ * then compare all fields, else (if at least one) is 'end' iterator, then just compare underlayed iterators.
+ */
+ bool equal(const self_type& other) const
+ {
+ if (!m_tr || !other.m_tr) // this iterator is 'end'
+ return m_cur == other.m_cur; // just compare 'end' iterators
+ // iterators are both 'normal' -- compare all fields
+ return m_cur == other.m_cur
+ && m_cur_res == other.m_cur_res
+ && m_ctl == other.m_ctl
+ && details::transformation_functor_equal_compare<transformer_type>(m_tr.get(), other.m_tr.get())
+ ;
+ }
+
+ result_type dereference() const
+ {
+ assert("Dereference of uninitialized iterator" && !!m_cur_res);
+ return m_cur_res.get();
+ }
+
+public:
+ /// Construct iterator initialized with given underlayed iterator and transformation functor
+ mapping_iterator_o2m(
+ typename boost::call_traits<iterator_type>::param_type begin
+ , typename boost::call_traits<transformer_type>::param_type tr
+ )
+ : m_cur(begin)
+ , m_tr(tr)
+ {
+ update_from_current();
+ }
+ /// Construct 'end' iterator initialized with given underlayed end iterator
+ mapping_iterator_o2m(
+ typename boost::call_traits<iterator_type>::param_type end
+ )
+ : m_cur(end)
+ {}
+ /// Copy constructor
+ mapping_iterator_o2m(const mapping_iterator_o2m& other)
+ : m_cur(other.m_cur)
+ , m_tr(other.m_tr)
+ , m_cur_res(other.m_cur_res)
+ , m_ctl(other.m_ctl)
+ {
+ }
+ /// Assignment operator
+ mapping_iterator_o2m& operator=(const mapping_iterator_o2m& other)
+ {
+ m_cur = other.m_cur;
+ m_tr = other.m_tr;
+ m_cur_res = other.m_cur_res;
+ m_ctl = other.m_ctl;
+ return *this;
+ }
+};
+
+} // namespace mage
+#endif // __LIBMAGE__ITERATOR__MAPPING_ITERATOR_O2M_HH__
Property changes on: libMAGE/branches/version-0-1/libmage/iterator/mapping_iterator_o2m.hh
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
Modified: libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am 2008-10-04 02:16:29 UTC (rev 495)
+++ libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am 2008-10-06 11:42:44 UTC (rev 496)
@@ -5,13 +5,17 @@
check_PROGRAMS = unit_tests
unit_tests_SOURCES = \
- mapping_iterator_o2o_tester.cc \
- mapping_iterator_o2m_tester.cc \
- mapping_iterator_m2o_tester.cc \
- mapping_iterator_m2m_tester.cc \
- char2hex_hex2char_tester.cc \
- xml_escape_tester.cc \
- transform_width_tester.cc
+ mapping_iterator_o2m_tester.cc
+
+# mapping_iterator_o2o_tester.cc \
+# mapping_iterator_o2m_tester.cc \
+# mapping_iterator_m2o_tester.cc \
+# mapping_iterator_m2m_tester.cc \
+# char2hex_hex2char_tester.cc \
+# xml_escape_tester.cc \
+# transform_width_tester.cc \
+# base64_tester.cc
+
unit_tests_LDFLAGS = -no-install
unit_tests_LDADD = -lboost_unit_test_framework$(BOOST_LIB_SUFFIX)
Modified: libMAGE/branches/version-0-1/libmage/iterator/tests/mapping_iterator_o2m_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/tests/mapping_iterator_o2m_tester.cc 2008-10-04 02:16:29 UTC (rev 495)
+++ libMAGE/branches/version-0-1/libmage/iterator/tests/mapping_iterator_o2m_tester.cc 2008-10-06 11:42:44 UTC (rev 496)
@@ -31,15 +31,24 @@
#include <libmage/debug/type_name.hh>
#include <iostream>
// </for-debug-purposes-only>
-#include <libmage/iterator/mapping_iterator.hh>
+#include <libmage/iterator/mapping_iterator_o2m.hh>
+#include <libmage/iterator/mapping_functor.hh>
+#define BOOST_AUTO_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
#include <libmage/shared/auto_test_case.hh>
// Standard includes
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_arithmetic.hpp>
#include <cstring>
#include <string>
using namespace std;
+struct equal_comparable_tag {};
+struct not_equal_comparable_tag {};
+
template <typename T>
class o2m_tr : public mage::mapping_functor<T, mage::one2many_mapper_tag>
{
@@ -51,6 +60,7 @@
template <typename MapIter>
result_type operator()(MapIter& it, result_type c)
{
+// std::cout << THIS_LOCATION() << std::endl;
m_elem = c;
it.overflow();
return c;
@@ -58,36 +68,60 @@
template <typename MapIter>
result_type operator()(MapIter& it)
{
+// std::cout << THIS_LOCATION() << std::endl;
it.underflow();
return m_elem;
}
};
+template <typename T>
+class o2m_tr_e : public mage::mapping_functor<T, mage::one2many_mapper_tag>
+{
+ T m_elem;
+
+public:
+ o2m_tr_e() : m_elem(0) {}
+ typedef T result_type;
+
+ template <typename MapIter>
+ result_type operator()(MapIter& it, result_type c)
+ {
+ m_elem = c;
+ it.overflow();
+ return c;
+ }
+ template <typename MapIter>
+ result_type operator()(MapIter& it)
+ {
+ it.underflow();
+ return m_elem;
+ }
+ bool operator==(const o2m_tr_e& other) const
+ {
+ return m_elem == other.m_elem;
+ }
+};
+
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: compare end() iterators");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "";
BOOST_CHECK(iter(a + strlen(a)) == iter(a + strlen(a)));
}
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
- BOOST_TEST_CHECKPOINT("o2m_tr: compare uninitialized iterators");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ BOOST_TEST_CHECKPOINT("o2m_tr_e: compare end() iterators");
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr_e<char> > iter;
const char* a = "";
- iter a1(a + strlen(a));
- iter a2(a + strlen(a));
- BOOST_CHECK(a1 == a2);
- BOOST_CHECK(a1 == a1);
- BOOST_CHECK(a1 == iter(a + strlen(a)));
- BOOST_CHECK(a2 == iter(a + strlen(a)));
+ BOOST_CHECK(iter(a + strlen(a)) == iter(a + strlen(a)));
}
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: copy uninitialized iterators");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "";
iter a1(a + strlen(a));
iter a2 = a1;
@@ -103,9 +137,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: no step to the end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin == end);
}
@@ -113,9 +147,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: step, step --> end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "a";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin != end);
++begin;
@@ -127,9 +161,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: deref, step, deref, step --> end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "a";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin != end);
BOOST_CHECK_EQUAL(*begin, 'a');
@@ -143,10 +177,10 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: compare initialized iterators");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "a";
- iter a1(a, a + strlen(a));
- iter a2(a, a + strlen(a));
+ iter a1(a, o2m_tr<char>());
+ iter a2(a, o2m_tr<char>());
BOOST_CHECK(a1 == a2);
BOOST_CHECK_EQUAL(*a1, 'a');
BOOST_CHECK_EQUAL(*a2, 'a');
@@ -185,9 +219,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: deref, step, step --> end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "a";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin != end);
BOOST_CHECK_EQUAL(*begin, 'a');
@@ -200,9 +234,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: step, deref, step --> end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "a";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin != end);
++begin;
@@ -215,9 +249,9 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: deref, step, deref, step, deref, step, deref, step --> end");
- typedef mage::mapping_iterator<const char*, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<const char*, o2m_tr<char> > iter;
const char* a = "ab";
- iter begin(a, a + strlen(a));
+ iter begin(a, o2m_tr<char>());
iter end(a + strlen(a));
BOOST_CHECK(begin != end);
BOOST_CHECK_EQUAL(*begin, 'a');
@@ -237,10 +271,10 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: make a string from 2 iterators #1");
- typedef mage::mapping_iterator<string::const_iterator, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<string::const_iterator, o2m_tr<char> > iter;
const string a = "Hello Africa!";
const string aa = "HHeelllloo AAffrriiccaa!!";
- iter begin(a.begin(), a.end());
+ iter begin(a.begin(), o2m_tr<char>());
iter end(a.end());
string hello(begin, end);
BOOST_CHECK_EQUAL(hello, aa);
@@ -249,10 +283,10 @@
MAGE_AUTO_TEST_CASE(mapping_iterator_o2m_test)
{
BOOST_TEST_CHECKPOINT("o2m_tr: make a string from 2 iterators #1");
- typedef mage::mapping_iterator<string::iterator, o2m_tr<char> > iter;
+ typedef mage::mapping_iterator_o2m<string::iterator, o2m_tr<char> > iter;
string a = "Hello Africa!";
const string aa = "HHeelllloo AAffrriiccaa!!";
- iter begin(a.begin(), a.end());
+ iter begin(a.begin(), o2m_tr<char>());
iter end(a.end());
string hello(begin, end);
BOOST_CHECK_EQUAL(hello, aa);
Modified: libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc 2008-10-04 02:16:29 UTC (rev 495)
+++ libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc 2008-10-06 11:42:44 UTC (rev 496)
@@ -49,8 +49,6 @@
MAGE_AUTO_TEST_CASE(transform_width_test)
{
- BOOST_TEST_MESSAGE( "Testing initialization :" );
-
typedef mapping_iterator<
string::const_iterator
, details::bits_shrink_transform<8, 4, char, int>
@@ -61,4 +59,23 @@
copy(iter(s.begin(), s.end()), iter(s.end()), back_inserter(result));
BOOST_CHECK_EQUAL(result, etalon);
}
+
+MAGE_AUTO_TEST_CASE(transform_width_test)
+{
+ typedef mapping_iterator<
+ string::const_iterator
+ , details::bits_shrink_transform<8, 6, char, int>
+ > iter;
+ // source string:
+ // 10101010 01010101 11001100 01100110 11111111 10011001
+ //
+ // expected ints are:
+ // 101010 100101 010111 001100 011001 101111 111110 011001
+ string s = "\xAA\x55\xCC\x66\xFF\x99";
+ vector<int> result;
+ const vector<int> etalon = boost::assign::list_of(42)(37)(23)(12)(25)(47)(62)(25);
+ copy(iter(s.begin(), s.end()), iter(s.end()), back_inserter(result));
+ BOOST_CHECK_EQUAL(result, etalon);
+}
+
// copy(iter(s.begin(), s.end()), iter(s.end()), ostream_iterator<int>(cout, " "));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|