|
From: <za...@us...> - 2008-10-02 18:43:26
|
Revision: 493
http://libmage.svn.sourceforge.net/libmage/?rev=493&view=rev
Author: zaufi
Date: 2008-10-02 18:43:11 +0000 (Thu, 02 Oct 2008)
Log Message:
-----------
save
Modified Paths:
--------------
libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am
libMAGE/branches/version-0-1/libmage/iterator/xml_escape.hh
libMAGE/branches/version-0-1/libmage/mpl/details/lcm_impl.hh
libMAGE/branches/version-0-1/libmage/mpl/integer_factorization.hh
libMAGE/branches/version-0-1/libmage/mpl/pow.hh
libMAGE/branches/version-0-1/libmage/mpl/tests/bits2bytes_tester.cc
libMAGE/branches/version-0-1/libmage/mpl/tests/integer_factorization_tester.cc
libMAGE/branches/version-0-1/libmage/shared/auto_test_case.hh
libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc
libMAGE/branches/version-0-1/support/class-tester.tpl
Added Paths:
-----------
libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh
libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc
libMAGE/branches/version-0-1/libmage/iterator/transform_width.hh
Added: libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh (rev 0)
+++ libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -0,0 +1,141 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class bits_shrink_transform (interface)
+ *
+ * \date Sat Sep 20 20:21:35 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__BITS_SHRINK_TRANSFORM_HH__
+# define __LIBMAGE__ITERATOR__DETAILS__BITS_SHRINK_TRANSFORM_HH__
+
+// Project specific includes
+# include <libmage-config.h>
+# include <libmage/iterator/mapping_functor.hh>
+# include <libmage/mpl/bits2bytes.hh>
+
+// Standard includes
+# include <boost/integer.hpp>
+# include <boost/mpl/assert.hpp>
+# include <boost/mpl/divides.hpp>
+# include <boost/mpl/integral_c.hpp>
+# include <boost/mpl/less_equal.hpp>
+# include <boost/mpl/sizeof.hpp>
+# include <boost/type_traits/is_integral.hpp>
+# include <boost/type_traits/make_unsigned.hpp>
+# include <cassert>
+# include <stdexcept>
+
+namespace mage { namespace details {
+
+/**
+ * \brief [Type brief class description here]
+ */
+template <
+ int BitsIn
+ , int BitsOut
+ , typename SrcType
+ , typename DstType
+ >
+class bits_shrink_transform : public mapping_functor<DstType, many2many_mapper_tag>
+{
+ BOOST_MPL_ASSERT((boost::is_integral<SrcType>)); // check that SrcType is integral type
+ BOOST_MPL_ASSERT((boost::is_integral<DstType>)); // check that DstType is integral type
+ BOOST_MPL_ASSERT((boost::mpl::bool_<(BitsIn > BitsOut)>));
+ // check that BitsIn/8 <= sizeof(SrcType) -- i.e. there is at least BitsIn bits in SrcType
+ BOOST_MPL_ASSERT((
+ boost::mpl::less_equal<
+ mpl::bits2bytes<boost::mpl::int_<BitsIn> >
+ , boost::mpl::sizeof_<SrcType>
+ >
+ ));
+ // check that BitsOut/8 <= sizeof(DstType) -- i.e. there is at least BitsOut bits in DstType
+ BOOST_MPL_ASSERT((
+ boost::mpl::less_equal<
+ mpl::bits2bytes<boost::mpl::int_<BitsOut> >
+ , boost::mpl::sizeof_<DstType>
+ >
+ ));
+
+ 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;
+
+ remainder_int m_bits_remain;
+ source_type m_current;
+
+ target_type select_bits(source_type t, remainder_int start_bit, remainder_int bits_count)
+ {
+ return (t >> start_bit) & ~(~SrcType(0) << bits_count);
+ }
+
+public:
+ typedef target_type result_type;
+
+ bits_shrink_transform() : m_bits_remain(0) {}
+
+ template <typename MapIter>
+ result_type operator()(MapIter& it, source_type c)
+ {
+ 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;
+ it.overflow();
+ return select_bits(m_current, m_bits_remain, BitsOut);
+ }
+ template <typename MapIter>
+ result_type operator()(MapIter& it)
+ {
+ assert("Sanity check" && (0 != m_bits_remain) && (BitsIn > m_bits_remain));
+ if (m_bits_remain > BitsOut) // Is there is more bits remains than needed?
+ {
+ // Yes. Just output another one element
+ return select_bits(m_current, m_bits_remain -= BitsOut, BitsOut);
+ }
+ else if (m_bits_remain == BitsOut) // Is last bunch of bits remain?
+ {
+ // Yes. Just output it and switch back to 'normal' mode
+ it.underflow();
+ 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
+ if (it.has_next())
+ {
+ source_type next = it.next();
+ std::swap(next, m_current);
+ remainder_int bits_remain = BitsOut - m_bits_remain;
+ assert("Reminder excpected to be less than BitsIn" && BitsIn > bits_remain);
+ std::swap(bits_remain, m_bits_remain);
+ 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;
+ return r;
+ }
+ throw std::runtime_error("Incomplete sequence of elements");
+ }
+};
+
+}} // namespace details, mage
+#endif // __LIBMAGE__ITERATOR__DETAILS__BITS_SHRINK_TRANSFORM_HH__
Property changes on: libMAGE/branches/version-0-1/libmage/iterator/details/bits_shrink_transform.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-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/iterator/tests/Makefile.am 2008-10-02 18:43:11 UTC (rev 493)
@@ -10,7 +10,8 @@
mapping_iterator_m2o_tester.cc \
mapping_iterator_m2m_tester.cc \
char2hex_hex2char_tester.cc \
- xml_escape_tester.cc
+ xml_escape_tester.cc \
+ transform_width_tester.cc
unit_tests_LDFLAGS = -no-install
unit_tests_LDADD = -lboost_unit_test_framework$(BOOST_LIB_SUFFIX)
Added: libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc (rev 0)
+++ libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc 2008-10-02 18:43:11 UTC (rev 493)
@@ -0,0 +1,64 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class tester for transform_width
+ *
+ * \date Sat Sep 20 20:27:35 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/>.
+ */
+
+// Project specific includes
+#include <libmage-config.h>
+// <for-debug-purposes-only>
+#include <libmage/debug/location.hh>
+#include <libmage/debug/out_any.hh>
+#include <libmage/debug/type_name.hh>
+#include <iostream>
+// </for-debug-purposes-only>
+#include <libmage/iterator/mapping_iterator.hh>
+#include <libmage/iterator/transform_width.hh>
+// #define BOOST_AUTO_TEST_MAIN
+// #define BOOST_TEST_DYN_LINK
+#include <libmage/shared/auto_test_case.hh>
+#include <libmage/debug/out_any.hh>
+
+// Standard includes
+#include <boost/assign.hpp>
+#include <iostream>
+
+using namespace std;
+using namespace mage;
+
+MAGE_TEST_MAKE_IT_STREAMABLE(std::vector<int>);
+
+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>
+ > iter;
+ string s = "\xAA\x55\xCC\x66"; // 1010 1010 0101 0101 1100 1100 0110 0110
+ vector<int> result;
+ const vector<int> etalon = boost::assign::list_of(10)(10)(5)(5)(12)(12)(6)(6);
+ 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, " "));
Property changes on: libMAGE/branches/version-0-1/libmage/iterator/tests/transform_width_tester.cc
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
Added: libMAGE/branches/version-0-1/libmage/iterator/transform_width.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/transform_width.hh (rev 0)
+++ libMAGE/branches/version-0-1/libmage/iterator/transform_width.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -0,0 +1,56 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class transform_width (interface)
+ *
+ * \date Sat Sep 20 19:21:28 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__TRANSFORM_WIDTH_HH__
+# define __LIBMAGE__ITERATOR__TRANSFORM_WIDTH_HH__
+
+// Project specific includes
+# include <libmage-config.h>
+# include <libmage/iterator/details/bits_shrink_transform.hh>
+
+// Standard includes
+
+namespace mage {
+
+/**
+ * \brief [Type brief class description here]
+ *
+ * [More detailed description here]
+ *
+ */
+template <
+ int SrcWidth
+ , int DstWidth
+ , typename SrcType
+ , typename DstType
+ >
+class transform_width : public details::bits_shrink_transform<SrcWidth, DstWidth, SrcType, DstType>
+{
+};
+
+} // namespace mage
+#endif // __LIBMAGE__ITERATOR__TRANSFORM_WIDTH_HH__
Property changes on: libMAGE/branches/version-0-1/libmage/iterator/transform_width.hh
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
Modified: libMAGE/branches/version-0-1/libmage/iterator/xml_escape.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/iterator/xml_escape.hh 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/iterator/xml_escape.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -69,7 +69,7 @@
return current;
}
/// It makes \c xml_escape equal comparable to take its state into account
- /// when mapping_iterators are compared.
+ /// when \c mapping_iterators are compared.
bool operator==(const xml_escape& other) const
{
return m_current == other.m_current;
Modified: libMAGE/branches/version-0-1/libmage/mpl/details/lcm_impl.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/mpl/details/lcm_impl.hh 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/mpl/details/lcm_impl.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -189,6 +189,9 @@
>
class lcm_impl
{
+ BOOST_MPL_ASSERT((is_boost_mpl_integral<N1>));
+ BOOST_MPL_ASSERT((is_boost_mpl_integral<N2>));
+
typedef typename integer_factorization<N1, Traits>::type n1_dvisors;
typedef typename integer_factorization<N2, Traits>::type n2_dvisors;
Modified: libMAGE/branches/version-0-1/libmage/mpl/integer_factorization.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/mpl/integer_factorization.hh 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/mpl/integer_factorization.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -31,8 +31,10 @@
// Project specific includes
# include <libmage-config.h>
# include <libmage/mpl/details/divisor_finder.hh>
+# include <libmage/type_traits/is_boost_mpl_integral.hh>
// Standard includes
+# include <boost/mpl/assert.hpp>
namespace mage { namespace mpl {
@@ -64,6 +66,7 @@
>
struct integer_factorization
{
+ BOOST_MPL_ASSERT((is_boost_mpl_integral<N>));
typedef typename details::divisor_collector<
N
, Traits<typename N::value_type>
Modified: libMAGE/branches/version-0-1/libmage/mpl/pow.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/mpl/pow.hh 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/mpl/pow.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -30,16 +30,15 @@
// Project specific includes
# include <libmage-config.h>
+# include <libmage/type_traits/is_boost_mpl_integral.hh>
// Standard includes
# include <boost/mpl/assert.hpp>
-# include <boost/mpl/integral_c.hpp>
-# include <boost/mpl/int.hpp>
-# include <boost/mpl/multiplies.hpp>
# include <boost/mpl/equal_to.hpp>
# include <boost/mpl/eval_if.hpp>
+# include <boost/mpl/integral_c.hpp>
+# include <boost/mpl/multiplies.hpp>
# include <boost/mpl/prior.hpp>
-# include <boost/type_traits/is_integral.hpp>
namespace mage { namespace mpl {
@@ -57,8 +56,8 @@
, boost::mpl::multiplies<N, pow<N, typename boost::mpl::prior<M>::type> >
>::type
{
- BOOST_MPL_ASSERT((boost::is_integral<typename N::value_type>));
- BOOST_MPL_ASSERT((boost::is_integral<typename M::value_type>));
+ BOOST_MPL_ASSERT((is_boost_mpl_integral<N>));
+ BOOST_MPL_ASSERT((is_boost_mpl_integral<M>));
};
}} // namespace mpl, mage
Modified: libMAGE/branches/version-0-1/libmage/mpl/tests/bits2bytes_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/mpl/tests/bits2bytes_tester.cc 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/mpl/tests/bits2bytes_tester.cc 2008-10-02 18:43:11 UTC (rev 493)
@@ -29,6 +29,8 @@
// #define BOOST_AUTO_TEST_MAIN
// #define BOOST_TEST_DYN_LINK
#include <libmage/shared/auto_test_case.hh>
+#include <libmage/debug/out_any.hh>
+#include <libmage/debug/type_name.hh>
// Standard includes
#include <iostream>
Modified: libMAGE/branches/version-0-1/libmage/mpl/tests/integer_factorization_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/mpl/tests/integer_factorization_tester.cc 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/mpl/tests/integer_factorization_tester.cc 2008-10-02 18:43:11 UTC (rev 493)
@@ -38,7 +38,7 @@
using namespace boost;
using namespace boost::mpl;
-using namespace mage;
+//using namespace mage;
using namespace mage::mpl;
using namespace std;
Modified: libMAGE/branches/version-0-1/libmage/shared/auto_test_case.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/shared/auto_test_case.hh 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/shared/auto_test_case.hh 2008-10-02 18:43:11 UTC (rev 493)
@@ -12,12 +12,12 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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 libMAGE. If not, write to:
* The Free Software Foundation, Inc.,
@@ -31,6 +31,7 @@
// Project specific includes
# include <libmage-config.h>
+# include <libmage/debug/out_any.hh>
// Standard includes
# include <boost/preprocessor/cat.hpp>
@@ -40,4 +41,21 @@
# define MAGE_AUTO_TEST_CASE(Name) \
BOOST_AUTO_TEST_CASE(BOOST_PP_CAT(BOOST_PP_CAT(Name,_),__LINE__))
+/**
+ * Helper macro to create an \c oeprator<< for given type
+ * We have a flexible debugging output system, so why not to use it for testing purposes too,
+ * instead of \c BOOST_TEST_DONT_PRINT_LOG_VALUE macro to suppress any output :)
+ */
+# define MAGE_TEST_MAKE_IT_STREAMABLE(Type) \
+namespace boost { namespace test_tools { namespace tt_detail { \
+template<> \
+struct print_log_value<Type> \
+{ \
+ void operator()(std::ostream& os, const Type& t) \
+ { \
+ os << mage::debug::out_any(t); \
+ } \
+}; \
+}}}
+
#endif // __LIBMAGE__SHARED__AUTO_TEST_CASE_HH__
Modified: libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc
===================================================================
--- libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc 2008-10-02 18:43:11 UTC (rev 493)
@@ -63,6 +63,7 @@
MAGE_AUTO_TEST_CASE(is_boost_mpl_integral_test)
{
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<void>::value, false);
BOOST_CHECK_EQUAL(is_boost_mpl_integral<int>::value, false);
BOOST_CHECK_EQUAL(is_boost_mpl_integral<empty_test>::value, false);
BOOST_CHECK_EQUAL(is_boost_mpl_integral<test_with_some_tag>::value, false);
Modified: libMAGE/branches/version-0-1/support/class-tester.tpl
===================================================================
--- libMAGE/branches/version-0-1/support/class-tester.tpl 2008-10-01 05:07:47 UTC (rev 492)
+++ libMAGE/branches/version-0-1/support/class-tester.tpl 2008-10-02 18:43:11 UTC (rev 493)
@@ -25,9 +25,21 @@
[+IF ( == (get "add_main") "no") +]// [+ ENDIF +]#define BOOST_AUTO_TEST_MAIN
[+IF ( == (get "add_main") "no") +]// [+ ENDIF +]#define BOOST_TEST_DYN_LINK
#include <libmage/shared/auto_test_case.hh>
+// <debug>
+// Helpful debug stuff here. Uncomment files that u need.
+// #include <libmage/debug/backtrace.hh>
+// #include <libmage/debug/dump_memory.hh>
+// #include <libmage/debug/location.hh>
+// #include <libmage/debug/out_any.hh>
+// #include <libmage/debug/type_name.hh>
+// </debug>
// Standard includes
+#include <iostream>
+using namespace std;
+using namespace mage;
+
// Your first test function :)
MAGE_AUTO_TEST_CASE([+ classname +]_test)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|