Exemple #1
0
 int getMin() {
     return min.top();
 }
Exemple #2
0
void build_ListCallback(RDIR *rdir, EListCallbackArg arg)
{
   const char *fname = retro_dirent_get_name(rdir);

	if(arg == EListCallbackArg_Pop) 
	{
		currPath = pathStack.top();
		pathStack.pop();
		currVirtPath = virtPathStack.top();
		virtPathStack.pop();
		return;
	}
	
   if (retro_dirent_is_dir(rdir))
	{
		if(!strcmp(fname,".")) return;
		if(!strcmp(fname,"..")) return;

		pathStack.push(currPath);
		virtPathStack.push(currVirtPath);

		currVirtPath = currVirtPath + "/" + fname;
		bool ok = LIBFAT::MkDir(currVirtPath.c_str());

		if(!ok)
			printf("ERROR adding dir %s via libfat\n",currVirtPath.c_str());

		currPath = currPath + path_default_slash() + fname;
		return;
	}
	else
	{
		std::string path = currPath + path_default_slash() + fname;

		FILE* inf = fopen(path.c_str(),"rb");
		if(inf)
		{
			u8 * buf;
			size_t elements_read;
			long len;

			fseek(inf, 0, SEEK_END);
			len = ftell(inf);
			fseek(inf, 0, SEEK_SET);
			buf = new u8[len];
			elements_read = fread(buf, 1, len, inf);
			if (elements_read != len)
				printf(
					"libfat:  %lu bytes read instead of %l.\n",
					elements_read,
					len
				);
			fclose(inf);

			std::string path = currVirtPath + "/" + fname;
         printf("FAT + (%10.2f KB) %s \n",len/1024.f,path.c_str());
			bool ok = LIBFAT::WriteFile(path.c_str(),buf,len);
			if(!ok) 
				printf("ERROR adding file to fat\n");
			delete[] buf;
		} else printf("ERROR opening file for fat\n");
	}
}
Exemple #3
0
//-----------------------------------------------------------------------------
// WM_COMMAND メッセージ処理
//-----------------------------------------------------------------------------
LRESULT OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
	WORD wNotifyCode = HIWORD(wParam);
	WORD wID = LOWORD(wParam);
	HWND hwndCtl = (HWND)lParam;

	int fixed = 0;

	switch (wID) {
		case ID__1:
			fixed = 1;
			break;
		case ID__2:
			fixed = 2;
			break;
		case ID__3:
			fixed = 3;
			break;
		case ID__4:
			fixed = 4;
			break;
		case ID__5:
			fixed = 5;
			break;
		case ID__6:
			fixed = 6;
			break;
		case ID__7:
			fixed = 7;
			break;
		case ID__8:
			fixed = 8;
			break;
		case ID__9:
			fixed = 9;
			break;
		case ID__0:
			fixed = 0;
			break;
		case IDM_GAME_INIT:
			return OnGameInit(hwnd, wParam, lParam);
			
		case IDM_GAME_OPEN:
			return OnGameOpen(hwnd, wParam, lParam);

		case ID_GAME_PARSE:
			if (g_game.Reparse() == 0) {
				MessageBox(hwnd, _T("手詰まりです"), _T("数独サポート"), MB_OK);
			}
			InvalidateRect(hwnd, NULL, FALSE);
			return 0;

		case ID_GAME_PARSE_ALL:
			g_game.ReparseAll();
			InvalidateRect(hwnd, NULL, FALSE);
			if (g_game.IsFinished()) {
				MessageBox(hwnd, _T("解けました"), _T("数独サポート"), MB_OK);
			} else {
				MessageBox(hwnd, _T("手詰まりです"), _T("数独サポート"), MB_OK);
			}

			return 0;

		case ID_GAME_TOTAL:
			if (SoAtari(hwnd)) {
				InvalidateRect(hwnd, NULL, FALSE);
				MessageBox(hwnd, _T("解けました"), _T("数独サポート"), MB_OK);
			} else {
				MessageBox(hwnd, _T("やっぱり手詰まりです"), _T("数独サポート"), MB_OK);
			}
			return 0;

		case IDM_GAME_EXIT:
			DestroyWindow(hwnd);
			return 0;

		case ID_HELP_ABOUT:
			DialogBox(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDD_ABOUT), hwnd, About_DlgProc);
			return 0;
	}

	if (fixed != 0) {
		g_gameStack.push(g_game);
		g_game.FixCell(g_yCell, g_xCell, fixed);
		g_game.ReparseStart();
	} else {
		g_game = g_gameStack.top();
		g_gameStack.pop();
		g_game.ReparseStart();
	}

	if (g_game.IsFinished()) {
		MessageBox(hwnd, _T("解けました"), _T("数独サポート"), MB_OK);
	}

	InvalidateRect(hwnd, NULL, FALSE);

	return 0;
}
Exemple #4
0
 void visit(const CallStmt *op) {
   simit_iassert(functionStack.size() > 0);
   addReverseEdge(functionStack.top(), op->callee);
   op->callee.accept(this);
 }
Exemple #5
0
  /**
   * Check whether the specified dialog is the top-most one.
   */
  bool IsTopDialog(WndForm &dialog) {
    assert(HasDialog());

    return &dialog == dialogs.top();
  }
 void TransformPop() { m_mtx=m_transformStack.top(); m_transformStack.pop(); }
    void endElement(void *ctx, const char *name)
    {
        CC_UNUSED_PARAM(ctx);
        SAXState curState = _stateStack.empty() ? SAX_DICT : _stateStack.top();
        const std::string sName((char*)name);
        if( sName == "dict" )
        {
            _stateStack.pop();
            _dictStack.pop();
            if ( !_dictStack.empty())
            {
                _curDict = _dictStack.top();
            }
        }
        else if (sName == "array")
        {
            _stateStack.pop();
            _arrayStack.pop();
            if (! _arrayStack.empty())
            {
                _curArray = _arrayStack.top();
            }
        }
        else if (sName == "true")
        {
            if (SAX_ARRAY == curState)
            {
                _curArray->push_back(Value(true));
            }
            else if (SAX_DICT == curState)
            {
                (*_curDict)[_curKey] = Value(true);
            }
        }
        else if (sName == "false")
        {
            if (SAX_ARRAY == curState)
            {
                _curArray->push_back(Value(false));
            }
            else if (SAX_DICT == curState)
            {
                (*_curDict)[_curKey] = Value(false);
            }
        }
        else if (sName == "string" || sName == "integer" || sName == "real")
        {
            if (SAX_ARRAY == curState)
            {
                if (sName == "string")
                    _curArray->push_back(Value(_curValue));
                else if (sName == "integer")
                    _curArray->push_back(Value(atoi(_curValue.c_str())));
                else
                    _curArray->push_back(Value(utils::atof(_curValue.c_str())));
            }
            else if (SAX_DICT == curState)
            {
                if (sName == "string")
                    (*_curDict)[_curKey] = Value(_curValue);
                else if (sName == "integer")
                    (*_curDict)[_curKey] = Value(atoi(_curValue.c_str()));
                else
                    (*_curDict)[_curKey] = Value(utils::atof(_curValue.c_str()));
            }

            _curValue.clear();
        }
        
        _state = SAX_NONE;
    }
Exemple #8
0
inline std::deque<Token>& ParserContext::OutputQueue() const
{
    assert(!m_OutputQueues.empty());
    return *m_OutputQueues.top();
}
bool ProcessNoiseObjectPixel(unsigned long* pixels, long* pixelRef, unsigned long onColour)
{
	long pixel = *pixelRef;
	long x = pixel % s_ChunkDenoiseWidth;
	long y = pixel / s_ChunkDenoiseWidth;
	long width = s_ChunkDenoiseWidth;
	long nextPixel;

	if (s_CheckedPixels[pixel] == UNCHECKED)
	{
		nextPixel = (y - 1) * width + x;

		s_CheckedPixels[pixel] = WENT_UP;

		if (y > 0)
		{
			if (s_CheckedPixels[nextPixel] == UNCHECKED)
			{
				if (pixels[nextPixel] == onColour)
				{
					s_ObjectPixelsPath.push(nextPixel);
					*pixelRef = nextPixel;
					s_ObjectPixelsIndex[s_ObjectPixelsCount] = nextPixel;
					s_ObjectPixelsCount++;
					SetObjectPixelsXFromTo(nextPixel);
				}
				else
					s_CheckedPixels[nextPixel] = CHECKED;
			}
		}
		
		return true;
	}
	else if (s_CheckedPixels[pixel] == WENT_UP)
	{
		nextPixel = y * width + (x - 1);

		s_CheckedPixels[pixel] = WENT_LEFT;

		if (x > 0)
		{
			if (s_CheckedPixels[nextPixel] == UNCHECKED)
			{
				if (pixels[nextPixel] == onColour)
				{
					s_ObjectPixelsPath.push(nextPixel);
					*pixelRef = nextPixel;
					s_ObjectPixelsIndex[s_ObjectPixelsCount] = nextPixel;
					s_ObjectPixelsCount++;
					SetObjectPixelsXFromTo(nextPixel);
				}
				else
					s_CheckedPixels[nextPixel] = CHECKED;
			}
		}
		
		return true;
	}
	else if (s_CheckedPixels[pixel] == WENT_LEFT)
	{
		nextPixel = y * width + (x + 1);

		s_CheckedPixels[pixel] = WENT_RIGHT;

		if (x < width - 1)
		{
			if (s_CheckedPixels[nextPixel] == UNCHECKED)
			{
				if (pixels[nextPixel] == onColour)
				{
					s_ObjectPixelsPath.push(nextPixel);
					*pixelRef = nextPixel;
					s_ObjectPixelsIndex[s_ObjectPixelsCount] = nextPixel;
					s_ObjectPixelsCount++;
					SetObjectPixelsXFromTo(nextPixel);
				}
				else
					s_CheckedPixels[nextPixel] = CHECKED;
			}
		}
	
		return true;
	}
	else if (s_CheckedPixels[pixel] == WENT_RIGHT)
	{
		nextPixel = (y + 1) * width + x;

		s_CheckedPixels[pixel] = WENT_DOWN;

		if (y < s_ChunkDenoiseHeight - 1)
		{
			if (s_CheckedPixels[nextPixel] == UNCHECKED)
			{
				if (pixels[nextPixel] == onColour)
				{
					s_ObjectPixelsPath.push(nextPixel);
					*pixelRef = nextPixel;
					s_ObjectPixelsIndex[s_ObjectPixelsCount] = nextPixel;
					s_ObjectPixelsCount++;
					SetObjectPixelsXFromTo(nextPixel);
				}
				else
					s_CheckedPixels[nextPixel] = CHECKED;
			}
		}

		return true;
	}
	else if (s_CheckedPixels[pixel] >= WENT_DOWN)
	{
		if (s_ObjectPixelsPath.empty())
			return false;

		s_CheckedPixels[pixel] = CHECKED;

		nextPixel = s_ObjectPixelsPath.top();
		s_ObjectPixelsPath.pop();

		if (pixel == nextPixel && !s_ObjectPixelsPath.empty())
		{
			nextPixel = s_ObjectPixelsPath.top();
			s_ObjectPixelsPath.pop();
		}

		*pixelRef = nextPixel;
		return true;
	}
	else
		return false;	
}
Exemple #10
0
    /** \brief
    Return a reference to the next element that will be returned by pop().

    Does not remove the element.

    \pre \c !empty().
    */
    Element & head() { return data_.top(); }
Exemple #11
0
    /**
    \brief Pop an element off the stack.

    This is the last element that was pushed onto the stack that has not yet
    been popped off.

    \pre \c !empty().
    */
    Element pop() {
        Element e = data_.top();
        data_.pop();
        return e;
    }
Exemple #12
0
    /** \brief
    Return the next element that will be returned by pop().

    Does not remove the element.

    \pre \c !empty().
    */
    Element const & head() const { return data_.top(); }
Exemple #13
0
		GameMode::Type previousGameMode() const { return gameModeStack_.top(); }
Exemple #14
0
void StateManager::Clear()
{
	while(!states.empty())
	{ delete states.top(); states.pop(); }
}
Exemple #15
0
 inline void tic() {
   stack.push(t0);
   gettimeofday(&(stack.top()),NULL);
 }
Exemple #16
0
    void startElement(void *ctx, const char *name, const char **atts)
    {
        CC_UNUSED_PARAM(ctx);
        CC_UNUSED_PARAM(atts);
        std::string sName((char*)name);
        if( sName == "dict" )
        {
            m_pCurDict = new CCDictionary<std::string, CCObject*>();
            if(! m_pRootDict)
            {
				// Because it will call m_pCurDict->release() later, so retain here.
                m_pRootDict = m_pCurDict;
				m_pRootDict->retain();
            }
            m_tState = SAX_DICT;

            CCSAXState preState = SAX_NONE;
            if (! m_tStateStack.empty())
            {
                preState = m_tStateStack.top();
            }

            if (SAX_ARRAY == preState)
            {
                // add the dictionary into the array
                m_pArray->addObject(m_pCurDict);
            }
            else if (SAX_DICT == preState)
            {
                // add the dictionary into the pre dictionary
                CCAssert(! m_tDictStack.empty(), "The state is wrong!");
                CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
                pPreDict->setObject(m_pCurDict, m_sCurKey);
            }

			m_pCurDict->release();

            // record the dict state
            m_tStateStack.push(m_tState);
            m_tDictStack.push(m_pCurDict);
        }
        else if(sName == "key")
        {
            m_tState = SAX_KEY;
        }
        else if(sName == "integer")
        {
            m_tState = SAX_INT;
        }
        else if(sName == "real")
        {
            m_tState = SAX_REAL;
        }
        else if(sName == "string")
        {
            m_tState = SAX_STRING;
        }
        else if (sName == "array")
        {
            m_tState = SAX_ARRAY;
            m_pArray = new CCMutableArray<CCObject*>();

            CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
            if (preState == SAX_DICT)
            {
                m_pCurDict->setObject(m_pArray, m_sCurKey);
            }
            else if (preState == SAX_ARRAY)
            {
                CCAssert(! m_tArrayStack.empty(), "The state is worng!");
                CCMutableArray<CCObject*>* pPreArray = m_tArrayStack.top();
                pPreArray->addObject(m_pArray);
            }
            m_pArray->release();
            // record the array state
            m_tStateStack.push(m_tState);
            m_tArrayStack.push(m_pArray);
        }
        else
        {
            m_tState = SAX_NONE;
        }
    }
void STACK_ARGS call_terms (void)
{
	while (!TermFuncs.empty())
		TermFuncs.top().first(), TermFuncs.pop();
}
Exemple #18
0
	typename std::stack<T>::reference& top()
	{
		return internal.top();
	}
    void startElement(void *ctx, const char *name, const char **atts)
    {
        CC_UNUSED_PARAM(ctx);
        CC_UNUSED_PARAM(atts);
        const std::string sName(name);
        if( sName == "dict" )
        {
			if(_resultType == SAX_RESULT_DICT && _rootDict.empty())
            {
                _curDict = &_rootDict;
            }

            _state = SAX_DICT;

            SAXState preState = SAX_NONE;
            if (! _stateStack.empty())
            {
                preState = _stateStack.top();
            }

            if (SAX_ARRAY == preState)
            {
                // add a new dictionary into the array
                _curArray->push_back(Value(ValueMap()));
				_curDict = &(_curArray->rbegin())->asValueMap();
            }
            else if (SAX_DICT == preState)
            {
                // add a new dictionary into the pre dictionary
                CCASSERT(! _dictStack.empty(), "The state is wrong!");
                ValueMap* preDict = _dictStack.top();
                (*preDict)[_curKey] = Value(ValueMap());
				_curDict = &(*preDict)[_curKey].asValueMap();
            }

            // record the dict state
            _stateStack.push(_state);
            _dictStack.push(_curDict);
        }
        else if(sName == "key")
        {
            _state = SAX_KEY;
        }
        else if(sName == "integer")
        {
            _state = SAX_INT;
        }
        else if(sName == "real")
        {
            _state = SAX_REAL;
        }
        else if(sName == "string")
        {
            _state = SAX_STRING;
        }
        else if (sName == "array")
        {
            _state = SAX_ARRAY;

			if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty())
            {
				_curArray = &_rootArray;
            }
            SAXState preState = SAX_NONE;
            if (! _stateStack.empty())
            {
                preState = _stateStack.top();
            }

            if (preState == SAX_DICT)
            {
                (*_curDict)[_curKey] = Value(ValueVector());
				_curArray = &(*_curDict)[_curKey].asValueVector();
            }
            else if (preState == SAX_ARRAY)
            {
                CCASSERT(! _arrayStack.empty(), "The state is wrong!");
                ValueVector* preArray = _arrayStack.top();
                preArray->push_back(Value(ValueVector()));
				_curArray = &(_curArray->rbegin())->asValueVector();
            }
            // record the array state
            _stateStack.push(_state);
            _arrayStack.push(_curArray);
        }
        else
        {
            _state = SAX_NONE;
        }
    }
Exemple #20
0
	typename std::stack<T>::const_reference& top() const
	{
		return internal.top();
	}
Exemple #21
0
void print_stack(std::stack<std::string>& stack1){
	while( !stack1.empty() ){
		debug_lib::log( "%s", stack1.top().c_str() );
		stack1.pop();
	}
}
Exemple #22
0
/*
inline
marker* markerStack::push(short mid, pid_t tid, intptr_t* sp) {	
	marker *nm;
	markerDescriptor *desc = markerDescManager::get(mid);
	if (desc->one_way()) { 
		// oneway marker can share the 
		// reusable marker object
		_reusable.init(tid, sp, desc);
		nm = &_reusable;
	}
	else { // two-way markers		
		if (_free_slot) {
			// pick a free slot 
			nm = _free_slot;		
			
			// set its content
			nm->_tid = tid;
			nm->_sp = sp;
			nm->_desc = desc;
			
			// == forward the free-slot ==
			// note that the list is constructed by prepending, so the
			// last element is the very first in the list and the list
			// expands towards the list head.
			if (_free_slot != _stack)
				// still more room, grab next
				_free_slot = _free_slot->prev; 
			else
				// stack is full now, no free slot
				_free_slot = NULL; 
		}
		else {
			// no free slot is available, go ahead and 
			// allocate a marker instead
			nm = new marker(tid, sp, desc);
			DL_PREPEND(_stack, nm);
		}
	}
	
	return nm;
}

inline 
marker* markerStack::pop() {
	// invariant: _stack will be NULL only at the very beginning, 
	// as soon as a marker is created, the _stack will remain 
	// non-null since we don't deallocate markers explicitly, only
	// advance _free_slot pointers back-and-forth. So, _stack should
	// never be NULL when calling pop().
	// 
	assert (_stack != NULL, "[AS-ERROR] Popping from an empty marker stack.");
	
	// _free_slot is the end of the list
	if (_free_slot) 
	  // expand free-list
		_free_slot = _free_slot->next;	
	else 
		// grab the top-of-stack
		_free_slot = _stack;
	
	// No deallocation and pop anymore
	// DL_DELETE(_stack, _stack); 	
	// -- _length;
	
	// top-of-stack is the current free slot
	return _free_slot;
}
*/
inline 
marker* markerStack::peek() {
	return _stack.size() > 0 ? _stack.top() : NULL;
}
Exemple #23
0
static Value DeserializeValue(std::string& str, bool* had_error, std::stack<StackDepthType>& depth_stack)
{
	Value v;

	*had_error = false;
	str = Trim(str);

	if (str.length() == 0)
		return v;

	if (str[0] == '[')
	{
		// This value is an array, determine the end of it and then deserialize the array
		depth_stack.push(InArray);
		size_t i = GetEndOfArrayOrObj(str, depth_stack);
		if (i == std::string::npos)
		{
			*had_error = true;
			return Value();
		}
		
		std::string array_str = str.substr(0, i + 1);
		v = Value(DeserializeArray(array_str, depth_stack));
		str = str.substr(i + 1, str.length());
	}
	else if (str[0] == '{')
	{
		// This value is an object, determine the end of it and then deserialize the object
		depth_stack.push(InObject);
		size_t i = GetEndOfArrayOrObj(str, depth_stack);

		if (i == std::string::npos)
		{
			*had_error = true;
			return Value();
		}

		std::string obj_str = str.substr(0, i + 1);
		v = Value(DeserializeInternal(obj_str, depth_stack));
		str = str.substr(i + 1, str.length());
	}
	else if (str[0] == '\"')
	{
		// This value is a string
		size_t end_quote = GetQuotePos(str, 1);
		if (end_quote == std::string::npos)
		{
			*had_error = true;
			return Value();
		}

		v = Value(UnescapeJSONString(str.substr(1, end_quote - 1)));
		str = str.substr(end_quote + 1, str.length());
	}
	else
	{
		// it's not an object, string, or array so it's either a boolean or a number or null.
		// Numbers can contain an exponent indicator ('e') or a decimal point.
		bool has_dot = false;
		bool has_e = false;
		std::string temp_val;
		size_t i = 0;
		bool found_digit = false;
		//bool found_first_valid_char = false;

		for (; i < str.length(); i++)
		{
			if (str[i] == '.')
			{
				if (!found_digit)
				{
					// As per JSON standards, there must be a digit preceding a decimal point
					*had_error = true;
					return Value();
				}

				has_dot = true;
			}
			else if ((str[i] == 'e') || (str[i] == 'E'))
			{		
				if ((_stricmp(temp_val.c_str(), "fals") != 0) && (_stricmp(temp_val.c_str(), "tru") != 0))
				{
					// it's not a boolean, check for scientific notation validity. This will also trap booleans with extra 'e' characters like falsee/truee
					if (!found_digit)
					{
						// As per JSON standards, a digit must precede the 'e' notation
						*had_error = true;
						return Value();
					}
					else if (has_e)
					{
						// multiple 'e' characters not allowed
						*had_error = true;
						return Value();
					}

					has_e = true;
				}
			}
			else if (str[i] == ']')
			{
				if (depth_stack.empty() || (depth_stack.top() != InArray))
				{
					*had_error = true;
					return Value();
				}
				
				depth_stack.pop();
			}
			else if (str[i] == '}')
			{
				if (depth_stack.empty() || (depth_stack.top() != InObject))
				{
					*had_error = true;
					return Value();
				}
				
				depth_stack.pop();
			}
			else if (str[i] == ',')
				break;			
			else if ((str[i] == '[') || (str[i] == '{'))
			{
				// error, we're supposed to be processing things besides arrays/objects in here
				*had_error = true;
				return Value();
			}

			if (!std::isspace(str[i]))
			{
				if (std::isdigit(str[i]))
					found_digit = true;

				//found_first_valid_char = true;
				temp_val += str[i];
			}
		}

		// store all floating point as doubles. This will also set the float and int values as well.
		if (_stricmp(temp_val.c_str(), "true") == 0)
			v = Value(true);
		else if (_stricmp(temp_val.c_str(), "false") == 0)
			v = Value(false);
		else if (has_e || has_dot)
		{
			char* end_char;
			errno = 0;
			double d = strtod(temp_val.c_str(), &end_char);
			if ((errno != 0) || (*end_char != '\0'))
			{
				// invalid conversion or out of range
				*had_error = true;
				return Value();
			}

			v = Value(d);
		}
		else if (_stricmp(temp_val.c_str(), "null") == 0)
			v = Value();
		else
		{
			// Check if the value is beyond the size of an int and if so, store it as a double
			char* end_char;
			errno = 0;
			long int ival = strtol(temp_val.c_str(), &end_char, 10);
			if (*end_char != '\0')
			{
				// invalid character sequence, not a number
				*had_error = true;
				return Value();
			}
			else if ((errno == ERANGE) && ((ival == LONG_MAX) || (ival == LONG_MIN)))
			{
				// value is out of range for a long int, should be a double then. See if we can convert it correctly.
				errno = 0;
				double dval = strtod(temp_val.c_str(), &end_char);
				if ((errno != 0) || (*end_char != '\0'))
				{
					// error in conversion or it's too big for a double
					*had_error = true;
					return Value();
				}

				v = Value(dval);
			}
			else if ((ival >= INT_MIN) && (ival <= INT_MAX))
			{
				// valid integer range
				v = Value((int)ival);
			}
			else
			{
				// probably running on a very old OS since this block implies that long isn't the same size as int.
				// int is guaranteed to be at least 16 bits and long 32 bits...however nowadays they're almost
				// always the same 32 bit size. But it's possible someone is running this on a very old architecture
				// so for correctness, we'll error out here
				*had_error = true;
				return Value();
			}
		}

		str = str.substr(i, str.length());
	}

	return v;
}
Exemple #24
0
void two_number(std::stack<double> &double_stack,double &a, double &b){
	b=double_stack.top();
	double_stack.pop();
	a=double_stack.top();
	double_stack.pop();
}
Exemple #25
0
std::string Parser::getAction(
	std::stack<std::string> &frameStack,
	std::stack<std::string> &pStack, std::list<int> &output,
	std::string expr, int &s, std::string &a, int &ip, int &ip2,
	std::map<std::string, bool> &visMap
	)
{
	std::string result;
	s = val(pStack.top()); // let "s" be stack top
	a = scanText(expr, ip2 = ip, " "); // let "a" be next token
	if ((result = (*mActionTable)[s][a]) == "_") // if error
		if (!frameStack.empty()) // if more alternatives to try
		{
			//=========================================================
			// pop branch info
			std::string name = popStack(frameStack); // get branch NAME
			int branchCnt = val(popStack(frameStack)); // get branch COUNT
			int branch = val(popStack(frameStack)); // get branch INDEX
			//=========================================================
			this->applyState(
				frameStack, pStack, output, s, a, ip, ip2, result
				); // apply branch STATE
			//=========================================================
			// push branch info
			frameStack.push(cstr(branch)); // push branch INDEX
			frameStack.push(cstr(branchCnt)); // push branch COUNT
			frameStack.push(name); // push branch NAME
			//=========================================================
		}
	//=========================================================
	std::string name =
		cstr(s) + "_" + a + "_" + cstr(ip); // build branch NAME
	std::string state = name + "_" +
		right(readSeq(output), LOOP_SAMPLE_LEN); // build parser STATE
	//=========================================================
	if (result.find(" ") != -1) // if multiple actions possible
	{
		int branchCnt = 1; // init branch COUNT
		int branch = 0; // init branch INDEX
		if (
			!frameStack.empty() && name == frameStack.top()
			) // if revisiting branch
		{
			//=========================================================
			// pop branch info
			frameStack.pop(); // pop branch NAME
			branchCnt = val(popStack(frameStack)); // get branch COUNT
			branch = val(popStack(frameStack)); // get branch INDEX
			//=========================================================
		}
		//=========================================================
		state += "_" + cstr(branch); // build parser STATE
		//=========================================================
		if (branch < branchCnt) // if branch legal
		{
			if (!branch) // if first encounter with branch
			{
				this->pushState(
					frameStack, pStack, output, s, a, ip, ip2, result
					); // push branch STATE
				branchCnt = countText(result, " ") + 1; // calc branch COUNT
			}
			//=========================================================
			result = getEntry(result, " ", branch); // choose this branch INDEX
			//=========================================================
			if (branch == branchCnt - 1) // if last encounter with branch
				this->popState(frameStack); // pop branch STATE
			else
			{
				//=========================================================
				// push branch info
				frameStack.push(cstr(branch + 1)); // push next branch INDEX
				frameStack.push(cstr(branchCnt)); // push branch COUNT
				frameStack.push(name); // push branch NAME
				//=========================================================
			}
		}
		else
			throw new Exception("parsing error");
	}
	//=========================================================
	// check for infinite recursion
	if (visMap.find(state) != visMap.end())
		throw new Exception("parsing error");
	visMap[state] = true; // mark as visited
	//=========================================================
	return result;
}
Exemple #26
0
void save(std::stack<char> &ch_stack,std::vector<std::string> &vec){
	char buff[2]={'\0','\0'};
	buff[0]=ch_stack.top();
	vec.push_back(buff);
	ch_stack.pop();
}
 /// Destructor
 ~TraceSlice_Stack() {
   while (!content.empty()) {
     delete content.top();
     content.pop();
   }
 }
Exemple #28
0
S32 LLAllocator::popMemType(void)
{
	S32 ret = memTypeStack.top();
	memTypeStack.pop();
	return ret;
}
Exemple #29
0
static void XMLCALL EndHandler(void *data, const char *el)
{
  char parent[SHORT_TEXT_LEN];
  
  if (nodestack.size() > 1) {
     nodestack.pop();
     } 
  else {
     nodestack.pop();
     return;
     }
  strn0cpy(parent, (nodestack.top()).nodename, sizeof((nodestack.top()).nodename));
  // No need to free the node
  
  depth--;
  if (!strncmp(el, "item", 4)) {
     // End of the current item
     if (*item->GetTitle())
        Parser.Items.Add(item);
     }
  else if (!strncmp(el, "title", 5)) {
     if (!strncmp(parent, "item", 4)) {
        item->SetTitle(data_string);
        }
     else if (!strncmp(parent, "channel", 7)) {
        debug("cParser::EndHandler(): Reelblog title '%s'", data_string);
        }
     }
  else if (!strncmp(el, "link", 4)) {
     if (!strncmp(parent, "item", 4)) {
        item->SetLink(data_string);
        }
     else if (!strncmp(parent, "channel", 7)) {
        debug("cParser::EndHandler(): Reelblog link '%s'", data_string);
        }
     }
  else if (!strncmp(el, "pubDate", 7)) {
     if (!strncmp(parent, "item", 4)) {
        item->SetDate(data_string);
        }
     else if (!strncmp(parent, "channel", 7)) {
        debug("cParser::EndHandler(): Reelblog date '%s'", data_string);
        }
     }
  else if (!strncmp(el, "description", 11)) {
     if (!strncmp(parent, "item", 4)) {
        item->SetDescription(data_string);
        }
     else if (!strncmp(parent, "channel", 7)) {
        debug("cParser::EndHandler(): Reelblog description '%s'", data_string);
        }
     }
  else if (!strncmp(el, "content:encoded", 15)) {
     if (!strncmp(parent, "item", 4)) {
        item->SetDescription(data_string); // overdrive description with content:encoded !
        }
     else if (!strncmp(parent, "channel", 7)) {
        debug("cParser::EndHandler(): Reelblog content '%s'", data_string);
        }
     }
  strcpy(data_string, "");
}
Exemple #30
0
 int top() {
     return s.top();
 }