bool SmallerBefore::CalcBothNotEmpty(const int value, std::stack<int>& stack1, std::stack<int>& stack2, std::vector<int>& S)
{
	if (value >= stack1.top() && value <= stack2.top())
	{
		stack1.push(value);
		S.push_back(stack1.size());
	}
	else if (value <= stack1.top())
	{
		while (! stack1.empty() && value < stack1.top())
		{
			stack2.push(stack1.top());
			stack1.pop();
		}
		stack1.push(value);
		S.push_back(stack1.size());
	}
	else if (value >= stack2.top())
	{
		while (! stack2.empty() && value >= stack2.top())
		{
			stack1.push(stack2.top());
			stack2.pop();
		}
		stack1.push(value);
		S.push_back(stack1.size());
	}

	return true;
}
Exemple #2
0
int freeObsDataSize()
{
  return 
    baseObsDataFreeStack.size() * sizeof(baseObsData) +
    fixedObsDataFreeStack.size() * sizeof(fixedObsData) +
    movingObsDataFreeStack.size() * sizeof(movingObsData);
}
Exemple #3
0
void EvalStack::exec(char chr) {
  AttributeValue a, b, c;
  switch (chr) {
  case '+':
  case '-':
  case '*':
  case '/':
  case '>':
  case '<':
  case funcMin:
  case funcMax:
  case funcTable:
    if (vals.size() < 2) return;
    b = vals.top(); vals.pop();
    a = vals.top(); vals.pop();
    vals.push(binop(a, b, chr));
    break;
  case '~':
    if (vals.size() < 1) return;
    if (vals.top().text.empty()) {
      a = vals.top(); vals.pop();
      vals.emplace(-a.max, -a.min);
    }
    break;
  case ':':
    if (vals.size() < 3) return;
    c = vals.top(); vals.pop();
    b = vals.top(); vals.pop();
    a = vals.top(); vals.pop();
    vals.push(a.max ? b : c);
    break;
  }
}
Exemple #4
0
void Draw::renderRect()
{
std::stack <int> tempPoints;
std::stack <char *> tempColor;

tempPoints=pointlist;
tempColor=colorlist;

if (pointlist.size()/4!=(colorlist.size()))
std::cout<<"Error,mismatch between number of colors and points in the rectangle"<<std::endl;

    while(!tempPoints.empty())
{
int x = tempPoints.top();
tempPoints.pop();
int y = tempPoints.top();
tempPoints.pop();
int width = tempPoints.top();
tempPoints.pop();
int height = tempPoints.top();
tempPoints.pop();



drawRectangle(x,y,width,height,tempColor.top());

tempColor.pop();

}


}
// I'm certain this function could be cleaned up, but it will require some
// serious brain storming, so it is a work in progress....
//
// The idea is I want to generate all possible permutations of RPN stacks given
// a set of 4 input integers.
void perms(std::set<int> possible, std::set<int>& all, std::stack<rpn_item> e, std::vector<rpn_item> const& ops) {
    // Once the stack is finished evaluate and add to the set
    if (e.size() == 7) {
        auto test = eval_rpn_stack(e);
        if (test > 0 && test != BAD_DIVIDE)
            all.insert(test);
        return;
    }

    // The very bottom of the stack MUST be an operator
    if (e.size() == 0) {
        for (auto i : ops) {
            auto tmp = e;
            tmp.push(i);
            perms(possible, all, tmp, ops);
        }
    }

    // the TOP 2 items in the stack MUST be integers
    if (e.size() >= 5) {
        for (auto i : possible) {
            auto tmp = possible;
            auto tmp_e = e;
            tmp.erase(i);
            tmp_e.push(i);
            perms(tmp, all, tmp_e, ops);
        }
    }

    // This is where things get messy...
    // I enumerate all possible stack configurations
    // There is no visible pattern that I can see and easily program so for now
    // this will remain a mess
    for (auto n1 = possible.begin(); n1 != possible.end(); ++n1) {
        for (auto n2 = std::next(n1); n2 != possible.end(); ++n2) {
            auto tmp_p = possible;
            tmp_p.erase(*n1); tmp_p.erase(*n2);
            for (auto op1 = ops.begin(); op1 != ops.end(); ++op1) {
                for (auto op2 = ops.begin(); op2 != ops.end(); ++op2) {
                    // op op n n
                    auto n = push_helper(e, {*op1, *op2, *n1, *n2});
                    perms(tmp_p, all, n, ops);
                    // op n op n
                    n = push_helper(e, {*op1, *n1, *op2, *n2});
                    perms(tmp_p, all, n, ops);
                    // n op n op
                    n = push_helper(e, {*n1, *op1, *n2, *op2});
                    perms(tmp_p, all, n, ops);
                    // op n n op
                    n = push_helper(e, {*op1, *n1, *n2, *op2});
                    perms(tmp_p, all, n, ops);
                    // n op op n
                    n = push_helper(e, {*n1, *op1, *op2, *n2});
                    perms(tmp_p, all, n, ops);
                }
            }
        }
    }
}
Exemple #6
0
	bool parameter() {
		std::size_t old_stack_size = stack_.size();
		if (T::match(*this)) {
			reduce_stack(stack_.size() - old_stack_size);
			return true;
		} else
			return false;
	}
Exemple #7
0
            /** Comparison operator.
             *  @param other  The object to compare ourselves to.
             *  @return \c true if this and given iterator are equal, \c false otherwise. */
            bool operator==(const typename PathMap<StoreT>::Iterator &other) const
            {
                if ( nodesAndChilds.size() == 0 || other.nodesAndChilds.size() == 0)
                    return nodesAndChilds.size() == other.nodesAndChilds.size();


                return      this->nodesAndChilds.top().node    == other.nodesAndChilds.top().node
                        &&  this->nodesAndChilds.top().childNo == other.nodesAndChilds.top().childNo;
            }
Exemple #8
0
void pushVerbosity(QudaVerbosity verbosity)
{
  vstack.push(getVerbosity());
  setVerbosity(verbosity);

  if (vstack.size() > 10) {
    warningQuda("Verbosity stack contains %u elements.  Is there a missing popVerbosity() somewhere?",
		static_cast<unsigned int>(vstack.size()));
  }
}
Exemple #9
0
static size_t GetEndOfArrayOrObj(const std::string& str, std::stack<StackDepthType>& depth_stack)
{
	size_t i = 1;
	bool in_quote = false;
	size_t original_count = depth_stack.size();
	
	for (; i < str.length(); i++)
	{
		if (str[i] == '\"')
		{
			if (str[i - 1] != '\\')
				in_quote = !in_quote;
		}
		else if (!in_quote)
		{
			if (str[i] == '[')
				depth_stack.push(InArray);
			else if (str[i] == '{')
				depth_stack.push(InObject);
			else if (str[i] == ']')
			{
				StackDepthType t = depth_stack.top();
				if (t != InArray)
				{
					// expected to be closing an array but instead we're inside an object block.
					// Example problem: {]}
					return std::string::npos;
				}
				
				size_t count = depth_stack.size();
				depth_stack.pop();
				if (count == original_count)
					break;
			}
			else if (str[i] == '}')
			{
				StackDepthType t = depth_stack.top();
				if (t != InObject)
				{
					// expected to be closing an object but instead we're inside an array.
					// Example problem: [}]
					return std::string::npos;
				}
					
				size_t count = depth_stack.size();
				depth_stack.pop();
				if (count == original_count)
					break;
			}
		}
	}
	
	return i;
}
Exemple #10
0
bool pe(std::stack<char> &a, std::stack<char> &b) {
  if(a.size() != b.size())
    return false;
  while(!a.empty()) {
    if(a.top() != b.top())
      return false;
    a.pop();
    b.pop();
  }
  return true;
}
//*******************************************************
// Parser::printStack
//*******************************************************
void Parser::printStack(std::ostream &theOS,
                        std::stack<std::shared_ptr<Symbol>> theStack)
{
  while (theStack.size() > 0)
  {
    theOS << *(theStack.top());
    theStack.pop();
    if (theStack.size() > 0)
    {
      theOS << " ";
    }
  }
}
Exemple #12
0
void back(void)
{
    if (menu_pages.size() > 1)
    {
        menu_pages.pop();
    }
}
void PostfixExprEvaluator::processUnaryOp(const Token &token,
	                                      std::stack<Token> &operands)
{
	assert(token.type == TokenType::TOK_UNARYOP);

	// ensure stack contains one operand
	if (operands.size() < 1)
	{
		throw StackUnderflowException();
	}

	// fetch operand off the stack
	auto operand = operands.top(); operands.pop();

	if (operand.type == TokenType::TOK_INT)
	{
		operand = castIntToFloat(operand);
	}

	Token opResult;
	
	opResult.type = TokenType::TOK_FLOAT,
	opResult.value.valueFloat = evalUnaryOp<float>(
		operand.value.valueFloat,
		static_cast<OpUnary>(token.value.valueInt));

	operands.push(opResult);
}
Exemple #14
0
    int start_elem(const std::string &elem){
        // new tag, clean content;
        current.clear();

        // check XML nested level, security protection
        if(stack_status.size() < 200){
            stack_status.push(elem);
        }else{
            throw DavixException(davix_scope_xml_parser(), StatusCode::ParsingError, "Impossible to parse S3 content, corrupted XML");
        }

        // check element, if it is "deleted" this recource has beed deleted successfully
        // or the resource did not exist in the first place, either way, log it 
        if( StrUtil::compare_ncase(delete_prop, elem) ==0){
            DAVIX_SLOG(DAVIX_LOG_TRACE, DAVIX_LOG_XML, "deleted entry found", elem.c_str());
            status.clear();
            entry_count = 0;
        }

        // check element, if "Error" there has been problem with deleting this resource
        // the code returned will have to be mapped to http code
        if( StrUtil::compare_ncase(error_prop, elem) ==0){
            DAVIX_SLOG(DAVIX_LOG_TRACE, DAVIX_LOG_XML, "error entry found", elem.c_str());
            status.clear();
            status.error = true;
            entry_count = 0;
        }


        return 1;
    }
   indri::lang::Node* defaultAfter( indri::lang::Node* oldNode, indri::lang::Node* newNode ) {
     if( _disqualifiers.size() && oldNode == _disqualifiers.top() )
       _disqualifiers.pop();
 
     _nodes.push_back( newNode );
     return newNode;
   }
Exemple #16
0
 check_point get_check_point()const
 {
    if ( check_points.size()){
    return check_points.top();
    }
    return check_point("throw point" ,this->get_source_pos(),this->get_stream_id());
 }
Exemple #17
0
int checkpoint_stl(std::stack<std::string> & in_stl , std::string object_name , std::string var_name ) {

    unsigned int ii ;
    unsigned int cont_size ;
    char var_declare[128] ;
    int status ;

    char ** items = NULL ;
    std::stack<std::string> temp_stack ;

    cont_size = in_stl.size() ;
    std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');

    if ( cont_size > 0 ) {

        sprintf(var_declare, "%s %s_%s[%d]" ,
         abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ;
        items = (char **)TMM_declare_var_s(var_declare) ;
        //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ;

        temp_stack = in_stl ;

        for ( ii = 0 ; ii < cont_size ; ii++ ) {
            items[ii] = (char *)((temp_stack.top()).c_str()) ;
            temp_stack.pop() ;
        }
    }

    return 0 ;
}
void task4_6::solution::process_operation( std::stack< double >& numbers, const char op)
{
	double l, r;

	if( op == '(' || op == ')' || numbers.size() < 2)
		throw std::logic_error("not correct expression at "+boost::lexical_cast< std::string >( line_index )+" line");

	r = numbers.top();
	numbers.pop();
	l = numbers.top();
	numbers.pop();

	switch( op )
	{
	case '+':
		numbers.push( l+r );
		break;
	case '-':
		numbers.push( l-r );
		break;
	case '*':
		numbers.push( l*r );
		break;
	case '/':
		if ( fabs(r)<=1e-9 )
			throw std::logic_error( "zero div " + boost::lexical_cast< std::string >( line_index ) );
		numbers.push( l/r );
		break;
	}

}
Exemple #19
0
int restore_stl(std::stack<std::string> & in_stl , std::string object_name , std::string var_name ) {

    unsigned int ii ;
    unsigned int cont_size ;

    REF2 * items_ref ;
    char ** items ;
    std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');

    //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ;

    cont_size = in_stl.size() ;
    for ( ii = 0 ; ii < cont_size ; ii++ ) {
        in_stl.pop() ;
    }

    items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ;

    if ( items_ref != NULL ) {
        items = (char **)items_ref->address ;
        cont_size = get_size((char *)items) ;

        for ( ii = cont_size - 1 ; ii < cont_size ; ii-- ) {
            in_stl.push( items[ii] ) ;
        }
        delete_stl( in_stl , object_name , var_name ) ;
    }

    return 0 ;
}
void DebugEmitterComponent::_CalculateNodeTransform(std::stack<mat4*>& stack, mat4* res)
{
	if (stack.size() == 1)
	{
		auto top = stack.top();
		stack.pop();

		mat4 result;
		mat4_copy(result, *top);
		mat4_copy(*res, result);
		float a = 0;
	}
	else
	{
		mat4 childRes;
		auto top = stack.top();
		stack.pop();
		_CalculateNodeTransform(stack, &childRes);

		mat4 result;

		mat4_mul_mat4(*top, childRes, result);
		mat4_copy(*res, result);
		float a = 0;
	}
}
Exemple #21
0
	void endEvent()
	{
		auto now = std::chrono::duration_cast<time_unit>(
					std::chrono::high_resolution_clock::now() - frameBegin);
		RW_CHECK(currentStack.size() > 0, "Perf stack is empty");
		currentStack.top().end = now.count();
		if (currentStack.size() == 1) {
			frame.childProfiles.push_back(currentStack.top());
			currentStack.pop();
		}
		else {
			auto tmp = currentStack.top();
			currentStack.pop();
			currentStack.top().childProfiles.push_back(tmp);
		}
	}
 indri::lang::Node* after( indri::lang::RawScorerNode* oldNode, indri::lang::RawScorerNode* newNode ) {
   if( newNode->getContext() == 0 && _restrictions.size() ) {
     newNode->setContext( _restrictions.top()->getField() );         
   }
   _nodes.push_back( newNode ); // should track for free.
   return newNode;
 }
void possibleAns(char *outstr, int counrOut, char *inA, int posA, char *inB, int posB, std::stack<char> mystack){
	if(posB == strlen(inB)){
		int x;
		for(x =0;x<strlen(inB)*2 -1;x++)
			printf("%c ",outstr[x]);
		printf("%c\n",outstr[x]);
	}
	else if(posA != strlen(inA)){	
		while((mystack.size() == 0 || mystack.top() != inB[posB]) && posA != strlen(inA)){
			mystack.push(inA[posA]);
			outstr[counrOut]='i';
			posA++; counrOut++;		
		}
		
		if(posA != strlen(inA)){
            outstr[counrOut]='i'; 
            mystack.push(inA[posA]);          
			possibleAns(outstr, counrOut +1, inA,  posA +1 ,  inB,  posB, mystack);
			mystack.pop(); 
        }
		if(mystack.top() == inB[posB]){
			outstr[counrOut]='o'; mystack.pop(); 	
			possibleAns(outstr, counrOut + 1, inA,  posA,  inB,  posB+1, mystack);
		}
	}
	else if(posA == strlen(inA) && mystack.top() == inB[posB] && posB != strlen(inB)){
        outstr[counrOut]='o'; mystack.pop(); 	
		possibleAns(outstr, counrOut + 1, inA,  posA,  inB,  posB+1, mystack);		
    }	
}
Exemple #24
0
 void pop_elem(std::stack<int> &s1,std::stack<int> &s2)
{
	while(s1.size()!=0)
	{
		int top=s1.top();
		s1.pop();
		s2.push(top);
	}
	if(s2.size()==0)
	{
		cout<<"empty\n";
		return;
	}
	int n=s2.top();
	s2.pop();
	cout<<" "<<n<<"\n";
}
Exemple #25
0
static pstring pop_check(std::stack<pstring> &stk, const pstring &expr)
{
	if (stk.size() == 0)
		throw plib::pexception(plib::pfmt("nld_function: stack underflow during infix parsing of: <{1}>")(expr));
	pstring res = stk.top();
	stk.pop();
	return res;
}
Exemple #26
0
void StateManager::Update()
{
	if(state_changed)
		state_changed = false;

	if(states.size() > 0)
		states.top()->Update();
}
 ~StackDeleter() {
   if( _stack ) {
     while( _stack->size() ) {
       delete _stack->top();
       _stack->pop();
     }
   }
 }
 /// Pop the uppermost pointer to TraceSlice if any
 inline TRACE_SLICE_TYPE * pop() {
   if (content.size() > 0) {
     TRACE_SLICE_TYPE * res = content.top(); content.pop(); return res;
   }
   else {
     return new TRACE_SLICE_TYPE(H,mydiagop,slice_size,NonVanishingOpsOnBlock);
   }
 }
Exemple #29
0
void display_stack(std::stack<int> s3)
{
	while(s3.size()!=0)
	{
		cout<<" "<<s3.top();
		s3.pop();
	}
	cout<<endl;
}
Exemple #30
0
void StateManager::Draw()
{
	if(states.size() > 0 && !state_changed)
	{
		WindowManager::Begin();
		states.top()->Draw();
		WindowManager::End();
	}
}