gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flags.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Nathan Binkert
29  */
30 
31 #ifndef __BASE_FLAGS_HH__
32 #define __BASE_FLAGS_HH__
33 
34 template <typename T>
35 class Flags
36 {
37  private:
38  T _flags;
39 
40  public:
41  typedef T Type;
42  Flags() : _flags(0) {}
43  Flags(Type flags) : _flags(flags) {}
44 
45  operator const Type() const { return _flags; }
46 
47  template <typename U>
48  const Flags<T> &
49  operator=(const Flags<U> &flags)
50  {
51  _flags = flags._flags;
52  return *this;
53  }
54 
55  const Flags<T> &
56  operator=(T flags)
57  {
58  _flags = flags;
59  return *this;
60  }
61 
62  bool isSet() const { return _flags; }
63  bool isSet(Type flags) const { return (_flags & flags); }
64  bool allSet() const { return !(~_flags); }
65  bool allSet(Type flags) const { return (_flags & flags) == flags; }
66  bool noneSet() const { return _flags == 0; }
67  bool noneSet(Type flags) const { return (_flags & flags) == 0; }
68  void clear() { _flags = 0; }
69  void clear(Type flags) { _flags &= ~flags; }
70  void set(Type flags) { _flags |= flags; }
71  void set(Type f, bool val) { _flags = (_flags & ~f) | (val ? f : 0); }
72  void
73  update(Type flags, Type mask)
74  {
75  _flags = (_flags & ~mask) | (flags & mask);
76  }
77 };
78 
79 #endif // __BASE_FLAGS_HH__
const Flags< FlagsType > & operator=(FlagsTypeflags)
Definition: flags.hh:56
FlagsType Type
Definition: flags.hh:41
void clear()
Definition: flags.hh:68
bool isSet() const
Definition: flags.hh:62
bool allSet(Type flags) const
Definition: flags.hh:65
Bitfield< 63 > val
Definition: misc.hh:770
bool isSet(Type flags) const
Definition: flags.hh:63
Bitfield< 6 > f
Definition: miscregs.hh:1379
Flags(Type flags)
Definition: flags.hh:43
bool noneSet(Type flags) const
Definition: flags.hh:67
Definition: flags.hh:35
bool allSet() const
Definition: flags.hh:64
void clear(Type flags)
Definition: flags.hh:69
bool noneSet() const
Definition: flags.hh:66
void set(Type f, bool val)
Definition: flags.hh:71
Bitfield< 3, 0 > mask
Definition: types.hh:64
void update(Type flags, Type mask)
Definition: flags.hh:73
void set(Type flags)
Definition: flags.hh:70
const Flags< FlagsType > & operator=(const Flags< U > &flags)
Definition: flags.hh:49
FlagsType _flags
Definition: flags.hh:38

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6