gem5  v20.1.0.0
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 
29 #ifndef __BASE_FLAGS_HH__
30 #define __BASE_FLAGS_HH__
31 
32 template <typename T>
33 class Flags
34 {
35  private:
36  T _flags;
37 
38  public:
39  typedef T Type;
40 
45  Flags() : _flags(0) {}
46  Flags(Type flags) : _flags(flags) {} // end of api_flags
48 
52  operator const Type() const { return _flags; }
53 
57  template <typename U>
58  const Flags<T> &
59  operator=(const Flags<U> &flags)
60  {
61  _flags = flags._flags;
62  return *this;
63  }
64 
68  const Flags<T> &
69  operator=(T flags)
70  {
71  _flags = flags;
72  return *this;
73  }
74 
79  bool isSet() const { return _flags; }
80  bool isSet(Type flags) const { return (_flags & flags); }
81  bool allSet() const { return !(~_flags); }
82  bool allSet(Type flags) const { return (_flags & flags) == flags; }
83  bool noneSet() const { return _flags == 0; }
84  bool noneSet(Type flags) const { return (_flags & flags) == 0; }
85  void clear() { _flags = 0; }
86  void clear(Type flags) { _flags &= ~flags; }
87  void set(Type flags) { _flags |= flags; }
88  void set(Type f, bool val) { _flags = (_flags & ~f) | (val ? f : 0); }
89  void
90  update(Type flags, Type mask)
91  {
92  _flags = (_flags & ~mask) | (flags & mask);
93  } // end of api_flags
95 };
96 
97 #endif // __BASE_FLAGS_HH__
Flags< FlagsType >::noneSet
bool noneSet() const
Definition: flags.hh:83
Flags< FlagsType >::allSet
bool allSet(Type flags) const
Definition: flags.hh:82
Flags
Definition: flags.hh:33
Flags< FlagsType >::Type
FlagsType Type
Definition: flags.hh:39
Flags< FlagsType >::Flags
Flags(Type flags)
Definition: flags.hh:46
Flags< FlagsType >::operator=
const Flags< FlagsType > & operator=(FlagsType flags)
Definition: flags.hh:69
Flags< FlagsType >::clear
void clear()
Definition: flags.hh:85
Flags< FlagsType >::set
void set(Type f, bool val)
Definition: flags.hh:88
Flags< FlagsType >::set
void set(Type flags)
Definition: flags.hh:87
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Flags< FlagsType >::allSet
bool allSet() const
Definition: flags.hh:81
Flags< FlagsType >::operator=
const Flags< FlagsType > & operator=(const Flags< U > &flags)
Definition: flags.hh:59
Flags< FlagsType >::update
void update(Type flags, Type mask)
Definition: flags.hh:90
Flags< FlagsType >::isSet
bool isSet(Type flags) const
Definition: flags.hh:80
Flags< FlagsType >::Flags
Flags()
Definition: flags.hh:45
Flags< FlagsType >::clear
void clear(Type flags)
Definition: flags.hh:86
Flags< FlagsType >::_flags
FlagsType _flags
Definition: flags.hh:36
Flags< FlagsType >::isSet
bool isSet() const
Definition: flags.hh:79
Flags< FlagsType >::noneSet
bool noneSet(Type flags) const
Definition: flags.hh:84
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17