Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
strong_type.h
1 /*
2  * StrongType class
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2006-19, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_UTIL_STRONG_TYPE_H
22 #define ELM_UTIL_STRONG_TYPE_H
23 
24 // SolidType class
25 template <class T>
26 class SolidType {
27 public:
28  inline explicit SolidType(T v = 0): _v(v) { }
29  inline T operator*(void) const { return _v; }
30  inline T& operator*(void) { return _v; }
31 private:
32  T _v;
33 };
34 
35 
36 // OTAWA_STRONG_TYPE macro
37 #define OTAWA_STRONG_TYPE(N, T) \
38  typedef struct N { \
39  typedef T _t; \
40  _t v; \
41  inline N(_t _v = 0): v(_v) { }; \
42  inline operator const _t&(void) const { return v; } \
43  inline operator _t&(void) { return v; } \
44  inline struct N& operator=(const _t& _v) { v = _v; return *this; } \
45  inline const _t& operator*(void) const { return v; } \
46  inline _t& operator*(void) { return v; } \
47  } N
48 
49 // Shortcut
50 #ifndef OTAWA_NO_SHORTCUT
51 # define STRONG_TYPE(N, T) OTAWA_STRONG_TYPE(N, T)
52 #endif
53 
54 #endif // ELM_UTIL_STRONG_TYPE_H
55 
SolidType::operator*
T & operator*(void)
Definition: strong_type.h:30
SolidType::SolidType
SolidType(T v=0)
Definition: strong_type.h:28
SolidType
Definition: strong_type.h:26
SolidType::operator*
T operator*(void) const
Definition: strong_type.h:29