orstring.cpp
来自「IO函数调用测试」· C++ 代码 · 共 144 行
CPP
144 行
#include "stdafx.h"
#include "idcombo.h"
#include "orstring.h"
/****************************************************************************
* CORString::OR
* Inputs:
* CString & s: Reference to a string
* CString t: String to append
* Result: void
*
* Effect:
* Appends the string t to the string s, with a possible "|"
* Notes:
* case | inputs | result
* -----+--------------+--------
* | s t | s
* I "" "" "0"
* II "" "0" "0"
* III "" "T" "T"
* IV "0" "T" "T"
* V "0" "0" "0"
* VI "S" "" "S"
* VII "0" "" "0"
* VIII "S" "0" "S"
* IX "S" "T" "S | T"
****************************************************************************/
void CORString::OR(CString & s, CString t)
{
if(s.GetLength() == 0 && t.GetLength() == 0)
{ /* I */
s = _T("0");
} /* I */
else
if(s.GetLength() == 0)
{ /* II, III */
s = t;
} /* II, III */
else
if(s == _T("0"))
{ /* IV, V */
if(t != _T("0"))
{ /* IV */
s = t;
} /* IV */
else
if(t == _T("0") && s == _T("0"))
{ /* V */
// do nothing
} /* V */
else
{ /* V */
// do nothing
} /* V */
} /* IV, V */
else
if(t.GetLength() == 0 || t == _T("0"))
{ /* VI, VII, VIII */
// do nothing
} /* VI, VII, VIII */
else
{ /* IX */
s += _T(" | ");
s += t;
} /* IX */
}
/****************************************************************************
* CORString::getString
* Inputs:
* IDDATA * ids: Table of bits
* DWORD bits: bits in bitvector
* Result: CString
* String constructed of bits
****************************************************************************/
CString CORString::getString(IDData * ids, DWORD bits)
{
int i;
CString s;
if(bits == 0)
{ /* see if 0 string */
for(i = 0; ids[i].id != 0; i++)
{ /* loop */
if(ids[i].val == 0)
{ /* found 0 */
s.LoadString(ids[i].id);
return s;
} /* found 0 */
} /* loop */
} /* see if 0 string */
for(i = 0; ids[i].id != 0; i++)
{ /* loop match */
if(ids[i].val & bits)
{ /* found one */
CString t;
t.LoadString(ids[i].id);
OR(s, t);
} /* found one */
} /* loop match */
if(s.GetLength() == 0)
s = _T("0");
return s;
}
/****************************************************************************
* CORString::ORzero
* Inputs:
* CString &s: String to which bits will be appended
* DWORD val: Bit value
* DWORD bit: Bit mask
* UINT id: ID of zero-valued bit
* Result: void
*
* Effect:
* If (val & bit) == 0, append the string designated by id
* Notes:
* This function handles those weird cases where Microsoft defines a
* "bit" to OR in which is actually a zero value, e.g,
* #define THIS 0x00000001
* #define NOT_THIS 0x00000000
* #define THAT 0x00000002
* #define NOT_THAT 0x00000000
* The "bit" parameter is the complement of the zero-bit value, e.g.,
* call the function as shown below. Note that if the value is THIS,
* the normal CORString constructor given a table of non-zero bits
* has already placed the "THIS" flag and the ORzero call will do nothing.
* ORzero(string, val, THIS, IDS_NOT_THIS);
****************************************************************************/
void CORString::ORzero(CString &s, DWORD val, DWORD bit, UINT id)
{
if((val & bit) != 0)
return; // 1-based value should already be set by constructor
CString t;
t.LoadString(id);
OR(s, t);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?