本文整理汇总了C++中CByteArray::GetAt方法的典型用法代码示例。如果您正苦于以下问题:C++ CByteArray::GetAt方法的具体用法?C++ CByteArray::GetAt怎么用?C++ CByteArray::GetAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CByteArray
的用法示例。
在下文中一共展示了CByteArray::GetAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetReceivedBuffer
BOOL COneCommand::GetReceivedBuffer(CByteArray &buffer) {
BOOL ret;int i,size;BYTE src,dst;
if((size=m_ReceiveBuffer.GetSize())!=buffer.GetSize()) {
buffer.RemoveAll();
buffer.Append(m_ReceiveBuffer);
return TRUE;
}
else {
ret=FALSE;
for(i=0;i<size;i++) {
src=m_ReceiveBuffer.GetAt(i);
dst=buffer.GetAt(i);
if(src!=dst) {
buffer.SetAt(i,src);
ret=TRUE;
}
}
return ret;
}
}
示例2: SetBinaryValue
BOOL CRegistry::SetBinaryValue(LPCTSTR name_of_value, const CByteArray& bytes_to_write)
{
ASSERT(name_of_value != NULL);
if (name_of_value == NULL) {
m_ErrorCode = ERROR_INVALID_PARAMETER;
return(FALSE);
}
DWORD size_of_buffer = bytes_to_write.GetSize();
LPBYTE memory_buffer = NULL;
try {
memory_buffer = new BYTE[ size_of_buffer ];
}
catch(...) {
memory_buffer = NULL;
}
if (memory_buffer == NULL) {
m_ErrorCode = ::GetLastError();
return(FALSE);
}
DWORD index = 0;
while(index < size_of_buffer) {
memory_buffer[ index ] = bytes_to_write.GetAt(index);
index++;
}
BOOL ret = SetValue(name_of_value, typeBinary, memory_buffer, size_of_buffer);
delete [] memory_buffer;
return(ret);
}
示例3: ModifyParamArray
/**
* Modifies a user param byte array with the ExtParam data passed with
* argument pParam. ExtParam data objects will be build from
* Ext_User_Prm_Data_Const/Ref fields within the GSD. Extparam data
* describes the datatype of the Ext_User_Prm_Data, the offset within
* the user param byte array and the value. The passed user param byte
* array (see argument UserParam) grows as necessary.
* Existing user param bytes within the array will be or-ed with the
* new byte value.
*
* @param CByteArray & UserParam - user param byte array to
* modify. The byte array will grow as necessary.
* @param ExtParam *pParam - Reference to ExtParam data
* object describing the Ext_User_Prm_Data. Shall not
* be NULL.
* @exception CMemoryException
* @see GSD: Ext_User_Prm_Data_Const/Ref
*/
void ModifyParamArray(CByteArray & UserParam, ExtParam *pParam)
{
int offset = 0;
int sizeArray = 0;
int sizeBytes = 0;
ASSERT(pParam);
switch(pParam->GetParamType()) {
case Array:
{
CByteArray* pBytes = pParam->GetByteArray();
sizeBytes = pBytes->GetSize();
sizeArray = UserParam.GetSize();
offset = pParam->GetByteOffset();
if(offset + sizeBytes > sizeArray) {
//grow the array
UserParam.SetSize(offset + sizeBytes);
BYTE *pb = UserParam.GetData();
//preset array
size_t sizeSet = offset + sizeBytes - sizeArray;
memset(&pb[sizeArray],0,sizeSet);
}
for (int x = 0; x < sizeBytes; x++) {
BYTE userbyte = UserParam.GetAt(offset);
BYTE setbyte = pBytes->GetAt(x);
userbyte |= setbyte;
UserParam.SetAt(offset++, userbyte);
}// next x
}
break;
case Byte:
{
offset = pParam->GetByteOffset();
sizeArray = UserParam.GetSize();
sizeBytes = sizeof(BYTE);
if(offset + sizeBytes > sizeArray) {
//grow the array
UserParam.SetSize(offset + sizeBytes);
BYTE *pb = UserParam.GetData();
//preset array
size_t sizeSet = offset + sizeBytes - sizeArray;
memset(&pb[sizeArray],0,sizeSet);
}
BYTE userbyte = UserParam.GetAt(offset); // Get current value in Bytearray
if (pParam->IsBitArea()) {
userbyte &= ~MakeBitFieldInByte(pParam->GetBitAreaStart(),
pParam->GetBitAreaLength());
userbyte |= (BYTE)(pParam->GetUsedValue() << pParam->GetBitAreaStart());
}
else {
userbyte = (BYTE)pParam->GetUsedValue();
}
UserParam.SetAt(offset, userbyte); // Set new value in ByteArray
}
break;
case Word:
{
BYTE setbyte = 0;
WORD data = (WORD)pParam->GetUsedValue();
offset = pParam->GetByteOffset();
sizeArray = UserParam.GetSize();
sizeBytes = sizeof(data);
if(offset + sizeBytes > sizeArray) {
//grow the array
UserParam.SetSize(offset + sizeBytes);
BYTE *pb = UserParam.GetData();
//preset array
size_t sizeSet = offset + sizeBytes - sizeArray;
memset(&pb[sizeArray],0,sizeSet);
}
for (int i = sizeBytes - 1; i >= 0 ; i--) {
//.........这里部分代码省略.........
示例4: AnalysisCard
/**
* @brief 从7张牌中分析出5张最大牌型
* @param bHandCards[] 要分析的手牌
* @param nCount 手牌张数
* @param bPublicCards[] 要分析公共牌
* @param nPublicCount 公共牌张数
* @param bResultCard[] 返回分析得到的数据牌
* @return 牌型
*/
int CUpGradeGameLogic::AnalysisCard(BYTE bHandCards[], int nHandCount, BYTE bPublicCards[], int nPublicCount, BYTE bResultCard[])
{
if ((nHandCount + nPublicCount) != 7)
{
return 0;
}
int i, j;
CByteArray arrCards;
for (i = 0; i < nHandCount; i++)
{
arrCards.Add(bHandCards[i]);
}
for (i = 0; i < nPublicCount; i++)
{
arrCards.Add(bPublicCards[i]);
}
BYTE bCard[5] = {0};
int nCardKind[21] = {0};
//// 21种组成方法
//BYTE bIndex[21][5] = {0, 1, 2, 3, 4, \
// 0, 1, 2, 3, 5, \
// 0, 1, 2, 3, 6, \
// 0, 1, 2, 4, 5, \
// 0, 1, 2, 4, 6, \
// 0, 1, 2, 5, 6, \
// 0, 1, 3, 4, 5, \
// 0, 1, 3, 4, 6, \
// 0, 1, 3, 5, 6, \
// 0, 1, 4, 5, 6, \
// 0, 2, 3, 4, 5, \
// 0, 2, 3, 4, 6, \
// 0, 2, 3, 5, 6, \
// 0, 2, 4, 5, 6, \
// 0, 3, 4, 5, 6, \
// 1, 2, 3, 4, 5, \
// 1, 2, 3, 4, 6, \
// 1, 2, 3, 5, 6, \
// 1, 2, 4, 5, 6, \
// 1, 3, 4, 5, 6, \
// 2, 3, 4, 5, 6, \
// };
// 21种组成方法
BYTE bIndex[21][7] = {0, 1, 2, 3, 4, 5, 6,
0, 1, 2, 3, 5, 4, 6,
0, 1, 2, 3, 6, 4, 5,
0, 1, 2, 4, 5, 3, 6,
0, 1, 2, 4, 6, 3, 5,
0, 1, 2, 5, 6, 3, 4,
0, 1, 3, 4, 5, 2, 6,
0, 1, 3, 4, 6, 2, 5,
0, 1, 3, 5, 6, 2, 4,
0, 1, 4, 5, 6, 2, 3,
0, 2, 3, 4, 5, 1, 6,
0, 2, 3, 4, 6, 1, 5,
0, 2, 3, 5, 6, 1, 4,
0, 2, 4, 5, 6, 1, 3,
0, 3, 4, 5, 6, 1, 2,
1, 2, 3, 4, 5, 0, 6,
1, 2, 3, 4, 6, 0, 5,
1, 2, 3, 5, 6, 0, 4,
1, 2, 4, 5, 6, 0, 3,
1, 3, 4, 5, 6, 0, 2,
2, 3, 4, 5, 6, 0, 1
};
for (i = 0; i < 21; i++)
{
for (j = 0; j < 5; j++)
{
// 按牌下标取出5张牌
bCard[j] = arrCards.GetAt(bIndex[i][j]);
}
// 获取牌型
nCardKind[i] = GetCardShape(bCard, 5);
//CString str;
//str.Format("dxh: 第%d种方法, 牌型: %d", i, nCardKind[i]);
//OutputDebugString(str);
}
// 取最大牌型位置
int nMax = 0;
for (i = 1; i < 21; i++)
{
//.........这里部分代码省略.........
示例5: if
CTobCompiler::EToken CTobCompiler::CompilePass1()
{
EToken r;
CString str, buf;
CByteArray* bin = 0;
for(;;)
{
if((r = GetToken(str)) <= 0) return r;
if(r == SYM_KEY)
{
if((r = GetToken(str)) < 0) return r;
if(r != SYM_TOKEN)
{
m_err = "not found keyword after '.'";
return ERR_NORMAL;
}
if(str == "def")
{
if((r = GetToken(str)) < 0) return r;
if(r != SYM_TOKEN)
{
m_err = "not found token after '.def'";
return ERR_NORMAL;
}
if((r = GetToken(buf)) < 0) return r;
if(r == SYM_BIN)
{
bin = new CByteArray;
if((r = GetBinary(*bin)) < 0) { delete bin; return r; }
}
else if(r == SYM_STR)
{
if((r = GetString(buf, false)) < 0) return r;
bin = new CByteArray;
for(LPCTSTR p = buf; *p; ++p) bin->Add(*(U8*)p);
if(r == SYM_STRING) bin->Add(0);
}
else if(r == SYM_STRING)
{
if((r = GetString(buf, true)) < 0) return r;
bin = new CByteArray;
for(LPCTSTR p = buf; *p; ++p) bin->Add(*(U8*)p);
if(r == SYM_STRING) bin->Add(0);
}
else
{
m_err = "not found '[' or ''' or '\"' after '.def <token>''";
return ERR_NORMAL;
}
m_defbin.SetAt(str, bin);
bin = 0;
}
else if(str == "change")
{
if((r = GetToken(str)) < 0) return r;
if(r != SYM_STR)
{
m_err = "not found ''' after '.change'";
return ERR_NORMAL;
}
if((r = GetString(str, false)) < 0) return r;
if( str.IsEmpty() || str.GetLength()>2 || str.GetLength() == 2 && (U8)str[0]<0x80)
{
m_err = "only one character is allowed after '.change'";
return ERR_NORMAL;
}
U16 c = (U8)str[0];
if(str.GetLength() == 2) c = (c<<8) + (U8)str[1];
if((r = GetToken(str)) < 0) return r;
if(r == SYM_BIN)
{
CByteArray tmp;
if((r = GetBinary(tmp)) < 0) return r;
buf.Empty();
int i, n = tmp.GetSize();
for(i = 0; i < n; ++i)
{
U8 b = tmp.GetAt(i);
if(!b) break;
buf += (TCHAR)b;
}
}
else if(r == SYM_STR)
{
if((r = GetString(buf, false)) < 0) return r;
}
else if(r == SYM_STRING)
{
if((r = GetString(buf, true)) < 0) return r;
}
else
{
m_err = "not found ''' or '\"' after '.change <char>'";
return ERR_NORMAL;
}
m_change.SetAt(c, buf);
}
else if(str == "bit")
{
//.........这里部分代码省略.........
示例6: bGetMsgInfoFromMsgStr
//.........这里部分代码省略.........
}
else
{
psCANData->m_ucDataType = RX_FLAG;
}
nIndex = omStrMsgID.GetLength();
omStrTemp = omStrTemp.Right(omStrTemp.GetLength() - nIndex - 1);
omStrTemp.TrimLeft();
// Channel ID
omStrMsgID = omStrTemp.SpanExcluding("\t ");
UCHAR ucChannel =
(UCHAR) strtol( (LPCTSTR )omStrMsgID,&pcStopString ,10);
nIndex = omStrMsgID.GetLength();
omStrTemp = omStrTemp.Right(omStrTemp.GetLength() - nIndex -1);
omStrTemp.TrimLeft();
// Get the message with name
omStrMsgID = omStrTemp.SpanExcluding("\t ");
// Get the rest of the string.
nIndex = omStrMsgID.GetLength();
omStrTemp = omStrTemp.Right(omStrTemp.GetLength() - nIndex -1);
omStrTemp.TrimLeft();
// Get message ID string after removing any message name.
omStrMsgID = omStrMsgID.SpanExcluding(defMSGID_NAME_DELIMITER);
UINT unMsgID = 0;
if( bHexON == TRUE)
{
unMsgID =
(UINT) strtol( (LPCTSTR )omStrMsgID,&pcStopString ,16);
}
else
{
unMsgID =
(UINT) strtol( (LPCTSTR )omStrMsgID,&pcStopString ,10);
}
// Get the message ID Type
omStrMsgIDType = omStrTemp.SpanExcluding("\t ");
// Message Id type is EXTENDED
if(omStrMsgIDType.Find(defMSGID_EXTENDED) != -1)
{
psCANData->m_uDataInfo.m_sCANMsg.m_ucEXTENDED = 1;
}// Message Id type is STD
else if(omStrMsgIDType.Find(defMSGID_STD)!= -1)
{
psCANData->m_uDataInfo.m_sCANMsg.m_ucEXTENDED = 0;
}
// Message Id type is RTR
if(omStrMsgIDType.Find(defMSGID_RTR)!= -1)
{
psCANData->m_uDataInfo.m_sCANMsg.m_ucRTR = 1;
}
else
{
psCANData->m_uDataInfo.m_sCANMsg.m_ucRTR = 0;
}
nIndex = omStrMsgIDType.GetLength();
omStrTemp = omStrTemp.Right(omStrTemp.GetLength() - nIndex -1);
omStrTemp.TrimLeft();
// Get the DLC
omStrDLC = omStrTemp.SpanExcluding("\t ");
nIndex = omStrDLC.GetLength();
UINT unDLC = (UINT) strtol((LPCTSTR)omStrDLC,&pcStopString ,16);
omStrTemp = omStrTemp.Right(omStrTemp.GetLength() - nIndex -1);
omStrTemp.TrimLeft();
// Get the data string
omStrData = omStrTemp;
// Check if Message ID and DLC is valid.
if(unMsgID>0 && unDLC<=8 && unDLC>0)
{
nIndex = omStrData.GetLength();
vConvStrtoByteArray(&omByteArrayDataTx,
omStrData.GetBuffer(nIndex),bHexON);
omStrData.ReleaseBuffer(nIndex);
INT nTotalData = (INT)omByteArrayDataTx.GetSize();
// Check if String to Byte array conversion
// has return a valid data
if(nTotalData<=8 )
{
for(INT i = 0; i<nTotalData; i++)
{
psCANData->m_uDataInfo.m_sCANMsg.m_ucData[i] =
omByteArrayDataTx.GetAt(i);
}
psCANData->m_uDataInfo.m_sCANMsg.m_unMsgID = unMsgID;
psCANData->m_uDataInfo.m_sCANMsg.m_ucDataLen = (UCHAR)unDLC;
psCANData->m_uDataInfo.m_sCANMsg.m_ucChannel = ucChannel;
nReturn = TRUE;
}
}
}
}
}
return nReturn;
}