本文整理汇总了C++中CAtlArray::SetCount方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlArray::SetCount方法的具体用法?C++ CAtlArray::SetCount怎么用?C++ CAtlArray::SetCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAtlArray
的用法示例。
在下文中一共展示了CAtlArray::SetCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Shuffle
POSITION CPlaylist::Shuffle()
{
static INT_PTR idx = 0;
static INT_PTR count = 0;
static CAtlArray<plsort_t> a;
ASSERT(GetCount() > 2);
// insert or remove items in playlist, or index out of bounds then recalculate
if ((count != GetCount()) || (idx >= GetCount())) {
a.RemoveAll();
idx = 0;
a.SetCount(count = GetCount());
POSITION pos = GetHeadPosition();
for (INT_PTR i = 0; pos; i++, GetNext(pos)) {
a[i].pos = pos; // initialize position array
}
//Use Fisher-Yates shuffle algorithm
srand((unsigned)time(nullptr));
for (INT_PTR i = 0; i < (count - 1); i++) {
INT_PTR r = i + (rand() % (count - i));
POSITION temp = a[i].pos;
a[i].pos = a[r].pos;
a[r].pos = temp;
}
}
return a[idx++].pos;
}
示例2: SetShuffle
// Calling this function with bEnable equals to true when
// shuffle is already enabled will re-shuffle the tracks.
void CPlaylist::SetShuffle(bool bEnable)
{
m_bShuffle = bEnable;
if (bEnable && !IsEmpty()) {
m_nShuffledListSize = GetCount();
CAtlArray<plsort_t> positions;
positions.SetCount(m_nShuffledListSize + 1);
srand((unsigned int)time(nullptr));
POSITION pos = GetHeadPosition();
for (size_t i = 0; pos; i++, GetNext(pos)) {
positions[i].n = rand();
positions[i].pos = pos;
}
qsort(positions.GetData(), m_nShuffledListSize, sizeof(plsort_t), compare);
positions[m_nShuffledListSize].pos = nullptr; // Termination
m_posHeadShuffle = positions[0].pos;
m_posTailShuffle = nullptr;
for (size_t i = 0; i < m_nShuffledListSize; i++) {
pos = positions[i].pos;
CPlaylistItem& pli = GetAt(pos);
pli.m_posPrevShuffle = m_posTailShuffle;
pli.m_posNextShuffle = positions[i + 1].pos;
m_posTailShuffle = pos;
}
} else {
m_posHeadShuffle = m_posTailShuffle = nullptr;
m_nShuffledListSize = 0;
}
}
示例3: LoadInternalExceptionList
static void LoadInternalExceptionList()
{
g_aException.SetCount( 0, 32 );
LPCTSTR rs = NULL;
size_t len = AtlLoadString(
IDS_INTERNAL_EXCEPTIONS,
reinterpret_cast<LPTSTR>(&rs),
0
);
LPTSTR buf = reinterpret_cast<LPTSTR>( malloc((len + 1) * sizeof(TCHAR)) );
_tcsncpy( buf, rs, len );
buf[len] = 0;
LPCTSTR p = _tcstok( buf, _T("|") );
while( p != NULL )
{
CExceptionInfo ei;
ei.bUser = false;
ei.bFiltered = false;
ei.dwCode = _tcstoul( p, NULL, 0 );
p = _tcstok( NULL, _T("|") );
_tcsncpy( ei.szName, p, _countof(ei.szName) );
ei.szName[_countof(ei.szName) - 1] = 0;
g_aException.Add( ei );
p = _tcstok( NULL, _T("|") );
}
free( buf );
}
示例4: sizeof
HRESULT CAC3Encoder::Encode(CAtlArray<float>& BuffIn, CAtlArray<BYTE>& BuffOut)
{
int buffsamples = BuffIn.GetCount() / m_pAVCtx->channels;
if (buffsamples < m_pAVCtx->frame_size) {
return E_ABORT;
}
float* pEnc = m_pSamples;
float* pIn = BuffIn.GetData();
int channels = m_pAVCtx->channels;
int samples = m_pAVCtx->frame_size;
for (int ch = 0; ch < channels; ++ch) {
for (int i = 0; i < samples; ++i) {
*pEnc++ = pIn[channels * i + ch];
}
}
int ret;
AVPacket avpkt;
int got_packet;
av_init_packet(&avpkt);
avpkt.data = NULL; // packet data will be allocated by the encoder
avpkt.size = 0;
ret = avcodec_encode_audio2(m_pAVCtx, &avpkt, m_pFrame, &got_packet);
if (ret < 0) {
av_free_packet(&avpkt);
return E_FAIL;
}
if (got_packet) {
BuffOut.SetCount(avpkt.size);
memcpy(BuffOut.GetData(), avpkt.data, avpkt.size);
}
av_free_packet(&avpkt);
size_t old_size = BuffIn.GetCount() * sizeof(float);
size_t new_size = BuffIn.GetCount() * sizeof(float) - m_framesize;
size_t new_count = new_size / sizeof(float);
memmove(pIn, (BYTE*)pIn + m_framesize, new_size);
BuffIn.SetCount(new_count);
return S_OK;
}
示例5: PutBytes
bool CJpegEncoderMem::PutBytes(const void* pData, int len)
{
CAtlArray<BYTE> moredata;
moredata.SetCount(len);
memcpy(moredata.GetData(), pData, len);
m_pdata->Append(moredata);
return true;
}
示例6: CreateSplineCoeffs
void Glyph::CreateSplineCoeffs(const CRect& spdrc)
{
spline.RemoveAll();
if (style.placement.path.IsEmpty()) {
return;
}
size_t i = 0, j = style.placement.path.GetCount();
CAtlArray<Point> pts;
pts.SetCount(j + 2);
Point p;
while (i < j) {
p.x = style.placement.path[i].x * scale.cx + spdrc.left * 64;
p.y = style.placement.path[i].y * scale.cy + spdrc.top * 64;
pts[++i] = p;
}
if (pts.GetCount() >= 4) {
if (pts[1].x == pts[j].x && pts[1].y == pts[j].y) {
pts.SetAt(0, pts[j - 1]);
pts.SetAt(j + 1, pts[2]);
} else {
p.x = pts[1].x * 2 - pts[2].x;
p.y = pts[1].y * 2 - pts[2].y;
pts.SetAt(0, p);
p.x = pts[j].x * 2 - pts[j - 1].x;
p.y = pts[j].y * 2 - pts[j - 1].y;
pts.SetAt(j + 1, p);
}
spline.SetCount(pts.GetCount() - 3);
for (size_t i = 0, j = pts.GetCount() - 4; i <= j; i++) {
static const float _1div6 = 1.0f / 6;
SplineCoeffs sc;
sc.cx[3] = _1div6 * (- pts[i + 0].x + 3 * pts[i + 1].x - 3 * pts[i + 2].x + pts[i + 3].x);
sc.cx[2] = _1div6 * (3 * pts[i + 0].x - 6 * pts[i + 1].x + 3 * pts[i + 2].x);
sc.cx[1] = _1div6 * (-3 * pts[i + 0].x + 3 * pts[i + 2].x);
sc.cx[0] = _1div6 * (pts[i + 0].x + 4 * pts[i + 1].x + 1 * pts[i + 2].x);
sc.cy[3] = _1div6 * (- pts[i + 0].y + 3 * pts[i + 1].y - 3 * pts[i + 2].y + pts[i + 3].y);
sc.cy[2] = _1div6 * (3 * pts[i + 0].y - 6 * pts[i + 1].y + 3 * pts[i + 2].y);
sc.cy[1] = _1div6 * (-3 * pts[i + 0].y + 3 * pts[i + 2].y);
sc.cy[0] = _1div6 * (pts[i + 0].y + 4 * pts[i + 1].y + 1 * pts[i + 2].y);
spline.SetAt(i, sc);
}
}
}
示例7: SortByPath
void CPlaylist::SortByPath()
{
CAtlArray<plsort2_t> a;
a.SetCount(GetCount());
POSITION pos = GetHeadPosition();
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].str = GetAt(pos).m_fns.GetHead(), a[i].pos = pos;
}
qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
}
示例8: Randomize
void CPlaylist::Randomize()
{
CAtlArray<plsort_t> a;
a.SetCount(GetCount());
srand((unsigned int)time(nullptr));
POSITION pos = GetHeadPosition();
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].n = rand(), a[i].pos = pos;
}
qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
}
示例9: OnApply
BOOL CPPageAccelTbl::OnApply()
{
AfxGetMyApp()->UnregisterHotkeys();
UpdateData();
AppSettings& s = AfxGetAppSettings();
s.wmcmds.RemoveAll();
s.wmcmds.AddTail(&m_wmcmds);
CAtlArray<ACCEL> pAccel;
pAccel.SetCount(m_wmcmds.GetCount());
POSITION pos = m_wmcmds.GetHeadPosition();
for (int i = 0; pos; i++) {
pAccel[i] = m_wmcmds.GetNext(pos);
}
if (s.hAccel) {
DestroyAcceleratorTable(s.hAccel);
}
s.hAccel = CreateAcceleratorTable(pAccel.GetData(), pAccel.GetCount());
GetParentFrame()->m_hAccelTable = s.hAccel;
s.fWinLirc = !!m_fWinLirc;
s.strWinLircAddr = m_WinLircAddr;
if (s.fWinLirc) {
s.WinLircClient.Connect(m_WinLircAddr);
}
s.fUIce = !!m_fUIce;
s.strUIceAddr = m_UIceAddr;
if (s.fUIce) {
s.UIceClient.Connect(m_UIceAddr);
}
s.fGlobalMedia = !!m_fGlobalMedia;
AfxGetMyApp()->RegisterHotkeys();
s.AccelTblColWidth.bEnable = true;
s.AccelTblColWidth.cmd = m_list.GetColumnWidth(COL_CMD);
s.AccelTblColWidth.key = m_list.GetColumnWidth(COL_KEY);
s.AccelTblColWidth.id = m_list.GetColumnWidth(COL_ID);
s.AccelTblColWidth.mwnd = m_list.GetColumnWidth(COL_MOUSE);
s.AccelTblColWidth.mfs = m_list.GetColumnWidth(COL_MOUSE_FS);
s.AccelTblColWidth.appcmd = m_list.GetColumnWidth(COL_APPCMD);
s.AccelTblColWidth.remcmd = m_list.GetColumnWidth(COL_RMCMD);
s.AccelTblColWidth.repcnt = m_list.GetColumnWidth(COL_RMREPCNT);
return __super::OnApply();
}
示例10: Shuffle
POSITION CPlaylist::Shuffle()
{
CAtlArray<plsort2_t> a;
a.SetCount(GetCount());
srand((unsigned)time(NULL));
POSITION pos = GetHeadPosition();
for(int i = 0; pos; i++, GetNext(pos))
a[i].pos = pos;
pos = GetPos();
int rnd = Rand(0, a.GetCount()-1);
while(pos == a[rnd].pos) rnd = Rand(0, a.GetCount()-1);
return a[rnd].pos;
}
示例11: SortByPath
void CPlaylist::SortByPath()
{
CAtlArray<plsort2_t> a;
a.SetCount(GetCount());
POSITION pos = GetHeadPosition();
for(int i = 0; pos; i++, GetNext(pos))
a[i].str = GetAt(pos).m_fns.GetHead(), a[i].pos = pos;
qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
for(int i = 0; i < a.GetCount(); i++)
{
AddTail(GetAt(a[i].pos));
__super::RemoveAt(a[i].pos);
if(m_pos == a[i].pos) m_pos = GetTailPosition();
}
}
示例12: SortByName
void CPlaylist::SortByName()
{
CAtlArray<plsort2_t> a;
a.SetCount(GetCount());
POSITION pos = GetHeadPosition();
for (int i = 0; pos; i++, GetNext(pos)) {
CString& fn = GetAt(pos).m_fns.GetHead();
a[i].str = (LPCTSTR)fn + std::max(fn.ReverseFind('/'), fn.ReverseFind('\\')) + 1;
a[i].pos = pos;
}
qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
}
示例13: SortById
void CPlaylist::SortById()
{
CAtlArray<plsort_t> a;
a.SetCount(GetCount());
POSITION pos = GetHeadPosition();
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].n = GetAt(pos).m_id, a[i].pos = pos;
}
qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
for (size_t i = 0; i < a.GetCount(); i++) {
AddTail(GetAt(a[i].pos));
__super::RemoveAt(a[i].pos);
if (m_pos == a[i].pos) {
m_pos = GetTailPosition();
}
}
}
示例14: Randomize
void CPlaylist::Randomize()
{
CAtlArray<plsort_t> a;
a.SetCount(GetCount());
srand((unsigned int)time(NULL));
POSITION pos = GetHeadPosition();
for(int i = 0; pos; i++, GetNext(pos))
a[i].n = rand(), a[i].pos = pos;
qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
CList<CPlaylistItem> pl;
for(int i = 0; i < a.GetCount(); i++)
{
AddTail(GetAt(a[i].pos));
__super::RemoveAt(a[i].pos);
if(m_pos == a[i].pos)
m_pos = GetTailPosition();
}
}
示例15: sizeof
HRESULT CDll_RS232::ReadBuffer( CAtlArray<BYTE> &buffer )
{
HRESULT hr = S_OK ;
if ( !m_bIsConnection ) return E_FAIL ;
OVERLAPPED ov ;
memset( &ov , 0 , sizeof( ov ) ) ;
ov.hEvent = CreateEvent( NULL , TRUE , NULL , NULL ) ;
DWORD dwRead , dwError ;
COMSTAT cs ;
memset( &cs , 0 , sizeof( cs ) ) ;
if ( !ClearCommError( m_hCommPort , &dwError , &cs ) ){
ATLASSERT( 0 ) ;
ATLTRACE( "Get count available bytes failed\r\n" ) ;
return E_FAIL ;
}
if ( cs.cbInQue == 0 ) {
CloseHandle( ov.hEvent ) ;
return S_OK ;
}
bool ok = buffer.SetCount( cs.cbInQue ) ;
ATLASSERT ( ok ) ;
BOOL bRet = ReadFile( m_hCommPort , buffer.GetData() , ( DWORD )buffer.GetCount() , &dwRead , &ov ) ;
if ( !bRet ){
if ( GetLastError() == ERROR_IO_PENDING ){
DWORD dwWait = WaitForSingleObject( ov.hEvent , INFINITE ) ;
ATLASSERT( dwWait == WAIT_OBJECT_0 ) ;
}else{
ATLASSERT( 0 ) ;
hr = E_FAIL ;
}
}
CloseHandle( ov.hEvent ) ;
return hr ;
}