L4Re - L4 Runtime Environment
types
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
2 /*
3  * (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com>
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction. Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License. This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18 
20 
21 #pragma once
22 
23 // very simple type traits for basic L4 functions, for a more complete set
24 // use <l4/cxx/type_traits> or the standard <type_traits>.
25 
26 namespace L4 {
27 
31 namespace Types {
32 
62  template<typename BITS_ENUM, typename UNDERLYING = unsigned long>
63  class Flags
64  {
65  public:
67  typedef UNDERLYING value_type;
69  typedef BITS_ENUM bits_enum_type;
72 
73  private:
74  struct Private_bool;
75  value_type _v;
76  explicit Flags(value_type v) : _v(v) {}
77 
78  public:
80  enum None_type { None };
81 
90  Flags(None_type) : _v(0) {}
91 
93  Flags() : _v(0) {}
94 
103  Flags(BITS_ENUM e) : _v(((value_type)1) << e) {}
104 
110  static type from_raw(value_type v) { return type(v); }
111 
113  operator Private_bool * () const
114  { return _v != 0 ? (Private_bool *)1 : 0; }
115 
117  bool operator ! () const { return _v == 0; }
118 
120  friend type operator | (type lhs, type rhs)
121  { return type(lhs._v | rhs._v); }
122 
124  friend type operator | (type lhs, bits_enum_type rhs)
125  { return lhs | type(rhs); }
126 
128  friend type operator & (type lhs, type rhs)
129  { return type(lhs._v & rhs._v); }
130 
132  friend type operator & (type lhs, bits_enum_type rhs)
133  { return lhs & type(rhs); }
134 
136  type &operator |= (type rhs) { _v |= rhs._v; return *this; }
138  type &operator |= (bits_enum_type rhs) { return operator |= (type(rhs)); }
139 
141  type &operator &= (type rhs) { _v &= rhs._v; return *this; }
143  type &operator &= (bits_enum_type rhs) { return operator &= (type(rhs)); }
144 
146  type operator ~ () const { return type(~_v); }
147 
154  type &clear(bits_enum_type flag) { return operator &= (~type(flag)); }
155 
157  value_type as_value() const { return _v; }
158  };
159 
165  template< bool V > struct Bool
166  {
167  typedef Bool<V> type;
168  enum { value = V };
169  };
170 
173  struct False : Bool<false> {};
174 
177  struct True : Bool<true> {};
178 
179  /*********************/
188  template<typename A, typename B>
189  struct Same : False {};
190 
191  template<typename A>
192  struct Same<A, A> : True {};
193 
194  template<bool EXP, typename T = void> struct Enable_if {};
195  template<typename T> struct Enable_if<true, T> { typedef T type; };
196 
197  template<typename T1, typename T2, typename T = void>
198  struct Enable_if_same : Enable_if<Same<T1, T2>::value, T> {};
199 
200  template<typename T> struct Remove_const { typedef T type; };
201  template<typename T> struct Remove_const<T const> { typedef T type; };
202  template<typename T> struct Remove_volatile { typedef T type; };
203  template<typename T> struct Remove_volatile<T volatile> { typedef T type; };
204  template<typename T> struct Remove_cv
205  { typedef typename Remove_const<typename Remove_volatile<T>::type>::type type; };
206 
207  template<typename T> struct Remove_pointer { typedef T type; };
208  template<typename T> struct Remove_pointer<T*> { typedef T type; };
209  template<typename T> struct Remove_reference { typedef T type; };
210  template<typename T> struct Remove_reference<T&> { typedef T type; };
211  template<typename T> struct Remove_pr { typedef T type; };
212  template<typename T> struct Remove_pr<T&> { typedef T type; };
213  template<typename T> struct Remove_pr<T*> { typedef T type; };
214 } // Types
215 } // L4
Compare two data types for equality.
Definition: types:189
value_type as_value() const
Get the underlying value.
Definition: types:157
Template for defining typical Flags bitmaps.
Definition: types:63
None_type
The none type to get an empty bitmap.
Definition: types:80
L4 low-level kernel interface.
Flags< BITS_ENUM, UNDERLYING > type
the Flags<> type itself
Definition: types:71
UNDERLYING value_type
type of the underlying value
Definition: types:67
Flags(BITS_ENUM e)
Make flags from bit name.
Definition: types:103
type & clear(bits_enum_type flag)
Clear the given flag.
Definition: types:154
friend type operator&(type lhs, type rhs)
Support & of two compatible Flags types.
Definition: types:128
Flags()
Make default Flags.
Definition: types:93
Bool< V > type
The meta type itself.
Definition: types:167
BITS_ENUM bits_enum_type
enum type defining a name for each bit
Definition: types:69
Use this to get an empty bitmap.
Definition: types:80
type operator~() const
Support ~ for Flags types.
Definition: types:146
Flags(None_type)
Make an empty bitmap.
Definition: types:90
True meta value.
Definition: types:177
Boolean meta type.
Definition: types:165
type & operator&=(type rhs)
Support &= of two compatible Flags types.
Definition: types:141
static type from_raw(value_type v)
Make flags from a raw value of value_type.
Definition: types:110
friend type operator|(type lhs, type rhs)
Support | of two compatible Flags types.
Definition: types:120
bool operator!() const
Support for if (!flags) syntax (test for empty flags).
Definition: types:117
type & operator|=(type rhs)
Support |= of two compatible Flags types.
Definition: types:136
False meta value.
Definition: types:173