summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/Flags.cpp
blob: 13cbd85915b537f9579d3ff10a56d9359c11a0f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//===-- Flags.cpp -----------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/Flags.h"

using namespace lldb_private;

//----------------------------------------------------------------------
// Default Constructor
//----------------------------------------------------------------------
Flags::Flags (ValueType flags) :
    m_flags(flags)
{
}

//----------------------------------------------------------------------
// Copy Constructor
//----------------------------------------------------------------------
Flags::Flags (const Flags& rhs) :
    m_flags(rhs.m_flags)
{
}

//----------------------------------------------------------------------
// Virtual destructor in case anyone inherits from this class.
//----------------------------------------------------------------------
Flags::~Flags ()
{
}

//----------------------------------------------------------------------
// Get accessor for all of the current flag bits.
//----------------------------------------------------------------------
Flags::ValueType
Flags::GetAllFlagBits () const
{
    return m_flags;
}

size_t
Flags::GetBitSize() const
{
    return sizeof (ValueType) * 8;
}

//----------------------------------------------------------------------
// Set accessor for all of the current flag bits.
//----------------------------------------------------------------------
void
Flags::SetAllFlagBits (ValueType flags)
{
    m_flags = flags;
}

//----------------------------------------------------------------------
// Clear one or more bits in our flag bits
//----------------------------------------------------------------------
Flags::ValueType
Flags::Clear (ValueType bits)
{
    m_flags &= ~bits;
    return m_flags;
}

//----------------------------------------------------------------------
// Set one or more bits in our flag bits
//----------------------------------------------------------------------
Flags::ValueType
Flags::Set (ValueType bits)
{
    m_flags |= bits;
    return m_flags;
}

//----------------------------------------------------------------------
// Returns true if any flag bits in "bits" are set
//----------------------------------------------------------------------
bool
Flags::IsSet (ValueType bits) const
{
    return (m_flags & bits) != 0;
}

//----------------------------------------------------------------------
// Returns true if all flag bits in "bits" are clear
//----------------------------------------------------------------------
bool
Flags::IsClear (ValueType bits) const
{
    return (m_flags & bits) == 0;
}


size_t
Flags::SetCount () const
{
    size_t count = 0;
    for (ValueType mask = m_flags; mask; mask >>= 1)
    {
        if (mask & 1)
            ++count;
    }
    return count;
}

size_t
Flags::ClearCount () const
{
    size_t count = 0;
    for (ValueType shift = 0; shift < sizeof(ValueType)*8; ++shift)
    {
        if ((m_flags & (1u << shift)) == 0)
            ++count;
    }
    return count;
}
OpenPOWER on IntegriCloud