forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutlflags.h
124 lines (99 loc) · 2.87 KB
/
utlflags.h
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
123
124
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Simple class to make it easier to deal with flags
//
//=============================================================================
#ifndef UTLFLAGS_H
#define UTLFLAGS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/dbg.h"
//-----------------------------------------------------------------------------
// Simple class to make it easier to deal with flags
//-----------------------------------------------------------------------------
template< class T >
class CUtlFlags
{
public:
CUtlFlags( int nInitialFlags = 0 );
// Flag setting
void SetFlag( int nFlagMask );
void SetFlag( int nFlagMask, bool bEnable );
// Flag clearing
void ClearFlag( int nFlagMask );
void ClearAllFlags();
bool IsFlagSet( int nFlagMask ) const;
// Is any flag set?
bool IsAnyFlagSet() const;
private:
T m_nFlags;
};
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
template< class T >
CUtlFlags<T>::CUtlFlags( int nInitialFlags )
{
// Makes sure we didn't truncate
Assert( nInitialFlags == (T)nInitialFlags );
m_nFlags = (T)nInitialFlags;
}
//-----------------------------------------------------------------------------
// Set flags
//-----------------------------------------------------------------------------
template< class T >
void CUtlFlags<T>::SetFlag( int nFlagMask )
{
// Makes sure we didn't truncate
Assert( nFlagMask == (T)nFlagMask );
m_nFlags |= (T)nFlagMask;
}
template< class T >
void CUtlFlags<T>::SetFlag( int nFlagMask, bool bEnable )
{
// Makes sure we didn't truncate
Assert( nFlagMask == (T)nFlagMask );
if ( bEnable )
{
m_nFlags |= (T)nFlagMask;
}
else
{
m_nFlags &= ~((T)nFlagMask);
}
}
//-----------------------------------------------------------------------------
// Clear flags
//-----------------------------------------------------------------------------
template< class T >
void CUtlFlags<T>::ClearFlag( int nFlagMask )
{
// Makes sure we didn't truncate
Assert( nFlagMask == (T)nFlagMask );
m_nFlags &= ~((T)nFlagMask);
}
template< class T >
void CUtlFlags<T>::ClearAllFlags()
{
m_nFlags = 0;
}
//-----------------------------------------------------------------------------
// Is a flag set?
//-----------------------------------------------------------------------------
template< class T >
bool CUtlFlags<T>::IsFlagSet( int nFlagMask ) const
{
// Makes sure we didn't truncate
Assert( nFlagMask == (T)nFlagMask );
return ( m_nFlags & nFlagMask ) != 0;
}
//-----------------------------------------------------------------------------
// Is any flag set?
//-----------------------------------------------------------------------------
template< class T >
bool CUtlFlags<T>::IsAnyFlagSet() const
{
return m_nFlags != 0;
}
#endif // UTLFLAGS_H