本文整理汇总了C++中TMem类的典型用法代码示例。如果您正苦于以下问题:C++ TMem类的具体用法?C++ TMem怎么用?C++ TMem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TMem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Header
bool TRf24Radio::Send(const uint16& NodeAddr, const uchar& Command, const TMem& Buff) {
bool ReceivedAck = false;
try {
Notify->OnNotifyFmt(ntInfo, "Sending message to node %d ...", NodeAddr);
RF24NetworkHeader Header(NodeAddr, Command);
TRpiUtil::SetMaxPriority();
uint16 From;
uchar Type;
TMem Payload; Payload.Gen(PAYLOAD_LEN);
TLock Lock(CriticalSection);
int RetryN = 0;
while (!ReceivedAck && RetryN < RETRY_COUNT) {
if (RetryN > 0) {
Notify->OnNotifyFmt(ntInfo, "Re-sending message, count %d", RetryN);
}
// write the message
_Send(Header, Buff);
// wait for an ACK
const uint64 StartTm = TTm::GetCurUniMSecs();
while (!ReceivedAck && TTm::GetCurUniMSecs() - StartTm < ACK_TIMEOUT) {
UpdateNetwork();
while (Read(From, Type, Payload)) {
if (Type == REQUEST_ACK) {
if (From != NodeAddr) {
Notify->OnNotifyFmt(ntWarn, "WTF!? received ACK from incorrect node, expected: %u, got: %u", NodeAddr, From);
} else {
Notify->OnNotifyFmt(ntInfo, "Received ack from node %u", NodeAddr);
ReceivedAck = true;
}
} else {
ReadThread.AddToQueue(TMsgInfo(From, Type, Payload));
}
}
}
RetryN++;
}
TRpiUtil::SetDefaultPriority();
} catch (const PExcept& Except) {
Notify->OnNotifyFmt(TNotifyType::ntErr, "Exception when sending!");
TRpiUtil::SetDefaultPriority();
return false;
}
if (!ReceivedAck) {
Notify->OnNotifyFmt(ntInfo, "Failed to send message!");
}
return ReceivedAck;
}
示例2: strlen
BOOL CMime::ReplaceCid(LPCTSTR pCid, LPCTSTR pReplace, LPCTSTR buf, DWORD size, LPSTR dest)
{_STT();
DWORD i = 0, x = 0;
DWORD cidlen = strlen( pCid );
TMem< char > cid;
if ( !cid.allocate( cidlen + 32 ) ) return FALSE;
// Fix up cid
strcpy( cid, "cid:" );
strcat( cid, pCid );
cidlen = strlen( cid );
// Simple replace routine
while( i < size )
{
if ( strnicmp( cid, &buf[ i ], cidlen ) ) dest[ x++ ] = buf[ i++ ];
else
{ strcpy( &dest[ x ], pReplace );
x += strlen( pReplace );
i += cidlen;
} // end else
} // end while
dest[ x ] = 0;
return TRUE;
}
示例3: Destroy
BOOL CMime::Load(LPCTSTR pFile)
{_STT();
// Out with the old
Destroy();
CWinFile file;
// Open the file
if ( !file.OpenExisting( pFile, GENERIC_READ ) )
return FALSE;
// Get file size
DWORD size = file.Size();
if ( size == 0 ) return FALSE;
// Allocate memory
TMem< BYTE > buf;
if ( !buf.allocate( size + 1 ) ) return FALSE;
// Read in the data into ram
DWORD read;
if ( !file.Read( buf, size, &read ) || read != size )
return FALSE;
buf[ size ] = 0;
// Load the file
if ( !LoadFromMemory( buf, size ) )
return FALSE;
return TRUE;
}
示例4: IAssert
void TWebNetClt::SendHttpRq(const PHttpRq& HttpRq){
// push fetch-id & create time to waiting-list
int FetchId=HttpRq->GetFldVal(THttp::FetchIdFldNm).GetInt(-1);
IAssert(FetchId!=-1);
TMem Mem; HttpRq->GetAsMem(Mem);
IAssert("Screwed NetMem"&&!memchr(Mem(),0,Mem.Len()));
PNetObj NetObj=PNetObj(new TNetMem(Mem));
SendNetObj(NetObj);
PushToSentQ(FetchId);
}
示例5: Lock
///////////////////////////////////////////
//// RF24 Radio transmitter
void TRf24Radio::TReadThread::Run() {
Notify->OnNotifyFmt(TNotifyType::ntInfo, "Starting read thread ...");
uint16 FromNode;
uchar Type;
TMem Payload;
Payload.Gen(PAYLOAD_LEN);
TMsgInfoV QueuedMsgV;
while (true) {
try {
// process queued messages
{
TLock Lock(Radio->CriticalSection);
// process new messages
Radio->UpdateNetwork();
while (Radio->Read(FromNode, Type, Payload)) {
Notify->OnNotifyFmt(ntInfo, "Read message, adding to queue ...");
AddToQueue(TMsgInfo(FromNode, Type, Payload));
}
if (!MsgQ.Empty()) {
Notify->OnNotifyFmt(ntInfo, "Adding %d messages to queue ...", MsgQ.Len());
QueuedMsgV.AddV(MsgQ);
MsgQ.Clr();
}
}
if (!QueuedMsgV.Empty()) {
Notify->OnNotifyFmt(ntInfo, "Processing %d messages ...", QueuedMsgV.Len());
for (int MsgN = 0; MsgN < QueuedMsgV.Len(); MsgN++) {
const TMsgInfo& Msg = QueuedMsgV[MsgN];
ProcessMsg(Msg.Val1, Msg.Val2, Msg.Val3);
}
Notify->OnNotify(ntInfo, "Queued messages processed!");
QueuedMsgV.Clr();
}
delayMicroseconds(500);
} catch (const PExcept& Except) {
Notify->OnNotifyFmt(TNotifyType::ntErr, "Error on the read thread: %s", Except->GetMsgStr().CStr());
}
}
}
示例6: GetSafeHwnd
void CPgPubExtra::OnSettings()
{
CReg *pReg = (CReg*)CDlgTabFrame::GetData( GetSafeHwnd() );
if ( pReg == NULL ) return;
CRKey *pRk = pReg->FindKey( "PUBINFO" );
if ( pRk == NULL ) return;
int sel = m_comboCodec.GetCurSel();
if ( sel == CB_ERR ) return;
// Get data pointer
LPCODECINFO pci = (LPCODECINFO)m_comboCodec.GetItemData( sel );
if ( pci == NULL || !m_codecs.VerifyPointer( pci ) ) return;
// Attempt to open settings dialog
HIC hIc = ICOpen( ICTYPE_VIDEO, pci->fourCC, ICMODE_QUERY );
if ( hIc != NULL )
{
DWORD size = pRk->GetValueSize( "CodecData" );
LPBYTE buf = (LPBYTE)pRk->GetValuePtr( "CodecData" );
// Restore settings
if ( size > 0 && buf != NULL )
ICSetState( hIc, buf, size );
// Configure the compressor
if ( ICConfigure( hIc, GetSafeHwnd() ) != ICERR_OK )
return;
size = ICGetStateSize( hIc );
if ( size > 0 )
{
TMem< BYTE > mem;
if ( mem.allocate( size ) )
if ( ICGetState( hIc, mem.ptr(), size ) == ICERR_OK )
pRk->Set( "CodecData", mem.ptr(), size );
} // end if
ICClose( hIc );
} // end if
}
示例7: GetParams
BOOL CNetCom::GetParams(CReg *pParams, GUID *pGuid)
{_STT();
if ( pParams == NULL ) return FALSE;
// See if there are any params
DWORD dwParams = 0; pParams->Destroy();
if ( m_prx->ReadPacketData( 0, NETMSGDT_PARAMS, NULL, 0, &dwParams ) && dwParams )
{ TMem< BYTE > buf;
if ( buf.allocate( dwParams ) &&
m_prx->ReadPacketData( 0, NETMSGDT_PARAMS, buf.ptr(), buf.size() ) )
pParams->LoadRegFromMem( buf, buf.size() );
} // end if
// Get the hash for these params
if ( pGuid ) GetParamsHash( pGuid );
return TRUE;
}
示例8: VerifyEmailList
BOOL CMime::VerifyEmailList(LPSTR pDst, LPCTSTR pSrc, LPCTSTR pSep)
{_STT();
// Sanity check
if ( pDst == NULL || pSrc == NULL ) return FALSE;
DWORD i = 0, skip = 0;
LPSTR pCopy = pDst;
TMem< char > buf;
// Are the destination and source the same?
if ( pDst == pSrc )
{ if ( !buf.allocate( ( strlen( pSrc ) * 2 ) + 1 ) ) return FALSE;
pCopy = buf.ptr();
} // end if
// Empty email list
*pCopy = 0;
char name[ MIME_STRSIZE ];
char user[ MIME_STRSIZE ];
char domain[ MIME_STRSIZE ];
// Pick apart the list then rebuild it
while( GetEmailComponents( &pSrc[ i ], name, user, domain, &skip ) )
{
// Skip to next address
i += skip;
// Add separator
if ( *pCopy != 0 ) strcat( pCopy, pSep );
// Append email address
BuildEmail( &pCopy[ strlen( pCopy ) ], name, user, domain );
} // end while
// Copy if dest and src are the same
if ( pDst == pSrc ) strcpy( pDst, pCopy );
return TRUE;
}
示例9: EncodeUrl
BOOL CReg::EncodeUrl(CPipe *pPipe, char chSepNameVal, char chSepValues )
{
// Ensure valid pipe
if ( NULL == pPipe ) return FALSE;
TMem< char > buf;
LPREGKEY prk = NULL;
while( ( prk = (LPREGKEY)GetNext( prk ) ) != NULL )
{
// Write separator if needed
if ( pPipe->GetBufferSize() ) pPipe->Write( &chSepValues, 1 );
LPCTSTR pName = prk->key->GetName();
CRKey *pRk = GetKey( pName );
if ( pRk )
{
// Write the name
if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( pName ) ) ) )
{ buf.Zero();
CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)pName, strlen( pName ) );
pPipe->Write( buf );
} // end if
// Separator
pPipe->Write( &chSepNameVal, 1 );
// Save the key value
CPipe tpipe;
prk->key->EncodeUrl( &tpipe, 1, chSepNameVal, chSepValues );
if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( tpipe.GetBufferSize() ) ) )
{ buf.Zero();
CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)tpipe.GetBuffer(), tpipe.GetBufferSize() );
pPipe->Write( buf );
} // end if
} // end if
} // end while
return TRUE;
}
示例10: Replace
BOOL CRKey::Replace(LPCTSTR pSrc, LPCTSTR pDst)
{_STTEX();
// Open files
CWinFile src, dst;
if ( !src.OpenExisting( pSrc, GENERIC_READ ) ) return FALSE;
if ( !dst.OpenNew( pDst, GENERIC_WRITE ) ) return FALSE;
// Read in data
TMem< BYTE > in;
if ( !in.allocate( src.Size() ) ) return FALSE;
if ( !src.Read( in.ptr(), in.size() ) ) return FALSE;
src.Close();
// Run replace function
CPipe outpipe;
DWORD op = 0, i = 0;
char token[ 256 ];
while ( Replace( &outpipe, &op, in.str(), in.size(),
NULL, NULL, token, NULL, &i ) )
{
} // end while
// Write out the data
return dst.Write( outpipe.GetBuffer(), outpipe.GetBufferSize() );
}
示例11: Load
BOOL CCfgFile::Load(LPCTSTR pFile, BOOL bMerge)
{_STTEX();
if ( pFile == NULL ) return FALSE;
// Lose old record
if ( !bMerge ) Destroy();
if ( !bMerge ) strcpy( m_szFileName, pFile );
CWinFile file;
// Set crypto key
if ( *m_szKey ) file.CryptoSetKey( m_szKey );
// Open the file
if ( !file.OpenExisting( pFile, GENERIC_READ ) )
return FALSE;
// Get file size
DWORD size = file.Size();
if ( size == 0 ) return FALSE;
// Allocate memory
TMem< BYTE > buf;
if ( !buf.allocate( size + 1 ) ) return FALSE;
// Read in the data into ram
DWORD read;
if ( !file.Read( buf, size, &read ) || read != size )
return FALSE;
buf[ size ] = 0;
// Load the file
if ( !LoadFromMem( buf, size, bMerge ) )
return FALSE;
if ( !bMerge ) strcpy( m_szFileName, pFile );
return TRUE;
}
示例12: SaveToMem
BOOL CMime::Save(LPCTSTR pFile)
{_STT();
CWinFile f;
// Attempt to open the new file
if ( !f.OpenNew( pFile ) ) return FALSE;
// How much data
DWORD size = SaveToMem( NULL, 0 );
if ( size == 0 ) return TRUE;
// Allocate memory
TMem< BYTE > buf;
if ( !buf.allocate( size + 1 ) ) return FALSE;
// Write MIME to buffer
DWORD bytes = SaveToMem( buf, size );
// Write out the data to disk file
f.Write( buf, bytes );
return TRUE;
}
示例13: defined
CStr CTrace::GetBacktrace( oexUINT x_uSkip, oexUINT x_uMax )
{
#if defined( OEX_NOEXECINFO )
return CStr();
#else
// Allocate space for pointers
TMem< void* > memPtrs;
if ( !memPtrs.OexNew( x_uMax ).Ptr() )
return CStr();
// Get backtrace
oexINT nPtrs = backtrace( memPtrs.Ptr(), x_uMax );
if ( !nPtrs )
return CStr();
// Get function symbols
char ** sStrings = backtrace_symbols( memPtrs.Ptr(), nPtrs );
// Build stack
CStr str;
for ( oexUINT i = x_uSkip; (oexINT)i < nPtrs; i++ )
{
if ( sStrings && sStrings[ i ] && oexCHECK_PTR( memPtrs.Ptr( i ) ) )
str += CStr().Fmt( oexT( "[0x%.8X] %s" oexNL8 ), (oexUINT)*(oexUINT*)memPtrs.Ptr( i ), sStrings[ i ] );
else if ( oexCHECK_PTR( memPtrs.Ptr( i ) ) )
str += CStr().Fmt( oexT( "[0x%.8X] ???" oexNL8 ), (oexUINT)*(oexUINT*)memPtrs.Ptr( i ) );
else
str += oexT( "[0x????????] ???" oexNL8 );
} // end if
memPtrs.Zero();
// Release the memory
if ( sStrings )
free( sStrings );
return str;
#endif
}
示例14: Send
void TWebFetchSendBatchJson::Send() {
TStr BodyStr = TJsonVal::GetStrFromVal(JsonArray);
TMem BodyMem; BodyMem.AddBf(BodyStr.CStr(), BodyStr.Len());
PHttpRq HttpRq = THttpRq::New(hrmPost, TUrl::New(UrlStr), THttp::AppJSonFldVal, BodyMem);
FetchHttpRq(HttpRq);
}
示例15: getUsed
oexUINT CBin::GroupAvg( oexINT nType, oexUINT uOffset, oexUINT uInterval, oexUINT uGroups, CBin &bin, oexINT nFlags )
{
// Sanity check
if ( 0 >= uGroups || !getUsed() )
return 0;
// Get skip value
oexUINT uSkip = nFlags & 0x0f;
if ( uSkip >= uGroups )
uSkip = 0;
// Get element size
oexUINT uESize = obj::StaticSize( nType );
if ( !uESize )
return 0;
// Total samples
oexUINT uSamples = getUsed() / uESize;
if ( uSamples < uInterval )
return 0;
// How many samples per group
oexUINT nSamplesPerGroup = ( uInterval - uSkip ) / ( uGroups - uSkip );
if ( !nSamplesPerGroup )
return 0;
// Allocate memory
oexUINT uBytes = uGroups * uESize;
if ( bin.Size() < uBytes )
if ( !bin.Allocate( uBytes ) )
return oexFALSE;
// Allocate an array to hold the counts
TMem< oexUINT > aCnts;
if ( !aCnts.OexNew( uGroups ).Ptr() )
return oexFALSE;
// Memory to hold acc
TMem< oexLONGDOUBLE > aAcc;
if ( !aAcc.OexNew( uGroups ).Ptr() )
return oexFALSE;
// Initialize group averages
for ( oexUINT i = 0; i < uGroups; i++ )
aAcc[ i ] = 0, aCnts[ i ] = 0;
// Accumulate all samples
while( ( uOffset + uInterval ) < uSamples )
{
// Accumulate samples in this interval
for ( oexUINT s = 0; s < uInterval; s++ )
{
// Get the value
oexLONGDOUBLE dV;
switch( nType )
{ case obj::tInt : dV = getINT( uOffset + s ); break;
case obj::tFloat : dV = getFLOAT( uOffset + s ); break;
case obj::tDouble : dV = getDOUBLE( uOffset + s ); break;
default : dV = 0;
} // end switch
// Range check and add
// if ( 1000000 > oex::cmn::Abs( dV ) && .0000001 < oex::cmn::Abs( dV ) )
if ( s < uSkip )
aAcc[ s ] = dV, aCnts[ s ]++;
else
{ oexUINT o = uSkip + s / nSamplesPerGroup;
if ( o >= uGroups ) o = uGroups - 1;
aAcc[ o ] += dV; aCnts[ o ]++;
} // end else
} // end for
uOffset += uInterval;
} // end while
// Calculate averages
switch( nType )
{
case obj::tInt :
for ( oexUINT g = 0; g < uGroups; g++ )
bin.setINT( g, aCnts[ g ] ? oexINT( aAcc[ g ] / aCnts[ g ] ) : 0 );
break;
case obj::tFloat :
for ( oexUINT g = 0; g < uGroups; g++ )
bin.setFLOAT( g, aCnts[ g ] ? oexFLOAT( aAcc[ g ] / aCnts[ g ] ) : 0 );
break;
case obj::tDouble :
for ( oexUINT g = 0; g < uGroups; g++ )
bin.setDOUBLE( g, aCnts[ g ] ? oexDOUBLE( aAcc[ g ] / aCnts[ g ] ) : 0 );
break;
default :
return 0;
} // end switch
//.........这里部分代码省略.........