Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flags.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2008-04-07
7 
8  Copyright (C) 2008, 2009 Universite de Grenoble 1
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __Flags_H
30 #define __Flags_H 1
31 
32 namespace Feel
33 {
35 namespace detail
36 {
37 
38 class Flag
39 {
40  int i;
41 public:
42  inline Flag( int i );
43  inline operator int() const
44  {
45  return i;
46  }
47 };
48 
49 inline Flag::Flag( int ai ) : i( ai ) {}
50 
51 
52 template<typename Enum>
53 class Flags
54 {
55  typedef void **Zero;
56  int i;
57 public:
58  typedef Enum enum_type;
59 
60  inline Flags( const Flags &f ) : i( f.i ) {}
61  inline Flags( Enum f ) : i( f ) {}
62  inline Flags( Zero = 0 ) : i( 0 ) {}
63  inline Flags( Flag f ) : i( f ) {}
64 
65  inline Flags &operator=( const Flags &f )
66  {
67  i = f.i;
68  return *this;
69  }
70  inline Flags &operator&=( int mask )
71  {
72  i &= mask;
73  return *this;
74  }
75  inline Flags &operator&=( unsigned int mask )
76  {
77  i &= mask;
78  return *this;
79  }
80  inline Flags &operator|=( Flags f )
81  {
82  i |= f.i;
83  return *this;
84  }
85  inline Flags &operator|=( Enum f )
86  {
87  i |= f;
88  return *this;
89  }
90  inline Flags &operator^=( Flags f )
91  {
92  i ^= f.i;
93  return *this;
94  }
95  inline Flags &operator^=( Enum f )
96  {
97  i ^= f;
98  return *this;
99  }
100 
101  inline operator int() const
102  {
103  return i;
104  }
105 
106  inline Flags operator|( Flags f ) const
107  {
108  Flags g;
109  g.i = i | f.i;
110  return g;
111  }
112  inline Flags operator|( Enum f ) const
113  {
114  Flags g;
115  g.i = i | f;
116  return g;
117  }
118  inline Flags operator^( Flags f ) const
119  {
120  Flags g;
121  g.i = i ^ f.i;
122  return g;
123  }
124  inline Flags operator^( Enum f ) const
125  {
126  Flags g;
127  g.i = i ^ f;
128  return g;
129  }
130  inline Flags operator&( int mask ) const
131  {
132  Flags g;
133  g.i = i & mask;
134  return g;
135  }
136  inline Flags operator&( unsigned int mask ) const
137  {
138  Flags g;
139  g.i = i & mask;
140  return g;
141  }
142  inline Flags operator&( Enum f ) const
143  {
144  Flags g;
145  g.i = i & f;
146  return g;
147  }
148  inline Flags operator~() const
149  {
150  Flags g;
151  g.i = ~i;
152  return g;
153  }
154 
155  inline bool operator!() const
156  {
157  return !i;
158  }
159 
160  inline bool testFlag( Enum f ) const
161  {
162  return i & f;
163  }
164 
165 };
166 
167 } // detail
169 
170 
171 #define FEELPP_DECLARE_FLAGS(Flags, Enum) \
172  typedef detail::Flags<Enum> Flags;
173 
174 } // Feel
175 #endif /* __Flags_H */
Elements & operator=(Elements const &e)
Definition: elements.hpp:335

Generated on Sun Dec 22 2013 13:11:00 for Feel++ by doxygen 1.8.5