int main(int argc, char *argv[])
{
    CQueue<int> q;
    q.appendTail(1);
    q.appendTail(2);

    cout << q.deleteHead() << endl;
    cout << q.deleteHead() << endl;
    q.appendTail(4);
    cout << q.deleteHead() << endl;
    // q.deleteHead();

    CStack<int> s;
    s.push(1);
    s.push(2);
    s.push(3);
    cout << s.top() << endl;
    s.pop();
    cout << s.top() << endl;
    s.pop();
    s.pop();
    // s.pop();

    return 0;
}
Example #2
0
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]);
}
Example #3
0
int main() {
    CStack<int> s;
    s.push(10);
    s.push(20);
    s.push(30);
    cout << s.size() << endl;
    cout << s.top() << endl;
    s.pop();
    s.pop();
    s.pop();
    cout << s.top() << endl;
}
Example #4
0
TEST_F(FFITest, CStackTooManyArgument) {
    // we assume this
    ASSERT_TRUE(sizeof(uint64_t) >= sizeof(intptr_t));

    CStack cstack;
    for (int i = 0; i < CStack::MAX_ARGC + CStack::MAX_REG; i++) {
        EXPECT_TRUE(cstack.push(Object::makeFixnum(3), CStack::SIGNATURE_INT));
    }
    const bool result = cstack.push(Object::makeFixnum(3), CStack::SIGNATURE_INT);
    EXPECT_FALSE(result);
    ucs4string err = cstack.getLastError();
    EXPECT_STREQ("too many ffi arguments", err.ascii_c_str());
}
Example #5
0
TEST_F(FFITest, CStackWithByteVector) {
    CStack cstack;
    Object b = Object::makeByteVector(2);
    ByteVector* const bv = b.toByteVector();
    bv->u8Set(0, 1);
    bv->u8Set(1, 2);
    cstack.push(b, CStack::SIGNATURE_POINTER);
    cstack.push("hige", CStack::SIGNATURE_POINTER);
    intptr_t* p = cstack.reg();
    EXPECT_EQ(2, cstack.regCount());
    EXPECT_EQ(1, ((uint8_t*)(p[0]))[0]);
    EXPECT_EQ(2, ((uint8_t*)(p[0]))[1]);
    EXPECT_STREQ("hige", (char*)p[1]);
}
Example #6
0
void MysqlThread::OnTerminate(IThreadHandle *pHandle, bool cancel)
{
	if (cancel)
	{
		Invalidate();
		g_QueueLock->Lock();
		g_FreeThreads.push(this);
		g_QueueLock->Unlock();
	} else {
		g_QueueLock->Lock();
		g_ThreadQueue.push(this);
		g_QueueLock->Unlock();
	}
}
Example #7
0
TEST_F(FFITest, CStackWithFixnum) {
    CStack cstack;
    EXPECT_TRUE(cstack.push(Object::makeFixnum(3), CStack::SIGNATURE_INT));
    EXPECT_TRUE(cstack.push(Object::makeFixnum(4), CStack::SIGNATURE_INT));
    EXPECT_TRUE(cstack.push(Object::makeFixnum(-5), CStack::SIGNATURE_INT));
    EXPECT_TRUE(cstack.push(Bignum::makeIntegerFromU32(0xffffffff), CStack::SIGNATURE_INT64));
    intptr_t* p = cstack.reg();
    EXPECT_EQ(4, cstack.regCount());
    EXPECT_EQ(3, p[0]);
    EXPECT_EQ(4, p[1]);
    EXPECT_EQ(-5, p[2]);
    const uint32_t x = 0xffffffff;
    const uint32_t y = p[3];
    EXPECT_EQ(x, y);
}
Example #8
0
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
}
Example #9
0
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);
}
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;
}
Example #11
0
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();
}
Example #12
0
static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
{
	GETMENU_R(params[1]);

	if (pMenu->isDestroying)
	{
		return 0;	//prevent infinite recursion
	}

	pMenu->isDestroying = true;

	CPlayer *player;
	for (int i=1; i<=gpGlobals->maxClients; i++)
	{
		player = GET_PLAYER_POINTER_I(i);
		if (player->newmenu == pMenu->thisId)
		{
			pMenu->Close(player->index);
		}
	}
	g_NewMenus[params[1]] = NULL;
	delete pMenu;
	g_MenuFreeStack.push(params[1]);

	return 1;
}
Example #13
0
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]);
}
Example #14
0
int main()
{
   CStack s;

   s.print();

   s.push(5);
   s.push(10);
   s.push(8);

   s.print();

   cout << "top of stack = " << s.pop() << endl;

   s.print();

   return 0;
}
Example #15
0
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());
}
Example #16
0
void CurlThread::OnTerminate(IThreadHandle* pHandle, bool cancel) {
    if (!cancel) {
        g_QueueLock->Lock();
        g_ThreadQueue.push(this);
        g_QueueLock->Unlock();
    } else {
        delete curl_;
    }
}
Example #17
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;
}
Example #18
0
static cell AMX_NATIVE_CALL free_tr2(AMX *amx, cell *params)
{
    TraceResult *tr = reinterpret_cast<TraceResult *>(params[1]);
    if (!tr)
    {
        return 0;
    }

    g_FreeTRs.push(tr);

    return 1;
}
Example #19
0
// nothing interesting
int main() {
	CStack stack;

	stack.push(13);
	stack.push(17);
	stack.print();

	int taken_val;
	
	taken_val = stack.pop();
	printf("Taken value: %d\n", taken_val);
	stack.print();
	
	return 0;
}
Example #20
0
int main(int argc, char* argv[])
{
	CStack s;
	int i = 0, t;
	while(i < 10)
		s.push(i++);
	i = 0;
	while(s.pop(t))
	{
		if(s.isEmpty() == true)
			break;
		cout << t << endl;
	}

	return 0;
}
Example #21
0
void ParseAndOrAdd(CStack<ke::AString *> & files, const char *name)
{
	if (strncmp(name, "plugins-", 8) == 0)
	{
#if !defined WIN32
		size_t len = strlen(name);
		if (strcmp(&name[len-4], ".ini") == 0)
		{
#endif
			ke::AString *pString = new ke::AString(name);
			files.push(pString);
#if !defined WIN32
		}
#endif
	}
}
Example #22
0
bool UsrMessageNatives::DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter)
{
	MsgWrapperList *pList;
	MsgListenerWrapper *pListener;
	IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());

	if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
	{
		return false;
	}

	pListener = (*iter);
	pList->erase(iter);
	m_FreeListeners.push(pListener);

	return true;
}
Example #23
0
/*
 *test the template 
 * */
int main(int argc, char **argv)
{
    CStack<CMsg> msgStack;
    int i;
    CMsg msg[10];
    CMsg msgPop;
    for (i = 0; i < 10; i++ )
    {
        msg[i].msgNo = i;
        msg[i].msgInfo = "I am ready!";
        msgStack.push(msg[i]);
    }
    
    while(i-- > 0)
    {
        msgStack.pop(msgPop);
        cout<<"msgStack:"<<"msgNo-"<<msgPop.msgNo<<" "<<"msgInfo '"<<msgPop.msgInfo<<"'"<<endl;
    }
    return 1;
}
Example #24
0
int main()
{
	CStack stack; // Default constructor is called.  Our stack will be 
				 // kDefaultStackSize (10) elements large.

	// Let's push some integers (0, 1, 2, 3, 4) on the stack
	for(int i = 0; i < 5; i++)
		stack.push(i);

	// Now lets pop all the elements off of the stack printing each one 
	// as they come off
	while(stack.isEmpty() == false)
	{
		cout << "Top = " << stack.getTop() << endl;
		stack.pop();
	}
	
	return EXIT_SUCCESS;

} // end of main()
Example #25
0
void UsrMessageNatives::OnPluginUnloaded(IPlugin *plugin)
{
	MsgWrapperList *pList;

	if (plugin->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList), true))
	{
		MsgWrapperIter iter;
		MsgListenerWrapper *pListener;

		for (iter=pList->begin(); iter!=pList->end(); iter++)
		{
			pListener = (*iter);
			if (g_UserMsgs.UnhookUserMessage(pListener->GetMessageId(), pListener, pListener->IsInterceptHook()))
			{
				m_FreeListeners.push(pListener);
			}
		}

		delete pList;
	}
}
Example #26
0
// Check if the parenthesis in an expression are balanced
// PRE: str points to the expression to check
// POST: returns 1 if balanced, otherwise returns 0
bool CheckParens(const char* str) {
	CStack stack;		// Stack used for balance checking
	char temp[2];		// String used to push the parens on the stack

	// Loop through pushing lefts and popping/comparing rights
	temp[1]=0;
	for(int x=0;str[x];x++) {
		*temp=str[x];
		if(isLeftParen(*temp)) {
			stack.push(temp);
		} else if(isRightParen(*temp)) {
			if(stack.empty() || getRightParen(stack.pop()[0])!=*temp)
				return 0;
		}
	}

	// If the stack isn't empty, parens aren't balanced
	if(stack.empty())
		return 1;
	else
		return 0;
}
Example #27
0
TEST_F(FFITest, CStackWithFlonum) {
    CStack cstack;
    // use sse registers
    EXPECT_TRUE(cstack.push(Object::makeFlonum(1.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(2.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(3.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(4.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(5.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(6.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(7.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(8.0), CStack::SIGNATURE_DOUBLE));

    // use stack
    EXPECT_TRUE(cstack.push(Object::makeFlonum(9.0), CStack::SIGNATURE_DOUBLE));
    EXPECT_TRUE(cstack.push(Object::makeFlonum(10.0), CStack::SIGNATURE_DOUBLE));

    EXPECT_EQ(2, cstack.count());
    double* p = (double*)cstack.frame();
    EXPECT_DOUBLE_EQ(9.0, p[0]);
    EXPECT_DOUBLE_EQ(10.0, p[1]);
}
Example #28
0
// Solve a postfix expression
// PRE: expr is the postfix expression to solve
// POST: answer is the answer, returns 1 if
//       successful, otherwise returns 0
bool SolvePostfix(const char* expr,double &answer) {
	int x,y;					// Index variables
	double right,left;			// Right and left parts of the value
	char str[MAX_LENGTH+1];		// String for number to string conversion
	char ch;					// Temporary char to hold expr[x] etc
	CStack stack;				// The stack to hold the values

	// Loop through the postfix expression
	for(x=0;x<signed(strlen(expr));x++) {
		ch=expr[x];

		// If we have an operator, set up left/right
		if(isOperator(ch)) {
			right=atof(stack.pop());
			if(stack.empty()) {
				break;
			} else {
				left=atof(stack.pop());
			}
		}

		// Do an operation or push a number
		switch(ch) {
		case '+':
			sprintf(str,"%lf",left+right);
			stack.push(str);
			break;
		case '-':
			sprintf(str,"%lf",left-right);
			stack.push(str);
			break;
		case '*':
			sprintf(str,"%lf",left*right);
			stack.push(str);
			break;
		case '/':
			if(!right)
				break;
			sprintf(str,"%lf",left/right);
			stack.push(str);
			break;
		case '^':
			sprintf(str,"%lf",pow(left,right));
			stack.push(str);
			break;
		case ' ':		// Skip white space and various delimiters
		case ',':
		case '\t':
		case '\n':
			break;
		default:	// Number (hopefully)
			for(y=0;y<=MAX_LENGTH && expr[x];y++,x++) {
				if(!isNumber(expr[x])) {
					--x;		// Revisit this character
					break;
				}
				str[y]=expr[x];
			}
			if(!y) {	// Bad input
				return 0;
			}
			str[y]=0;
			stack.push(str);
			break;
		}
	}

	// If the stack is empty, no answer!
	if(stack.empty())
		return 0;
	else
		answer=atof(stack.pop());

	// If the stack is not empty, too few operations
	if(!stack.empty())
		return 0;

	return 1;
}
Example #29
0
void CPluginMngr::CacheAndLoadModules(const char *plugin)
{
	size_t progsize;
	char *prog = ReadIntoOrFromCache(plugin, progsize);

	if (!prog)
		return;

	AMX_HEADER hdr;
	memcpy(&hdr, prog, sizeof(AMX_HEADER));

	uint16_t magic = hdr.magic;
	amx_Align16(&magic);

	if (magic != AMX_MAGIC)
	{
		return;
	}

	if (hdr.file_version < MIN_FILE_VERSION ||
		hdr.file_version > CUR_FILE_VERSION)
	{
		return;
	}
	if ((hdr.defsize != sizeof(AMX_FUNCSTUB)) &&
		(hdr.defsize != sizeof(AMX_FUNCSTUBNT)))
	{
		return;
	}

	amx_Align32((uint32_t*)&hdr.nametable);
	uint16_t *namelength=(uint16_t*)((unsigned char*)prog + (unsigned)hdr.nametable);
	amx_Align16(namelength);
	if (*namelength>sNAMEMAX)
	{
		return;
	}

	if (hdr.stp <= 0)
	{
		return;
	}

	AMX amx;
	memset(&amx, 0, sizeof(AMX));
	amx.base = (unsigned char *)prog;

	int num;
	char name[sNAMEMAX+1];

	num = amx_GetLibraries(&amx);
	for (int i=0; i<num; i++)
	{
		amx_GetLibrary(&amx, i, name, sNAMEMAX);
		if (stricmp(name, "Float")==0)
			continue;
		//awful backwards compat hack
		if (stricmp(name, "socket")==0)
			strcpy(name, "sockets");
		//we don't want to report failed modules here...
		LoadModule(name, PT_ANYTIME, true, true);
	}

	cell tag_id;
	amx_NumTags(&amx, &num);

	ke::Vector<LibDecoder *> expects;
	ke::Vector<LibDecoder *> defaults;
	CStack<LibDecoder *> delstack;
	for (int i=0; i<num; i++)
	{
		amx_GetTag(&amx, i, name, &tag_id);
		if (name[0] == '?')
		{
			LibDecoder *dc = new LibDecoder;
			delstack.push(dc);
			if (DecodeLibCmdString(name, dc))
			{
				if (dc->cmd == LibCmd_ForceLib)
				{
					RunLibCommand(dc);
				} else if ( (dc->cmd == LibCmd_ExpectClass) ||
							(dc->cmd == LibCmd_ExpectLib) )
				{
					expects.append(dc);
				} else if (dc->cmd == LibCmd_DefaultLib) {
					defaults.append(dc);
				}
			}
		}
	}

	for (size_t i=0; i<expects.length(); i++)
	{
		RunLibCommand(expects[i]);
	}
	for (size_t i=0; i<defaults.length(); i++)
	{
		RunLibCommand(defaults[i]);
	}

	expects.clear();
	defaults.clear();

	while (!delstack.empty())
	{
		delete delstack.front();
		delstack.pop();
	}

	return;
}
Example #30
0
void TimerNatives::DeleteTimerInfo(TimerInfo *pInfo)
{
	m_FreeTimers.push(pInfo);
}