Esempio n. 1
0
//Pop
void pPopMatrix(){
    projection.pop();
}
Esempio n. 2
0
	void next()
	{
		assert(_stack.size());
		node *p = _stack.top();
		_stack.pop();

		auto &gl = p->group_list;

		// acceptable state
		if (gl.empty()) {
			p->print();
			delete p;
			return;
		}

		// branch the first group
		const int start0 = gl[0].first;
		const int end0 = gl[0].second;
		for (int i = start0 + 2; i < end0; i++) {
			auto *tmp = new node;
			tmp->edge_list = p->edge_list;
			tmp->edge_list.push_back(make_pair(start0, i));
			tmp->group_list.reserve(gl.size() + 1);
			tmp->group_list.push_back(make_pair(start0+1, i-1));
			tmp->group_list.push_back(make_pair(i+1, end0));
			for (int j = 1; j < gl.size(); j++)
				tmp->group_list.push_back(gl[j]);
			_stack.push(tmp);
		}
		// edge case of the first group
		if (end0 - start0 > 1) {
			auto *tmp = new node;
			tmp->edge_list  = p->edge_list;
			tmp->edge_list.push_back(make_pair(start0, end0));
			tmp->group_list = p->group_list;
			tmp->group_list[0] = make_pair(start0+1, end0-1);
			_stack.push(tmp);
		}

		// branch the remaining groups, if any
		if (gl.size() == 1) {
			delete p;
			return;
		}
		for (int i = 1; i < gl.size(); i++) {
			const int start = gl[i].first;
			const int end = gl[i].second;
			if (end - start == 0) {
				auto *tmp = new node;
				tmp->edge_list = p->edge_list;
				tmp->edge_list.push_back(make_pair(start0, start));
				tmp->group_list.reserve(gl.size() + 1);
				if (end0 - start0)
					tmp->group_list.push_back(make_pair(start0+1, end0));
				for (int k = 1; k < i; k++)
					tmp->group_list.push_back(gl[k]);
				for (int k = i+1; k < gl.size(); k++)
					tmp->group_list.push_back(gl[k]);
				_stack.push(tmp);
				continue;
			}
			// end > start
			for (int j = start; j <= end; j++) {
				auto *tmp = new node;
				tmp->edge_list = p->edge_list;
				tmp->edge_list.push_back(make_pair(start0, j));
				tmp->group_list.reserve(gl.size() + 1);
				if (end0 - start0)
					tmp->group_list.push_back(make_pair(start0+1, end0));
				for (int k = 1; k < i; k++)
					tmp->group_list.push_back(gl[k]);

				if (j == start) {
					tmp->group_list.push_back(make_pair(start+1, end));
				} else if (j == end) {
					tmp->group_list.push_back(make_pair(start, end-1));
				} else {
					tmp->group_list.push_back(make_pair(start, j-1));
					tmp->group_list.push_back(make_pair(j+1, end));
				}

				for (int k = i+1; k < gl.size(); k++)
					tmp->group_list.push_back(gl[k]);
				_stack.push(tmp);
			}
		}
		delete p;
	}
Esempio n. 3
0
 static void pop(std::stack<T>& stk) {
     stk.pop();
 }
Esempio n. 4
0
inline void GLMatrixStack::loadIdentity() {
   matricies_.pop();
   matricies_.push(glm::mat4());   
}
Esempio n. 5
0
    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(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(atof(_curValue.c_str()));
            }

            _curValue.clear();
        }
        
        _state = SAX_NONE;
    }
Esempio n. 6
0
 double toc() {
     double outval = GetTimestampNow() / 1000000.0 - tictoc_wall_stack.top();
     tictoc_wall_stack.pop();
     return outval;
 }
Esempio n. 7
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;
}
Esempio n. 8
0
void parse_item(std::istream &s, std::stack<json::Value *> &struct_stack)
{
	// Get the object/array:
	json::Array *arr = NULL;
	json::Object *obj = NULL;
	if(struct_stack.top()->type() == json::TYPE_ARRAY)
		arr = dynamic_cast<json::Array *>(struct_stack.top());
	else
		obj = dynamic_cast<json::Object *>(struct_stack.top());

	
	// See if we've reached the end:
	char c = s.peek();
	check_stream(s);
	if((arr && c == ']')
		|| (obj && c == '}'))
	{
		s.ignore();
		check_stream(s);
		struct_stack.pop();

		if(!struct_stack.empty())
		{
			eat_whitespace(s);
		}

		return;
	}

	// Check for a comma:
	if((arr && !arr->empty())
		|| (obj && !obj->empty()))
	{
		if(c != ',')
			throw json::ParseException("Expected \',\' token.");

		s.ignore();
		check_stream(s);
		eat_whitespace(s);
	}


	// Read in a key if this is an object
	std::string key;
	if(obj)
	{
		key = read_json_string_basic(s);
		eat_whitespace(s);
		if(checked_stream_get(s) != ':')
			throw json::ParseException("Expected \':\' token.");
		eat_whitespace(s);
	}


	// Read in the actual value:
	json::Value *v = NULL;
	try
	{
		v = read_json_value(s);
		if(arr)
			arr->pushBackTake(v);
		else
			obj->takeValue(key, v);
	}
	catch(...)
	{
		delete v;
		throw;
	}

	if(v->type() == json::TYPE_ARRAY
		|| v->type() == json::TYPE_OBJECT)
	{
		struct_stack.push(v);
	}

	eat_whitespace(s);
}
Esempio n. 9
0
inline T popTop(std::stack<T> &s) {
  T result = s.top();
  s.pop();
  return result;
}
Esempio n. 10
0
void ZLResourceTreeReader::endElementHandler(const char *tag) {
	if (!myStack.empty() && (NODE == tag)) {
		myStack.pop();
	}
}
int IterativeDeepening::dfs_search(LiteState& current, int& bound, std::stack<LiteState>& path, Timer& timer) {
	
    if(!timer.is_still_valid()){
        return current.get_g();
    }
	
	// Perform heuristic evaluation
    double startTime = omp_get_wtime();
	int h = heuristic->calc_h(std::make_shared<LiteState>(current));
    heuristic_timer += (omp_get_wtime() - startTime);
    current.set_h(h);

	// Uses stack to trace path through state space
	path.push(current);

	// Bound check
	if (current.get_f() > bound){
        // Remove this state from the back of the vector
		path.pop();
		//path.erase(path.begin() + path.size() - 1);
		nodes_rejected++;
		int f = current.get_f();
		state_space.remove(std::shared_ptr<LiteState>(new LiteState(current)));
		return f;
	}

	if (state_space.state_is_goal(current, goals)){

		timer.stop_timing_search();
		print_steps(path);
		solved = true;

        std::cout << "Nodes generated during search: " << nodes_generated << std::endl;
        std::cout << "Nodes expanded during search: " << nodes_expanded << std::endl;

        std::cout << "Sequential search took " << timer.get_search_time() << " seconds." << std::endl;
        std::cout << "Time spent calculating heuristic: " << heuristic_timer << " seconds." << std::endl;
		
		return current.get_f();
	}

	nodes_expanded++;
	int min = Search::protect_goals;

	const std::vector<Operator>& applicable_operators = get_applicable_ops(current);

	for (std::size_t i = 0; i < applicable_operators.size(); i++) {

		const Operator& op = applicable_operators[i];

		// Generate successor state, set path cost
		LiteState child = get_successor(op, current);
		int new_g = current.get_g() + op.get_cost();
		child.set_g(new_g);

		// Check if state has been visited, if it has check if we have reached it in fewer steps (lower g value)
		if (state_space.child_is_duplicate(std::shared_ptr<LiteState>(new LiteState(child)))) {
			nodes_rejected++;
			continue;
		}

		// Record operator
		int op_id = op.get_num();
		child.set_op_id(op_id);

		nodes_generated++;

        int t = 0;
 		// Explore child node
		t = dfs_search(child, bound, path, timer);
		if (t < min){
			min = t;
		}
		// Get out of recursion when done. 
		if (solved){
			break;
		}
	}
	// We have generated no children that have lead to a solution and are backtracking.
	// Erase node as we backtrack through state space
	path.pop();
	return min;
}
Esempio n. 12
0
void sglPopMatrix()
{
    ctm = transformStack.top();
    transformStack.pop();
}
Esempio n. 13
0
int main()
{
    std::list<Puzzle> solutions;
    
    static std::stack<Puzzle> alternatives;
    
    char inputString[81];
    
    std::string inputPuzzle = readAndVerify(inputString);
    
    Puzzle puzzle(inputPuzzle);
    
    puzzle.generatePossibleValues();
    
    alternatives.push(puzzle);
    
    while (!alternatives.empty())
    {
        puzzle = alternatives.top();
        alternatives.pop();
        
        //decide all immediately decideable cells
        puzzle.decideCells();
        
        //try simplification strats
        bool simplificationFound = true;
        while (!puzzle.solved() && simplificationFound)
        {
            simplificationFound = false;
            do
            {
                simplificationFound = hiddenSingles(puzzle);
            }
            while (simplificationFound == true);
            
            //fall back to guessing
            if (!simplificationFound)
            {
                Puzzle alternative;
                alternative = *clone(puzzle);
                if ((simplificationFound = guess(puzzle, alternative)))
                {
                    //record alternative if guess is wrong
                    alternatives.push(alternative);
                }
            }
            
            //decide all immediately decidable cells before looking for further simplifications
            if (simplificationFound)
            {
                puzzle.decideCells();
            }
        }
        
        
        //if solution is found or contradiction is found(no simplifications)
        if (puzzle.solved())
        {
            solutions.push_back(puzzle);
        }
    }
    
    if (solutions.empty())
    {
        std::cout << "No solutions.\n";
    }
    
    if (!solutions. empty())
    {
        while (!solutions.empty())
        {
            solutions.front().printPuzzle();
            solutions.pop_front();
        }
    }
    
    std::exit(0);
    
}//end main
Esempio n. 14
0
//Pop
void mvPopMatrix(){
    model_view.pop();
}
Esempio n. 15
0
void cleanStack(std::stack<TokenBase*> st) {
  while (st.size() > 0) {
    delete resolve_reference(st.top());
    st.pop();
  }
}
Esempio n. 16
0
void STACK_ARGS call_terms (void)
{
	while (!TermFuncs.empty())
		TermFuncs.top().first(), TermFuncs.pop();
}
Esempio n. 17
0
 void pop_check_point()const
 {
    check_points.pop();
 }
Esempio n. 18
0
void evalStackOp(std::stack<Alg_bool<FR>>& S, const LogicalOps op)
{
    typedef typename Alg_bool<FR>::R1T R1T;
    auto& RS = TL<R1C<FR>>::singleton();

    // y is right argument
    const auto R = S.top();
    S.pop();
    const bool yvalue = R.value();
#ifdef USE_ASSERT
    assert(1 == R.r1Terms().size());
#endif
    const R1T y = RS->argScalar(R);

    // z is result
    bool zvalue;
    FR zwitness;
    R1T z;

    // complement takes one argument
    if (LogicalOps::CMPLMNT == op) {
        zvalue = ! yvalue;
        zwitness = boolTo<FR>(zvalue);
        z = RS->createResult(op, y, y, zwitness);

    } else {
        // x is left argument
        const auto L = S.top();
        S.pop();
        const bool xvalue = L.value();
#ifdef USE_ASSERT
        assert(1 == L.r1Terms().size());
#endif
        const R1T x = RS->argScalar(L);

        zvalue = evalOp(op, xvalue, yvalue);
        zwitness = boolTo<FR>(zvalue);

        const bool
            xIsVar = x.isVariable(),
            yIsVar = y.isVariable();

        const LogicalOps NOT = LogicalOps::CMPLMNT;

        if (xIsVar == yIsVar) {
            z = RS->createResult(op, x, y, zwitness);

        } else if (xIsVar) { // && ! yIsVar
            if (yvalue) {
                switch (op) {
                case (LogicalOps::AND) : z = x; break;
                case (LogicalOps::OR) : z = y; break;
                case (LogicalOps::XOR) : z = RS->createResult(NOT, x, x, zwitness); break;
                case (LogicalOps::SAME) : z = x; break;
                }
            } else {
                switch (op) {
                case (LogicalOps::AND) : z = y; break;
                case (LogicalOps::OR) : z = x; break;
                case (LogicalOps::XOR) : z = x; break;
                case (LogicalOps::SAME) : z = RS->createResult(NOT, x, x, zwitness); break;
                }
            }

        } else if (yIsVar) { // && ! xIsVar
            if (xvalue) {
                switch (op) {
                case (LogicalOps::AND) : z = y; break;
                case (LogicalOps::OR) : z = x; break;
                case (LogicalOps::XOR) : z = RS->createResult(NOT, y, y, zwitness); break;
                case (LogicalOps::SAME) : z = y; break;
                }
            } else {
                switch (op) {
                case (LogicalOps::AND) : z = x; break;
                case (LogicalOps::OR) : z = y; break;
                case (LogicalOps::XOR) : z = y; break;
                case (LogicalOps::SAME) : z = RS->createResult(NOT, y, y, zwitness); break;
                }
            }
        }
    }

    S.push(
        Alg_bool<FR>(zvalue, zwitness, valueBits(zvalue), {z}));
}
Esempio n. 19
0
SceneNode* addNode(int shape) {
	// Original solid
	Mesh* m = Manager->getMesh(shape);
	int id;

	if (AvailableIds.empty()) {
		id = ID++;
	} else {
		id = AvailableIds.top();
		AvailableIds.pop();
	}

	CurrentID = id;

	SceneNode* n = new SceneNode(id, shape, m, Shader, TextureId);
	n->createBufferObjects();
	n->_position = glm::vec3(0.125, 0.125, 0.125);

	// X reflection solid
	SceneNode* nX = new SceneNode(n, ReflectionX);
	nX->_toRevert = true;
	nX->createBufferObjects();

	// Z reflection solid
	SceneNode* nZ = new SceneNode(n, ReflectionZ);
	nZ->_toRevert = true;
	nZ->createBufferObjects();

	// Origin reflection solid
	SceneNode* nO = new SceneNode(n, ReflectionO);
	nO->createBufferObjects();

	n->addCopy(nX);
	n->addCopy(nZ);
	n->addCopy(nO);
	DrawingZone->addNode(n);

	switch (SymMode) {
	case SymmetryMode::NONE:
		nX->_canDraw = false;
		nZ->_canDraw = false;
		nO->_canDraw = false;
		break;
	case SymmetryMode::XAXIS:
		nZ->_canDraw = false;
		nO->_canDraw = false;
		break;
	case SymmetryMode::ZAXIS:
		nX->_canDraw = false;
		nO->_canDraw = false;
		break;
	case SymmetryMode::XZAXIS:
		break;
	case SymmetryMode::O:
		nX->_canDraw = false;
		nZ->_canDraw = false;
		break;
	}

	return n;
}
Esempio n. 20
0
 inline void pop() { stack.pop(); }
Esempio n. 21
0
inline void GLMatrixStack::popMatrix() {
   if(matricies_.size() <= 1) {
      return;
   }
   matricies_.pop();
}
Esempio n. 22
0
 void undo() {
   history.pop();
 }
Esempio n. 23
0
inline void GLMatrixStack::setPerspective(const GLfloat& fovy, const GLfloat& aspect, const GLfloat& near, const GLfloat& far) {
   matricies_.pop();
   matricies_.push(glm::perspective(fovy, aspect, near, far));
}
Esempio n. 24
0
 section::~section() {
   _stack.pop();
 }
Esempio n. 25
0
/**
 * Scan a file for includes, defines and the lot.
 * @param filename the name of the file to scan.
 * @param ext the extension of the filename.
 * @param header whether the file is a header or not.
 * @param verbose whether to give verbose debugging information.
 */
void ScanFile(const char *filename, const char *ext, bool header, bool verbose)
{
	static StringSet defines;
	static std::stack<Ignore> ignore;
	/* Copy in the default defines (parameters of depend) */
	if (!header) {
		for (StringSet::iterator it = _defines.begin(); it != _defines.end(); it++) {
			defines.insert(strdup(*it));
		}
	}

	File file(filename);
	Lexer lexer(&file);

	/* Start the lexing! */
	lexer.Lex();

	while (lexer.GetToken() != TOKEN_END) {
		switch (lexer.GetToken()) {
			/* We reached the end of the file... yay, we're done! */
			case TOKEN_END: break;

			/* The line started with a # (minus whitespace) */
			case TOKEN_SHARP:
				lexer.Lex();
				switch (lexer.GetToken()) {
					case TOKEN_INCLUDE:
						if (verbose) fprintf(stderr, "%s #include ", filename);
						lexer.Lex();
						switch (lexer.GetToken()) {
							case TOKEN_LOCAL:
							case TOKEN_GLOBAL: {
								if (verbose) fprintf(stderr, "%s", lexer.GetString());
								if (!ignore.empty() && ignore.top() != NOT_IGNORE) {
									if (verbose) fprintf(stderr, " (ignored)");
									break;
								}
								const char *h = GeneratePath(file.GetDirname(), lexer.GetString(), lexer.GetToken() == TOKEN_LOCAL);
								if (h != NULL) {
									StringMap::iterator it = _headers.find(h);
									if (it == _headers.end()) {
										it = (_headers.insert(StringMapItem(strdup(h), new StringSet()))).first;
										if (verbose) fprintf(stderr, "\n");
										ScanFile(h, ext, true, verbose);
									}
									StringMap::iterator curfile;
									if (header) {
										curfile = _headers.find(filename);
									} else {
										/* Replace the extension with the provided extension of '.o'. */
										char path[PATH_MAX];
										strcpy(path, filename);
										*(strrchr(path, '.')) = '\0';
										strcat(path, ext != NULL ? ext : ".o");
										curfile = _files.find(path);
										if (curfile == _files.end()) {
											curfile = (_files.insert(StringMapItem(strdup(path), new StringSet()))).first;
										}
									}
									if (it != _headers.end()) {
										for (StringSet::iterator header = it->second->begin(); header != it->second->end(); header++) {
											if (curfile->second->find(*header) == curfile->second->end()) curfile->second->insert(strdup(*header));
										}
									}
									if (curfile->second->find(h) == curfile->second->end()) curfile->second->insert(strdup(h));
									free(h);
								}
							}
							/* FALL THROUGH */
							default: break;
						}
						break;

					case TOKEN_DEFINE:
						if (verbose) fprintf(stderr, "%s #define ", filename);
						lexer.Lex();
						if (lexer.GetToken() == TOKEN_IDENTIFIER) {
							if (verbose) fprintf(stderr, "%s", lexer.GetString());
							if (!ignore.empty() && ignore.top() != NOT_IGNORE) {
								if (verbose) fprintf(stderr, " (ignored)");
								break;
							}
							if (defines.find(lexer.GetString()) == defines.end()) defines.insert(strdup(lexer.GetString()));
							lexer.Lex();
						}
						break;

					case TOKEN_UNDEF:
						if (verbose) fprintf(stderr, "%s #undef ", filename);
						lexer.Lex();
						if (lexer.GetToken() == TOKEN_IDENTIFIER) {
							if (verbose) fprintf(stderr, "%s", lexer.GetString());
							if (!ignore.empty() && ignore.top() != NOT_IGNORE) {
								if (verbose) fprintf(stderr, " (ignored)");
								break;
							}
							StringSet::iterator it = defines.find(lexer.GetString());
							if (it != defines.end()) {
								free(*it);
								defines.erase(it);
							}
							lexer.Lex();
						}
						break;

					case TOKEN_ENDIF:
						if (verbose) fprintf(stderr, "%s #endif", filename);
						lexer.Lex();
						if (!ignore.empty()) ignore.pop();
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;

					case TOKEN_ELSE: {
						if (verbose) fprintf(stderr, "%s #else", filename);
						lexer.Lex();
						Ignore last = ignore.empty() ? NOT_IGNORE : ignore.top();
						if (!ignore.empty()) ignore.pop();
						if (ignore.empty() || ignore.top() == NOT_IGNORE) {
							ignore.push(last == IGNORE_UNTIL_ELSE ? NOT_IGNORE : IGNORE_UNTIL_ENDIF);
						} else {
							ignore.push(IGNORE_UNTIL_ENDIF);
						}
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;
					}

					case TOKEN_ELIF: {
						if (verbose) fprintf(stderr, "%s #elif ", filename);
						lexer.Lex();
						Ignore last = ignore.empty() ? NOT_IGNORE : ignore.top();
						if (!ignore.empty()) ignore.pop();
						if (ignore.empty() || ignore.top() == NOT_IGNORE) {
							bool value = ExpressionOr(&lexer, &defines, verbose);
							ignore.push(last == IGNORE_UNTIL_ELSE ? (value ? NOT_IGNORE : IGNORE_UNTIL_ELSE) : IGNORE_UNTIL_ENDIF);
						} else {
							ignore.push(IGNORE_UNTIL_ENDIF);
						}
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;
					}

					case TOKEN_IF: {
						if (verbose) fprintf(stderr, "%s #if ", filename);
						lexer.Lex();
						if (ignore.empty() || ignore.top() == NOT_IGNORE) {
							bool value = ExpressionOr(&lexer, &defines, verbose);
							ignore.push(value ? NOT_IGNORE : IGNORE_UNTIL_ELSE);
						} else {
							ignore.push(IGNORE_UNTIL_ENDIF);
						}
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;
					}

					case TOKEN_IFDEF:
						if (verbose) fprintf(stderr, "%s #ifdef ", filename);
						lexer.Lex();
						if (lexer.GetToken() == TOKEN_IDENTIFIER) {
							bool value = defines.find(lexer.GetString()) != defines.end();
							if (verbose) fprintf(stderr, "%s[%d]", lexer.GetString(), value);
							if (ignore.empty() || ignore.top() == NOT_IGNORE) {
								ignore.push(value ? NOT_IGNORE : IGNORE_UNTIL_ELSE);
							} else {
								ignore.push(IGNORE_UNTIL_ENDIF);
							}
						}
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;

					case TOKEN_IFNDEF:
						if (verbose) fprintf(stderr, "%s #ifndef ", filename);
						lexer.Lex();
						if (lexer.GetToken() == TOKEN_IDENTIFIER) {
							bool value = defines.find(lexer.GetString()) != defines.end();
							if (verbose) fprintf(stderr, "%s[%d]", lexer.GetString(), value);
							if (ignore.empty() || ignore.top() == NOT_IGNORE) {
								ignore.push(!value ? NOT_IGNORE : IGNORE_UNTIL_ELSE);
							} else {
								ignore.push(IGNORE_UNTIL_ENDIF);
							}
						}
						if (verbose) fprintf(stderr, " -> %signore", (!ignore.empty() && ignore.top() != NOT_IGNORE) ? "" : "not ");
						break;

					default:
						if (verbose) fprintf(stderr, "%s #<unknown>", filename);
						lexer.Lex();
						break;
				}
				if (verbose) fprintf(stderr, "\n");
				/* FALL THROUGH */
			default:
				/* Ignore the rest of the garbage on this line */
				while (lexer.GetToken() != TOKEN_EOL && lexer.GetToken() != TOKEN_END) lexer.Lex();
				lexer.Lex();
				break;
		}
	}

	if (!header) {
		for (StringSet::iterator it = defines.begin(); it != defines.end(); it++) {
			free(*it);
		}
		defines.clear();
		while (!ignore.empty()) ignore.pop();
	}
}
Esempio n. 26
0
    void myQuickSort(std::vector < T > &myVec, int q, int r,
                     const int switchThresh, std::stack < std::pair < int,
                     int > >&globalTodoStack, int &numBusyThreads,
                     const int numThreads,
                     std::vector < int >&globalStackWrite)
{
    T pivot;
    int i, j;

    /* this pair consists of the new q and r values */
    std::pair < int, int >myBorder;

    /* this variable indicates, whether the present thread does useful work atm */
    bool idle = true;

    /* only thread number 0 does useful work in the beginning */
    if (q != r)
        idle = false;

    while (true) {

        /* is the partition to be processed smaller than a certain threshhold?
         * -> then use insertion sort */
        if (r - q < switchThresh) {
            myInsertSort(myVec, q, r);
            /* and mark the region as sorted, by setting q to r, which makes
             * the thread run into the next while loop, where it requests
             * new work
             */
            q = r;
        }

        /* are we done with this part of the vector?
         * -> then pop another one off the todo-Stack and process it
         */
        while (q >= r) {

            /* only one thread at the time should access the todo-Stack and
             * the numBusyThreads and idle variables */
#           pragma omp critical
            {
                /* something left on the global stack to do? */
                if (false == globalTodoStack.empty()) {
                    if (true == idle)
                        ++numBusyThreads;
                    idle = false;
                    myBorder = globalTodoStack.top();
                    globalTodoStack.pop();
                    q = myBorder.first;
                    r = myBorder.second;
                    globalStackWrite[omp_get_thread_num()]++;

                    /* nothing left to do on the stack */
                } else {
                    if (false == idle)
                        --numBusyThreads;
                    idle = true;

                    /* busy wait here (not optimal) */
                }
            }   /* end critical section */

            /* if all threads are done, break out of this function
             * note, that the value of numBusyThreads is current, as there
             * is a flush implied at the end of the last critical section */
            if (numBusyThreads == 0) {
                return;
            }
        }   /* end while ( q >= r ) */


        /* now actually sort our partition */

        /* choose pivot, initialize borders */
        pivot = myVec[r];
        i = q - 1;
        j = r;

        /* partition step, which moves smaller numbers to the left
         * and larger numbers to the right of the pivot */
        while (true) {
            while (myVec[++i] < pivot);
            while (myVec[--j] > pivot);
            if (i >= j)
                break;
            std::swap(myVec[i], myVec[j]);
        }

        std::swap(myVec[i], myVec[r]);

        /* only push on the stack, if there is enough left to do */
        if (i - 1 - q > switchThresh) {
            myBorder = std::make_pair(q, i - 1);

#           pragma omp critical
            {
                globalTodoStack.push(myBorder);
                globalStackWrite[omp_get_thread_num()]++;
            }

        } else {
            /* for small partitions use insertion sort */
            myInsertSort(myVec, q, i - 1);
        }

        q = i + 1;
        /* r stays the same for the next iteration */
    }
}
Esempio n. 27
0
void callbackEndElement(void* userdata, const char* name)
{
    //kLogPrintf("\t- %s\n",name);
    //удаляем текущий эл-т из стека (текущим становится его родитель)
    curitem.pop();
}
Esempio n. 28
0
 /// Destructor
 ~TraceSlice_Stack() {
   while (!content.empty()) {
     delete content.top();
     content.pop();
   }
 }
Esempio n. 29
0
 /// \brief emit a closing array character.
 void emitArrayEnd() {
   State.pop();
   assert((State.size() >= 1) && "Closed too many JSON elements");
   OS << "]";
 }
Esempio n. 30
0
void SampleListener::onFrame(const Controller& controller) {
	//tictoc_stack.push(clock());
	// Get the most recent frame and report some basic information
	const Frame frame = controller.frame();

	HandList hands = frame.hands();
	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
		
		const Vector normal = hand.palmNormal();
		const Vector direction = hand.direction();

		// Get the Arm bone
		Arm arm = hand.arm();

		// Get fingers
		const FingerList fingers = hand.fingers();
		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;
	
			myfile << std::string(4, ' ') << fingerNames[finger.type()]
				<< ": " << hand.palmPosition().distanceTo(finger.tipPosition());

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
			}
		}
	}

	// Get tools
	const ToolList tools = frame.tools();
	for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
		const Tool tool = *tl;
	}

	// Get gestures
	const GestureList gestures = frame.gestures();
	for (int g = 0; g < gestures.count(); ++g) {
		Gesture gesture = gestures[g];

		switch (gesture.type()) {
		case Gesture::TYPE_CIRCLE:
		{
			CircleGesture circle = gesture;
			std::string clockwiseness;

			if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
				clockwiseness = "clockwise";
			}
			else {
				clockwiseness = "counterclockwise";
			}

			// Calculate angle swept since last frame
			float sweptAngle = 0;
			if (circle.state() != Gesture::STATE_START) {
				CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
				sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
			}
			break;
		}
		case Gesture::TYPE_SWIPE:
		{
			SwipeGesture swipe = gesture;
			break;
		}
		case Gesture::TYPE_KEY_TAP:
		{
			KeyTapGesture tap = gesture;
			break;
		}
		case Gesture::TYPE_SCREEN_TAP:
		{
			ScreenTapGesture screentap = gesture;
			break;
		}
		default:
			break;
		}
	}

	if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
		std::cout << std::endl;
	}
	myfile << " Time elapsed: "
		<< ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC;
	tictoc_stack.pop();
	myfile << endl;

}