int main() { try{ CQueue<int> cq; for(int i = 0; i < 10; i++) cq.appendTail(i); for(int i = 0; i < 10; i++) cout << cq.deleteHead() << ' '; cout << endl; cq.deleteHead(); } catch(exception &e) { cerr << e.what() << endl; } try{ CStack<int> cs; for(int i = 0; i < 10; i++) cs.push(i); for(int i = 0; i < 10; i++) cout << cs.pop() << ' '; cout << endl; cs.pop(); } catch(exception &e) { cerr << e.what() << endl; } return 0; }
//--------------------------------------------------------------------------- // @function: // CStackTest::EresUnittest_Pop // // @doc: // This test should assert. // //--------------------------------------------------------------------------- GPOS_RESULT CStackTest::EresUnittest_Pop() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); ULONG rgsz[] = {1, 2, 3, 4}; CStack<ULONG> *pstk = GPOS_NEW(pmp) CStack<ULONG> (pmp, 4); CAutoP<CStack<ULONG> > cAP; cAP = pstk; // add elements incl trigger resize of array for (ULONG i = 0; i < 4; i++) { pstk->Push(&rgsz[i]); GPOS_ASSERT( (* pstk->Peek()) == 4 - i); GPOS_ASSERT(pstk->Pop() == &rgsz[i]); } // now deliberately pop when the stack is empty pstk->Pop(); return GPOS_FAILED; }
float CDeck::InitEmptyCells(float delayPerLetter) { float currentDelay = 0.0f; for (int i=0; i<m_Letters.size(); i++) { if (m_Letters[i] == NULL) { CStack * stack = CGameScene::Instance()->GetCurrentRoom()->GetStack(); if(stack->IsEmpty()) { return currentDelay; } CLetter * letter = stack->GetLetterFromStack(); addChild(letter,CLetter::STAY_LAYER); float scale = 0.45; Point pos = Point(CELL_OFFSET_X+(CELL_SIZE_X/2),CELL_OFFSET_Y+(CELL_SIZE_Y/2)); letter->setPosition(pos.x + i*CELL_SIZE_X,pos.y); letter->SetDeckCell(i); letter->SetLastPosType(CLetter::LPT_DECK); m_Letters[i] = letter; currentDelay += delayPerLetter; letter->ShowAction(currentDelay); } } return currentDelay; }
void CProceso::PrvInstIntAFloat(CProceso* const pProceso) { CStack* pStack = &pProceso->m_Stack; long int_value = pStack->PopInt(); float float_value = (float) int_value; pStack->PushFloat(float_value); }
//Makes a new menu handle (-1 for failure) //native csdm_makemenu(title[]); static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params) { int len; char *title = get_amxstring(amx, params[1], 0, len); validate_menu_text(title); char *handler = get_amxstring(amx, params[2], 1, len); int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE); if (func == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Invalid function \"%s\"", handler); return 0; } Menu *pMenu = new Menu(title, amx, func); if (g_MenuFreeStack.empty()) { g_NewMenus.append(pMenu); pMenu->thisId = (int)g_NewMenus.length() - 1; } else { int pos = g_MenuFreeStack.front(); g_MenuFreeStack.pop(); g_NewMenus[pos] = pMenu; pMenu->thisId = pos; } return pMenu->thisId; }
static void PlayMenuMovie (void) { int h, i, j; CStack<char*> m; char* ps; CListBox lb; i = movieManager.m_nLibs; for (h = j = 0; j < i; j++) if (j != 2) //skip robot movies h += movieManager.m_libs [j].m_nMovies; if (!h) return; if (!m.Create (h)) return; for (i = j = 0; i < h; i++) if ((ps = movieManager.Cycle (i == 0, 0))) { if (j && !strcmp (ps, m [0])) break; m.Push (ps); } i = lb.ListBox (TXT_SELECT_MOVIE, m); if (i > -1) { SDL_ShowCursor (0); if (strstr (m [i], "intro")) subTitles.Init ("intro.tex"); else if (strstr (m [i], ENDMOVIE)) subTitles.Init (ENDMOVIE ".tex"); movieManager.Play (m [i], 1, 1, gameOpts->movies.bResize); subTitles.Close (); SDL_ShowCursor (1); } songManager.PlayCurrent (1); }
static void PlayMenuSong (void) { int h, i; CStack<char*> m (MAX_NUM_SONGS + 2); CFile cf; char szSongTitles [2][14] = {"- Descent 2 -", "- Descent 1 -"}; CListBox lb; m.Push (szSongTitles [0]); for (i = 0; i < songManager.TotalCount (); i++) { if (cf.Open (reinterpret_cast<char*> (songManager.SongData (i).filename), gameFolders.szDataDir, "rb", i >= songManager.Count (0))) { cf.Close (); if (i == songManager.Count (0)) m.Push (szSongTitles [1]); m.Push (songManager.SongData (i).filename); } } for (;;) { h = lb.ListBox (TXT_SELECT_SONG, m); if (h < 0) return; if (!strstr (m [h], ".hmp")) continue; for (i = 0; i < songManager.TotalCount (); i++) if (songManager.SongData (i).filename == m [h]) { songManager.Play (i, 0); return; } } }
void CProceso::PrvInstFloatAInt(CProceso* const pProceso) { CStack* pStack = &pProceso->m_Stack; float float_value = pStack->PopFloat(); long int_value = (long) float_value; pStack->PushInt(int_value); }
void CConParser::getLabeledBrackets(const CSentenceParsed &parse_tree, CStack<CLabeledBracket> &brackets) { std::vector<CLabeledBracket> vec; unsigned i; unsigned begin, end; unsigned long constituent; brackets.clear(); for (i=0; i<parse_tree.nodes.size(); ++i) { const CCFGTreeNode &node = parse_tree.nodes[i]; if (!node.is_constituent) { begin = node.token; end = begin; } else { begin = vec[node.left_child].begin; if (node.right_child == -1) end = vec[node.left_child].end; else end = vec[node.right_child].end; } #ifdef NO_TEMP_CONSTITUENT constituent = node.constituent; #else constituent = CConstituent::encodeTmp(node.constituent.code(), node.temp); #endif vec.push_back(CLabeledBracket(begin, end, constituent)); if (node.is_constituent) brackets.push(vec.back()); } //for }
void CDeck::InitEmptyCells() { for (int i=0; i<m_Letters.size(); i++) { if (m_Letters[i] == NULL) { CStack * stack = CGameScene::Instance()->GetCurrentRoom()->GetStack(); if(stack->IsEmpty()) { return; } CLetter * letter = stack->GetLetterFromStack(); //CGameScene::Instance()->addChild(letter); addChild(letter,CLetter::STAY_LAYER); float scale = 0.45; Point pos = Point(CELL_OFFSET_X+(CELL_SIZE_X/2),CELL_OFFSET_Y+(CELL_SIZE_Y/2)); letter->setPosition(pos.x + i*CELL_SIZE_X,pos.y); //letter->setOpacity(0); //letter->setScale(0.2f); letter->SetDeckCell(i); letter->SetLastPosType(CLetter::LPT_DECK); m_Letters[i] = letter; //letter->ShowAction(); /* auto scaleAction = CCScaleTo::create(0.5f,scale,scale); auto showAction = CCFadeIn::create(0.3f); auto spawn = Spawn::create(scaleAction,NULL); letter->runAction(spawn);*/ } } ShowLetters(); }
void StartFrame() { if (g_pWorker && (g_lasttime < gpGlobals->time)) { g_lasttime = gpGlobals->time + 0.05f; g_QueueLock->Lock(); size_t remaining = g_ThreadQueue.size(); if (remaining) { MysqlThread *kmThread; do { kmThread = g_ThreadQueue.front(); g_ThreadQueue.pop(); g_QueueLock->Unlock(); kmThread->Execute(); kmThread->Invalidate(); g_FreeThreads.push(kmThread); g_QueueLock->Lock(); } while (!g_ThreadQueue.empty()); } g_QueueLock->Unlock(); } RETURN_META(MRES_IGNORED); }
CPartContents* CPart::GetContentsOnCurrentCard() { CPartContents* contents = NULL; CStack * currStack = GetStack(); if( !currStack ) return NULL; CCard * currCard = currStack->GetCurrentCard(); if( !currCard ) return NULL; bool isBgPart = dynamic_cast<CBackground*>(mOwner) != NULL; bool bgPartWithNonSharedText = (isBgPart && !GetSharedText()); if( isBgPart && !GetSharedText() ) // We're on the background layer, not on the card, and don't have shared text? { contents = currCard->GetPartContentsByID( GetID(), isBgPart ); } else { contents = mOwner->GetPartContentsByID( GetID(), isBgPart ); } if( !contents ) { contents = new CPartContents( currCard ); contents->SetID( mID ); contents->SetIsOnBackground( isBgPart ); if( bgPartWithNonSharedText ) currCard->AddPartContents( contents ); else mOwner->AddPartContents( contents ); } return contents; }
void OnPluginsUnloading() { if (!g_pWorker) { return; } g_pWorker->Stop(false); delete g_pWorker; g_pWorker = NULL; g_QueueLock->Lock(); size_t remaining = g_ThreadQueue.size(); if (remaining) { MysqlThread *kmThread; do { kmThread = g_ThreadQueue.front(); g_ThreadQueue.pop(); g_QueueLock->Unlock(); kmThread->Execute(); kmThread->Invalidate(); g_FreeThreads.push(kmThread); g_QueueLock->Lock(); } while (!g_ThreadQueue.empty()); } g_QueueLock->Unlock(); }
CStack* CDocument::AddNewStack( std::string inStackName ) { ObjectID stackID = GetUniqueIDForStack(); std::stringstream fileName; fileName << "stack_" << stackID << ".xml"; std::string stackURL = mURL; if( stackURL[stackURL.length()-1] != '/' ) stackURL.append( 1, '/' ); stackURL.append( fileName.str() ); if( inStackName.size() == 0 ) { std::stringstream nameForUser; nameForUser << "Stack " << mStacks.size() +1; inStackName = nameForUser.str(); } CStack * theStack = NewStackWithURLIDNameForDocument( stackURL, stackID, inStackName, fileName.str(), this ); theStack->AddNewCardWithBackground(); theStack->SetLoaded(true); mStacks.push_back( theStack ); theStack->Release(); IncrementChangeCount(); return theStack; }
CValue CallFunction( CScope& scope, CStack& stack, const CSourceLocation& location, const std::string& symbol, const std::vector<CValue>& argValues) { // Analyze function value. CValue functionValue = scope.GetValue(symbol, location, stack); if (!IsFunction(functionValue)) { throw ExScopeSymbolIsNotFunction{ location, stack }; } if (argValues.size() > functionValue.GetFuncArity()) { throw ExScopeFormalActualArgCountMismatch{ location, stack }; } // Analyze function definition. const auto& functionDef = functionValue.GetFuncDef(); const auto& captures = functionValue.GetFuncCaptures(); auto applArgs = functionValue.GetAppliedArgs(); std::copy(begin(argValues), end(argValues), std::back_inserter(applArgs)); if (argValues.size() < functionValue.GetFuncArity()) { // "Curry on"... return CValue::MakeFunction(&functionDef, captures, applArgs); } // Call function const auto& argNames = functionDef.GetFormalArgs(); const auto& argLocations = functionDef.GetArgLocations(); assert(argNames.size() == argLocations.size()); unsigned argsCount = argNames.size(); CLocalScope funcScope{ scope.GetGlobalScope() }; for (unsigned i = 0; i < argsCount; ++i) { funcScope.TryRegisteringBind( stack, argNames[i], applArgs[i], argLocations[i]); } for (const auto& pr : captures) { funcScope.TryRegisteringBind( stack, pr.first, pr.second.value, pr.second.location); } stack.PushCall(symbol); CValue result = functionDef.Execute(funcScope, stack); stack.PopCall(); return result; }
void CProceso::PrvInstDivInt(CProceso* const pProceso) { CStack* pStack = &pProceso->m_Stack; long int_value2 = pStack->PopInt(); long int_value1 = pStack->PopInt(); long int_value = int_value1 / int_value2; pStack->PushInt(int_value); }
void CProceso::PrvInstDivFloat(CProceso* const pProceso) { CStack* pStack = &pProceso->m_Stack; float float_value2 = pStack->PopFloat(); float float_value1 = pStack->PopFloat(); float float_value = float_value1 / float_value2; pStack->PushFloat(float_value); }
void OnAmxxDetach() { while (!g_FreeTRs.empty()) { delete g_FreeTRs.front(); g_FreeTRs.pop(); } }
TEST_F(FFITest, CStackUnsupportedArgument) { // we assume this ASSERT_TRUE(sizeof(uint64_t) >= sizeof(intptr_t)); CStack cstack; const bool result = cstack.push(Object::makeEqHashTable(), CStack::SIGNATURE_INT); EXPECT_FALSE(result); ucs4string err = cstack.getLastError(); EXPECT_STREQ("unsupported ffi argument", err.ascii_c_str()); }
TEST_F(FFITest, CStackWithString) { CStack cstack; cstack.push(Object::makeFixnum(3), CStack::SIGNATURE_INT); cstack.push("hige", CStack::SIGNATURE_POINTER); intptr_t* p = cstack.reg(); EXPECT_EQ(2, cstack.regCount()); EXPECT_EQ(3, p[0]); EXPECT_STREQ("hige", (char*)p[1]); }
TEST_F(FFITest, CStackWithFlonum) { CStack cstack; EXPECT_TRUE(cstack.push(Object::makeFlonum(3.0), CStack::SIGNATURE_DOUBLE)); EXPECT_TRUE(cstack.push(Object::makeFlonum(2.0), CStack::SIGNATURE_DOUBLE)); double* p = (double*)cstack.frame(); EXPECT_EQ(4, cstack.count()); EXPECT_DOUBLE_EQ(3.0, p[0]); EXPECT_DOUBLE_EQ(2.0, p[1]); }
void CProceso::PrvInstIsZeroInt(CProceso* const pProceso) { CStack* pStack = &pProceso->m_Stack; long int_value = pStack->PopInt(); int_value = !int_value; //Si es igual a 0, la negación va a dar distinto de cero (verdadero), sino 0 (falso) pStack->PushInt(int_value); }
//Вывод стека void output(CStack* Sequence) { CStack* Temp = new CStack; while( Sequence->Size() != 0 ) Temp->Push_Back(Sequence->Pop_Back()); while( Temp->Size() != 0 ) printf("%c",Temp->Pop_Back()); putchar('\n'); }
int main() { CStack* myStack = new CStack(); cout << "myStack->Top(): " << myStack->Top() << endl; Node* NodeA = new Node(); NodeA->data = 99; myStack->Push(NodeA); Node* NodeB = myStack->Top(); cout << "myStack->Top(): " << NodeB->data << endl; }
//Получение данных CStack* input() { char c; CStack *temp = new (CStack); while( (c=getchar()) != '\n' ) { temp->Push_Back(c); } return temp; }
int main(void) { int iNum = 2196; int iD = 16; int iLen = 10; cout<<iNum<<"的"<<iD<<"进制数为: "<<Conversion(iNum, iD)<<endl; CStack<float> cfs; for(int i=0; i<iLen; i++) cfs.Push(i*3.02+2.08); cfs.Display(); cout<<"=====================Hanoi move game======================"<<endl; Hanoi(5, 'x', 'y', 'z'); CStack<float> cft( cfs ); cout<<"复制构造:"<<endl; cft.Display(); cft.Clear(); cft.Push( 3.9 ); cft.Display(); cfs.Display(); cout<<"赋值运算符:"<<endl; CStack<float> cfb = cfs; cfb.Display(); cout<<"cfb pop: "<<cfb.Pop()<<endl; cfb.Display(); cfb = cfs; cfb.Display(); return 0; }
int main() { int temp; CStack s; s.push(10); s.push(15); s.add(); s.pop(temp); printf("%d, %d\n",temp, s.GetNumb()); return 0; }
CScriptableObject* CDocument::GetParentObject( CScriptableObject* previousParent, LEOContext * ctx ) { CScriptableObject * frontObj = GetNextFrontScript( ctx ); if( frontObj ) // We're doing frontscripts? return frontObj; // Return next frontscript, not our parent. if( previousParent ) { CStack* stackForwardingToUs = dynamic_cast<CStack*>(previousParent); if( stackForwardingToUs ) { if( stackForwardingToUs->GetShouldForwardToMainStack() ) // Make messages sent from palettes continue to document window. { CStack * currentMainStack = CStack::GetMainStack(); if( currentMainStack && currentMainStack != stackForwardingToUs && currentMainStack->GetScriptContextGroupObject() == GetScriptContextGroupObject() ) { CCard * currentCard = currentMainStack->GetCurrentCard(); if( currentCard ) { return currentCard; } } } } } // Forward message to home stack's document for a last shot: CDocumentRef homeDocument = CDocumentManager::GetSharedDocumentManager()->GetHomeDocument(); if( homeDocument != this && homeDocument != nullptr && homeDocument->GetScriptContextGroupObject() == GetScriptContextGroupObject() ) { std::cout << " -> (" << homeDocument->GetObjectDescriptorString() << ")" << std::endl; return homeDocument; } // Still nothing? We're at end. See if there are any back scripts: if( ctx ) { CScriptContextUserData * ud = (CScriptContextUserData *)ctx->userData; CScriptContextGroupUserData * gud = (CScriptContextGroupUserData *)ctx->group->userData; if( !gud->mBackScripts.empty() ) { assert(ud->GetCurrentBackScript() == nullptr); assert(ud->GetCurrentFrontScript() == nullptr); CScriptableObject * obj = gud->mBackScripts.front(); ud->SetCurrentBackScript(obj); return obj; } } return nullptr; }
void ClearMenus() { for (size_t i = 0; i < g_NewMenus.length(); i++) { delete g_NewMenus[i]; } g_NewMenus.clear(); while (!g_MenuFreeStack.empty()) { g_MenuFreeStack.pop(); } }
static cell AMX_NATIVE_CALL create_tr2(AMX *amx, cell *params) { TraceResult *tr; if (g_FreeTRs.empty()) { tr = new TraceResult; } else { tr = g_FreeTRs.front(); g_FreeTRs.pop(); } memset(tr, 0, sizeof(TraceResult)); return reinterpret_cast<cell>(tr); }