Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTriState.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cTriState_H
7 #define _INC_cTriState_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cBits.h"
13 #include "cDebugAssert.h"
14 
15 namespace Gray
16 {
17  class cTriState
18  {
22  private:
23  signed char m_iVal;
24 
25  public:
27  : m_iVal((signed char)eVal)
28  {
31  }
32  cTriState(bool bVal)
33  : m_iVal((signed char)(bVal ? BITOP_SET : BITOP_CLR))
34  {
35  }
36  bool isInternalValidState() const
37  {
39  return m_iVal == BITOP_TOGGLE || m_iVal == BITOP_CLR || m_iVal == BITOP_SET;
40  }
41  bool isTriState() const
42  {
43  return m_iVal == BITOP_TOGGLE;
44  }
45  bool get_Bool() const
46  {
48  ASSERT(m_iVal != BITOP_TOGGLE);
49  return (bool)m_iVal;
50  }
51  bool GetBoolDef(bool bDefault = false) const
52  {
54  if (m_iVal == BITOP_TOGGLE)
55  return bDefault;
56  return (bool)m_iVal;
57  }
59  {
60  return (BITOP_TYPE)m_iVal;
61  }
62  void put_Tri(BITOP_TYPE eVal)
63  {
64  m_iVal = (signed char)eVal;
66  }
67  operator BITOP_TYPE() const
68  {
69  return get_Tri();
70  }
71  };
72 }
73 #endif
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cTriState.h:18
bool isInternalValidState() const
Definition: cTriState.h:36
BITOP_TYPE get_Tri() const
Definition: cTriState.h:58
bool GetBoolDef(bool bDefault=false) const
Definition: cTriState.h:51
bool get_Bool() const
Definition: cTriState.h:45
cTriState(BITOP_TYPE eVal=BITOP_TOGGLE)
Definition: cTriState.h:26
cTriState(bool bVal)
Definition: cTriState.h:32
bool isTriState() const
Definition: cTriState.h:41
void put_Tri(BITOP_TYPE eVal)
Definition: cTriState.h:62
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
BITOP_TYPE
Definition: cBits.h:22
@ BITOP_SET
OR bit operation to set bits.
Definition: cBits.h:28
@ BITOP_CLR
AND/NOT bit operation to clear bits.
Definition: cBits.h:27
@ BITOP_TOGGLE
XOR bit operation to flip bits. Also used for unknown bit state.
Definition: cBits.h:26