|
From: <za...@us...> - 2008-10-01 05:07:53
|
Revision: 492
http://libmage.svn.sourceforge.net/libmage/?rev=492&view=rev
Author: zaufi
Date: 2008-10-01 05:07:47 +0000 (Wed, 01 Oct 2008)
Log Message:
-----------
add one more tester
Modified Paths:
--------------
libMAGE/branches/version-0-1/libmage/type_traits/tests/Makefile.am
Added Paths:
-----------
libMAGE/branches/version-0-1/libmage/type_traits/is_boost_mpl_integral.hh
libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc
Added: libMAGE/branches/version-0-1/libmage/type_traits/is_boost_mpl_integral.hh
===================================================================
--- libMAGE/branches/version-0-1/libmage/type_traits/is_boost_mpl_integral.hh (rev 0)
+++ libMAGE/branches/version-0-1/libmage/type_traits/is_boost_mpl_integral.hh 2008-10-01 05:07:47 UTC (rev 492)
@@ -0,0 +1,78 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class is_boost_mpl_integral (interface)
+ *
+ * \date Wed Oct 1 07:44:49 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__TYPE_TRAITS__IS_BOOST_MPL_INTEGRAL_HH__
+# define __LIBMAGE__TYPE_TRAITS__IS_BOOST_MPL_INTEGRAL_HH__
+
+// Project specific includes
+# include <libmage-config.h>
+
+// Standard includes
+# include <boost/mpl/and.hpp>
+# include <boost/mpl/eval_if.hpp>
+# include <boost/mpl/has_xxx.hpp>
+# include <boost/mpl/integral_c_tag.hpp>
+# include <boost/type_traits/is_integral.hpp>
+# include <boost/type_traits/is_same.hpp>
+
+namespace mage { namespace details {
+
+BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_value_type, value_type, false)
+/// \note Unfortunately \c has_tag metafunction is not for public usage nowadays
+/// so it is better to define (copy-n-paste) it here again than include internal header
+BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_tag, tag, false)
+
+/// Lazy instantiation helper
+template <typename T>
+struct test_tag_and_value_type
+ : public boost::mpl::and_<
+ boost::is_same<typename T::tag, boost::mpl::integral_c_tag>
+ , boost::is_integral<typename T::value_type>
+ >
+{
+};
+
+}
+
+/**
+ * \brief Metafunction to check if given type is one of MPL's integral type
+ */
+template <typename T>
+struct is_boost_mpl_integral
+ : public boost::mpl::eval_if<
+ boost::mpl::and_<
+ details::has_tag<T>
+ , details::has_value_type<T>
+ >
+ , details::test_tag_and_value_type<T>
+ , boost::mpl::false_
+ >::type
+{
+};
+
+} // namespace mage
+#endif // __LIBMAGE__TYPE_TRAITS__IS_BOOST_MPL_INTEGRAL_HH__
Property changes on: libMAGE/branches/version-0-1/libmage/type_traits/is_boost_mpl_integral.hh
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
Modified: libMAGE/branches/version-0-1/libmage/type_traits/tests/Makefile.am
===================================================================
--- libMAGE/branches/version-0-1/libmage/type_traits/tests/Makefile.am 2008-09-30 14:46:01 UTC (rev 491)
+++ libMAGE/branches/version-0-1/libmage/type_traits/tests/Makefile.am 2008-10-01 05:07:47 UTC (rev 492)
@@ -10,7 +10,8 @@
is_consistent_const_tester.cc \
is_equal_comparable_tester.cc \
is_std_pair_tester.cc \
- is_std_basic_string_tester.cc
+ is_std_basic_string_tester.cc \
+ is_boost_mpl_integral_tester.cc
unit_tests_LDFLAGS = -no-install
unit_tests_LDADD = -lboost_unit_test_framework$(BOOST_LIB_SUFFIX)
Added: 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 (rev 0)
+++ libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc 2008-10-01 05:07:47 UTC (rev 492)
@@ -0,0 +1,90 @@
+/**
+ * \file
+ * $Id$
+ *
+ * \author See AUTHORS file from $(top_srcdir)
+ *
+ * \brief Class tester for is_boost_mpl_integral
+ *
+ * \date Wed Oct 1 08:00:45 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>
+#include <libmage/type_traits/is_boost_mpl_integral.hh>
+// #define BOOST_AUTO_TEST_MAIN
+// #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 <boost/mpl/int.hpp>
+#include <iostream>
+#include <list>
+
+using namespace std;
+using namespace mage;
+
+struct empty_test {};
+struct test_with_some_tag
+{
+ typedef int tag;
+};
+struct test_with_correct_tag
+{
+ typedef boost::mpl::integral_c_tag tag;
+};
+struct test_with_correct_tag_and_value_type
+{
+ typedef boost::mpl::integral_c_tag tag;
+ typedef int value_type;
+};
+
+MAGE_AUTO_TEST_CASE(is_boost_mpl_integral_test)
+{
+ 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);
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<test_with_correct_tag>::value, false);
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<std::list<int> >::value, false);
+}
+
+MAGE_AUTO_TEST_CASE(is_boost_mpl_integral_test)
+{
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<test_with_correct_tag_and_value_type>::value, true);
+}
+
+MAGE_AUTO_TEST_CASE(is_boost_mpl_integral_test)
+{
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<boost::mpl::true_>::value, true);
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<boost::mpl::bool_<false> >::value, true);
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<boost::mpl::int_<10> >::value, true);
+ BOOST_CHECK_EQUAL(is_boost_mpl_integral<boost::mpl::long_<10> >::value, true);
+}
+
+MAGE_AUTO_TEST_CASE(is_boost_mpl_integral_test)
+{
+ BOOST_CHECK_EQUAL((is_boost_mpl_integral<boost::mpl::integral_c<bool, false> >::value), true);
+ BOOST_CHECK_EQUAL((is_boost_mpl_integral<boost::mpl::integral_c<int, 123> >::value), true);
+}
Property changes on: libMAGE/branches/version-0-1/libmage/type_traits/tests/is_boost_mpl_integral_tester.cc
___________________________________________________________________
Added: svn:keywords
+ Id HeadURL Revision Date Author
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|