当前位置: 首页>>代码示例>>C++>>正文


C++ std::stack类代码示例

本文整理汇总了C++中std::stack的典型用法代码示例。如果您正苦于以下问题:C++ stack类的具体用法?C++ stack怎么用?C++ stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了stack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: top_pop

	 T Parser::top_pop(std::stack<T>& input){
		 T temp = input.top();
		 input.pop();
		 return temp;
	 }
开发者ID:arminak89,项目名称:CLI-Calculator,代码行数:5,代码来源:calculator.cpp

示例2: DeserializeValue

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 ] == ']' )
//.........这里部分代码省略.........
开发者ID:TheCodeInside,项目名称:BowLand,代码行数:101,代码来源:JSON.cpp

示例3: if

void Pulsar::PlotLoop::plot( std::stack< Reference::To<TextIndex> >& indeces )
{
  if (indeces.empty())
  {
    VERBOSE("Pulsar::PlotLoop::plot plotting");

    for (unsigned i=0; i<plots.size(); i++)
    {
      if (!overlay)
        cpgpage ();

      plots[i]->plot (archives[i]);
    }
    return;
  }

  Reference::To<TextIndex> index = indeces.top();
  indeces.pop();

  vector<string> current (plots.size());

  unsigned loop_size = 0;
  for (unsigned iplot=0; iplot < plots.size(); iplot++)
  {
    index->set_container( archives[iplot]->get_interface() );

    if (iplot == 0)
      loop_size = index->size();
    else if ( loop_size != index->size() )
      throw Error (InvalidState, "Pulsar::PlotLoop::plot",
                   "loop size for plot[0]=%u != that of plot[%u]=%u",
                   loop_size, iplot, index->size());
  }

  for (unsigned i=0; i<loop_size; i++)
  {
    for (unsigned iplot=0; iplot < plots.size(); iplot++) try
    {
      index->set_container( archives[iplot]->get_interface() );

      string index_command = index->get_index(i);

      VERBOSE("Pulsar::PlotLoop::plot " << index_command);

      PlotLabel* label = plots[iplot]->get_attributes()->get_label_above();
      current[iplot] = label->get_centre();

      plots[iplot]->configure( index_command );
  
      label->set_centre( current[iplot] + " " + index_command );
    }
    catch (Error& error)
    {
      cerr << "Pulsar::PlotLoop::plot error configuring " << index->get_index(i)
           << " of "
           << "\n\t" << archives[iplot]->get_filename()
           << "\n\t" << error.get_message() << endl;
    }

    try
    {
      plot (indeces);
    }
    catch (Error& error)
    {
      cerr << "Pulsar::PlotLoop::plot error plotting " 
           << "\n\t" << error.get_message() << endl;
    }

    for (unsigned iplot=0; iplot < plots.size(); iplot++)
    {
      PlotLabel* label = plots[iplot]->get_attributes()->get_label_above();
      label->set_centre( current[iplot] );
    }
  }

  indeces.push( index );
}
开发者ID:lbaehren,项目名称:lofarsoft,代码行数:78,代码来源:PlotLoop.C

示例4: DeserializeValue

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;
		for (; i < str.length(); i++)
		{
			if (str[i] == '.')
				has_dot = true;
			else if ((str[i] == 'e') || (str[i] == 'E'))
				has_e = true;
			else if (str[i] == ']')
			{
				if (depth_stack.top() != InArray)
				{
					*had_error = true;
					return Value();
				}
				
				depth_stack.pop();
			}
			else if (str[i] == '}')
			{
				if (depth_stack.top() != InObject)
				{
					*had_error = true;
					return Value();
				}
				
				depth_stack.pop();
			}
			else if (str[i] == ',')
				break;

			if (!std::isspace(str[i]))
				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);
//.........这里部分代码省略.........
开发者ID:lambertjamesd,项目名称:Krono,代码行数:101,代码来源:json.cpp

示例5: handle

namespace ospray {

  static std::map<int64,Ref<ospray::ManagedObject>> objectByHandle;
  static std::stack<int64> freedHandles;

  //! next unassigned ID on this node
  /*! we start numbering with 1 to make sure that "0:0" is an
    invalid handle (so we can typecast between (64-bit) handles
    and (64-bit)OSPWhatEver pointers */
  static int32 nextFreeLocalID = 1;

  void ObjectHandle::free()
  {
    freedHandles.push((int64)*this);
  }

  ObjectHandle::ObjectHandle()
  {
    if (freedHandles.empty()) {
      i32.ID    = nextFreeLocalID++;
      i32.owner = 0;
    } else {
      i64 = freedHandles.top();
      freedHandles.pop();
    }
  }

  ObjectHandle::ObjectHandle(int64 i) : i64(i)
  {
  }

  ObjectHandle::ObjectHandle(const ObjectHandle &other) : i64(other.i64)
  {
  }

  ObjectHandle &ObjectHandle::operator=(const ObjectHandle &other)
  {
    i64 = other.i64;
    return *this;
  }

  /*! define the given handle to refer to given object */
  void ObjectHandle::assign(const ObjectHandle &handle, ManagedObject *object)
  {
    objectByHandle[handle] = object;
  }

  void ObjectHandle::assign(ManagedObject *object) const
  {
    objectByHandle[*this] = object;
  }

  void ObjectHandle::freeObject() const
  {
    auto it = objectByHandle.find(i64);
    Assert(it != objectByHandle.end());
    it->second = nullptr;
    objectByHandle.erase(it);
  }

  int32 ObjectHandle::ownerRank() const
  {
    return i32.owner;
  }

  int32 ObjectHandle::objID() const
  {
    return i32.ID;
  }

  ospray::ObjectHandle::operator int64() const
  {
    return i64;
  }

  bool ObjectHandle::defined() const
  {
    auto it = objectByHandle.find(i64);
    return it != objectByHandle.end();
  }

  ManagedObject *ObjectHandle::lookup() const
  {
    if (i64 == 0) return nullptr;

    auto it = objectByHandle.find(i64);
    if (it == objectByHandle.end()) {
#ifndef NDEBUG
      // iw - made this into a warning only; the original code had
      // this throw an actual exceptoin, but that may be overkill
      std::cout << "#osp: WARNING: ospray is trying to look up object handle "+std::to_string(i64)+" that isn't defined!" << std::endl;
#endif
      return nullptr;
    }
    return it->second.ptr;
  }

  ObjectHandle ObjectHandle::lookup(ManagedObject *object)
  {
    for (auto it = objectByHandle.begin(); it != objectByHandle.end(); it++) {
//.........这里部分代码省略.........
开发者ID:cpgribble78,项目名称:OSPRay,代码行数:101,代码来源:ObjectHandle.cpp

示例6: push

inline void push( std::stack<StackValueType> &s, T t ) {
  s.push( t );
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:3,代码来源:ftcontains_visitor.cpp

示例7: AnalysisWildCard

void MyCompressData::AnalysisWildCard(const char *inWildCard,char *outFileList,std::stack<std::string>& ioStack)
{
	bool theStartFlag = 1;
	if(outFileList[0] != '\0')
	{
		theStartFlag = 0;
	}
	HANDLE hFind;
	WIN32_FIND_DATA fd;
	//================================
	//ワイルドカード使用時
	//================================
	hFind = FindFirstFile(inWildCard, &fd);		
		
	//検索失敗
	if(hFind == INVALID_HANDLE_VALUE) 
	{
		return;
	}
			
	//===================================
	//ディレクトリの名前取得
	//===================================
	char theDirName[256];
	strcpy(theDirName,inWildCard);
	for(int i = (int)strlen(theDirName); i >= 0; i--)
	{
		if(theDirName[i] == '/')
		{
			theDirName[i + 1] = '\0';
			break;
		}
	}

	
	char theBuffer[256];
	do 
	{
		if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
		{
			if(theStartFlag == 0)
			{
				strcat(outFileList,",");
			}
			strcat(outFileList,theDirName);
			strcat(outFileList,fd.cFileName);
			theStartFlag = 0;
		}
		else if(fd.cFileName[0] != '.')
		{
			strcpy(theBuffer,theDirName);
			strcat(theBuffer,fd.cFileName);
			strcat(theBuffer,"/");
			strcat(theBuffer,"*");
			ioStack.push(std::string(theBuffer));
		}
	} while(FindNextFile(hFind, &fd));

    FindClose(hFind);



}
开发者ID:akasakariki,项目名称:VSD3,代码行数:63,代码来源:paczip.cpp

示例8: OnStartCluster

	void OnStartCluster(const std::string & id, const AttrMap & attrs)
	{
		assert(!id.empty());
		m_clusterStack.push(GetCluster(m_graph, m_clusterStack.top(), id, m_merge));
		m_clusterStack.top()->SetProperty(DOT_PROP_CDOTITEM, new CDotCluster(id, attrs));
	}
开发者ID:GordonSmith,项目名称:GraphControl,代码行数:6,代码来源:DotParser.cpp

示例9: startElement

    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;
        }
    }
开发者ID:RayRiver,项目名称:misc,代码行数:90,代码来源:CCFileUtils.cpp

示例10:

	CGraphvizVisitor(IGraph * graph, bool merge) 
	{
		m_graph = graph;
		m_merge = merge;
		m_clusterStack.push(graph);
	}
开发者ID:GordonSmith,项目名称:GraphControl,代码行数:6,代码来源:DotParser.cpp

示例11: OnStartGraph

	void OnStartGraph(int kind, const std::string & id, const AttrMap & attrs)
	{
		assert(!id.empty());
		m_graph->SetProperty(DOT_PROP_CDOTITEM, new CDotGraph(kind, id, attrs));
		m_clusterStack.push(NULL);
	}
开发者ID:GordonSmith,项目名称:GraphControl,代码行数:6,代码来源:DotParser.cpp

示例12: LASError_Reset

LAS_DLL void LASError_Reset(void) {
    if (errors.empty()) return;
    for (std::size_t i=0;i<errors.size();i++) errors.pop();
}
开发者ID:lclsdut,项目名称:UrbanReconstruction,代码行数:4,代码来源:las_c_api.cpp

示例13: LASError_PushError

LAS_DLL void LASError_PushError(int code, const char *message, const char *method) {
    LASError err = LASError(code, std::string(message), std::string(method));
    errors.push(err);
}
开发者ID:lclsdut,项目名称:UrbanReconstruction,代码行数:4,代码来源:las_c_api.cpp

示例14: free

 void ObjectHandle::free()
 {
   freedHandles.push((int64)*this);
 }
开发者ID:cpgribble78,项目名称:OSPRay,代码行数:4,代码来源:ObjectHandle.cpp

示例15: getPicture

/*! \brief return current camera picture, as rgb or yuv picture, threadsave
 *
 * \param rgb if set to zero (default), yuv-Picture will return, <br>
 *            if set to other value, rgb-Picture will return
 * \param removeFrame if set to 1 (default) the next picture will be catch <br>
 *                    if set to zero, the last picture will be returned
 * \return SPicture pointer to lokal buffer, which didn't change until the next call from getPicture with
 *         the same rgb-parameter
 * \return NULL if any error occured
 */
SPicture* getPicture(int rgb/* = 0*/, int removeFrame/* = 1*/)
{
    if(mutex_lock(mutex))
        g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_lock</font>"));

    // if start wasn't called
    if(!g_run)
    {
        while(g_capture.isOpened())
            g_capture.release();
        printf("encoder.getPicture after call g_capture.release\n");
        g_Messages.push(string("getPicture</b> <font color='blue'>Kamera wurde geschlossen</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 1</font>"));
        return 0;
    }
    // try to open capture
    else if(!g_capture.isOpened())
    {
        g_Messages.push(string("getPicture</b> <font color='red'>keine Kamera geoeffnet!</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 2</font>"));
        return 0;
    }


    //get next or last picture
    Mat m, m2, m3;
    if(!removeFrame)
        g_capture.retrieve(m);
    else
        g_capture >> m; // get a new frame from camer

    if(!m.size().area())
    {
        g_Messages.push(string("getPicture</b> <font color='red'>picture from camera is empty</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 3</font>"));
        return 0;
    }

    //m = cvLoadImage("test.jpg");
    if(m.depth() != CV_8U)
    {
        g_Messages.push(string("getPicture</b> <font color='red'>depth != unsigned char</font>\n"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 4</font>"));
        return 0;
    }
    //m.convertTo(m2, )
    //Scale Picture to choosen resolution (if camera didn't support it)
    Mat matrices[4];
    //IplImage src = m;
    //  IplImage* scaled = cvCreateImage(cvSize(g_cfg.width, g_cfg.height), IPL_DEPTH_8U, 3);

    //cvResize( &src, scaled, CV_INTER_LINEAR );
    m3.create(g_cfg.width, g_cfg.height, m.type());
    resize(m, m3, Size(g_cfg.width, g_cfg.height));

    char buffer[256];
    sprintf(buffer, "getPicture</b> <i>breite: %d, hoehe: %d, area: %d</i>", m.size().width, m.size().height, m.size().area());
    // g_Messages.push(string(buffer));

    //rgb-output
    if(rgb)
    {
        //imshow("LIVE", scaled);
        split(m3, matrices);
        matrices[3] = matrices[0].clone();
        matrices[3] = Scalar(255);
        merge(matrices, 4, m2);

        //get current buffer size and required buffer size
        int oldSize = picture_getSize(&g_rgbPicture);
        g_rgbPicture.width = m2.cols;
        g_rgbPicture.height = m2.rows;
        int newSize = picture_getSize(&g_rgbPicture);

        //compare buffer size and picture size, and make new buffer, if picture size differ
        if(oldSize != newSize)
        {
            picture_release(&g_rgbPicture);
            if(picture_create(&g_rgbPicture, m2.cols, m2.rows, 4))
            {
                g_Messages.push(string("getPicture</b> <font color='red'>Fehler beim speicher reservieren in getPicture rgb!</font>"));
                if(mutex_unlock(mutex))
                    g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 5</font>"));
                return NULL;
            }
        }
//.........这里部分代码省略.........
开发者ID:commshare,项目名称:OpenLive4Cam,代码行数:101,代码来源:capture.cpp


注:本文中的std::stack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。