Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69482 - in sandbox/enums/libs/enums/test: . enum_range enum_set
From: vicente.botet_at_[hidden]
Date: 2011-03-02 11:31:35


Author: viboes
Date: 2011-03-02 11:31:33 EST (Wed, 02 Mar 2011)
New Revision: 69482
URL: http://svn.boost.org/trac/boost/changeset/69482

Log:
Enums: Add some helpers
Added:
   sandbox/enums/libs/enums/test/Ex.hpp (contents, props changed)
   sandbox/enums/libs/enums/test/enum_range/
   sandbox/enums/libs/enums/test/enum_set/

Added: sandbox/enums/libs/enums/test/Ex.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/test/Ex.hpp 2011-03-02 11:31:33 EST (Wed, 02 Mar 2011)
@@ -0,0 +1,98 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/enums for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef EX_HPP
+#define EX_HPP
+
+
+#include <boost/enums/emulation.hpp>
+#include <boost/enums/size.hpp>
+#include <boost/enums/pos.hpp>
+#include <boost/enums/val.hpp>
+#include <boost/enums/enum_traits.hpp>
+#include <boost/enums/enum_traiter.hpp>
+
+ BOOST_ENUM_CLASS_START(EC3, int) {
+ Enum0,
+ Enum1,
+ Enum2
+ } BOOST_ENUM_CLASS_CONS_END(EC3, int)
+
+namespace boost {
+ namespace enums {
+ namespace meta {
+
+ template <>
+ struct size<EC3>
+ {
+ static const int value = 3;
+ };
+ template <>
+ struct pos<EC3, EC3::Enum0>
+ {
+ static const int value = 0;
+ };
+ template <>
+ struct pos<EC3, EC3::Enum1>
+ {
+ static const int value = 1;
+ };
+ template <>
+ struct pos<EC3, EC3::Enum2>
+ {
+ static const int value = 2;
+ };
+
+ template <>
+ struct val<EC3, 0>
+ {
+ static const boost::enums::enum_type<EC3>::type value = EC3::Enum0;
+ };
+ template <>
+ struct val<EC3, 1>
+ {
+ static const boost::enums::enum_type<EC3>::type value = EC3::Enum1;
+ };
+ template <>
+ struct val<EC3, 2>
+ {
+ static const boost::enums::enum_type<EC3>::type value = EC3::Enum2;
+ };
+ } // namespace meta
+ template <>
+ struct enum_traits<EC3> : enum_traiter<EC3>
+ {
+ static int pos(EC3 e)
+ {
+ switch (boost::enums::get_value(e))
+ {
+ case EC3::Enum0: return 0;
+ case EC3::Enum1: return 1;
+ case EC3::Enum2: return 2;
+ default: return -1;
+ }
+ }
+ static EC3 val(int p)
+ {
+ switch (p)
+ {
+ case 0: return boost::convert_to<EC3>(EC3::Enum0);
+ case 1: return boost::convert_to<EC3>(EC3::Enum1);
+ case 2: return boost::convert_to<EC3>(EC3::Enum2);
+ default: throw "bad_parameter";
+ }
+ }
+ };
+ }
+}
+
+#endif


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