1 | #ifndef BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP |
2 | #define BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP |
3 | |
4 | // MS compatible compilers support #pragma once |
5 | #if defined(_MSC_VER) |
6 | # pragma once |
7 | #endif |
8 | |
9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
10 | // strong_typedef.hpp: |
11 | |
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
13 | // Use, modification and distribution is subject to the Boost Software |
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
15 | // http://www.boost.org/LICENSE_1_0.txt) |
16 | |
17 | // See http://www.boost.org/libs/serialization for updates, documentation, and revision history. |
18 | |
19 | // macro used to implement a strong typedef. strong typedef |
20 | // guarentees that two types are distinguised even though the |
21 | // share the same underlying implementation. typedef does not create |
22 | // a new type. BOOST_STRONG_TYPEDEF(T, D) creates a new type named D |
23 | // that operates as a type T. |
24 | |
25 | #include <boost/config.hpp> |
26 | #include <boost/operators.hpp> |
27 | |
28 | #define BOOST_STRONG_TYPEDEF(T, D) \ |
29 | struct D \ |
30 | : boost::totally_ordered1< D \ |
31 | , boost::totally_ordered2< D, T \ |
32 | > > \ |
33 | { \ |
34 | T t; \ |
35 | explicit D(const T t_) : t(t_) {}; \ |
36 | D(): t() {}; \ |
37 | D(const D & t_) : t(t_.t){} \ |
38 | D & operator=(const D & rhs) { t = rhs.t; return *this;} \ |
39 | D & operator=(const T & rhs) { t = rhs; return *this;} \ |
40 | operator const T & () const {return t; } \ |
41 | operator T & () { return t; } \ |
42 | bool operator==(const D & rhs) const { return t == rhs.t; } \ |
43 | bool operator<(const D & rhs) const { return t < rhs.t; } \ |
44 | }; |
45 | |
46 | #endif // BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP |
47 | |