Ejemplo n.º 1
0
vector<int>
ObjModelLoader::extractFaceComponents(const string& s)
{
	/*
	 * Bitfield for components:
	 * 1 0 1	(example) vertex and normal present but no texture coords
	 */
	int bitField = 0;
	vector<int> result(4);
	//cout << "Original: " << s << endl;
	//cout << "Kopie   : ";

	string token;
	istringstream isstream(s);
	int componentCount = 0;
	while (getline(isstream, token, '/')) {
		if (!token.empty()) {
			bitField |= (int) (pow((double)2, (double)2 - componentCount));
			result[componentCount + 1] = atoi(token.c_str());
			//cout <<  result[componentCount+1] << "/";
		}
		//else cout << "/";

		++componentCount;
	}
	//cout << endl;
	//cout << "-------" << bitField << "-------------" << endl;
	result[0] = bitField;
	return result;
}
Ejemplo n.º 2
0
std::string SourceBlock::printLine(uint32_t line) const
{
    std::string source_line = "";
    std::istringstream isstream(m_source);
    uint16_t lineCount = 1;
    while(std::getline(isstream, source_line))
    {
        if(lineCount == line)
            return source_line;
        ++lineCount;
    }
    return "Could not extract line";
}
Ejemplo n.º 3
0
const std::string& Call::List::sqlColumnName(std::size_t column) const throw (class Exception)
{
	if (column == 4)
		return "FunctionIdentifier";
	else if (column == 5)
		return "Function";
	else if (column >= 6 && column <= 5 + sqlMaxArguments)
	{
		std::istringstream isstream("ArgumentIdentifier");
		isstream << column - 5;
		
		return isstream.str();
	}
	else if (column >= 6 + sqlMaxArguments && column <= 6 + 2 * Call::sqlMaxArguments - 1)
	{
		std::istringstream isstream("Argument");
		isstream << column - (5 + sqlMaxArguments);
		
		return isstream.str();
	}
	
	return Object::List::sqlColumnName(column);
}
Ejemplo n.º 4
0
	    //static boost::mutex io_mutex;
		bool json_parse(const std::string& strin, ptree& ptout)
		{
		    static boost::mutex io_mutex;
			boost::mutex::scoped_lock lock(io_mutex);
			if(strin.length()<=0)return false;
			try
			{
			    //LOG_BASELINE_DEBUG<<"[json] parse: in="<<strin;
				std::istringstream isstream(strin);
				boost::property_tree::json_parser::read_json(isstream, ptout);
			}
			catch(std::exception& err)
			{
                LOG_BASELINE_ERROR<< "json parse(): has error, " << err.what();
				return false;
            }
            catch(...)
            {
                LOG_BASELINE_ERROR << "json parse(): has unknown error!\n";
				return false;
            }
			return true;
		}
Ejemplo n.º 5
0
	static void _parseResponseHeader( std::map<std::string, std::string> & headerMap, const std::string & result)
	{
		headerMap.clear();
		
		std::string line;
		std::istringstream isstream(result);
		while (std::getline(isstream, line))
		{
			const std::string::size_type i = line.find( ':' );
			if (i == std::string::npos)
				continue;
			
			const std::string left = strGetLower(strGetTrim(line.substr(0,i)));
			const std::string right= strGetTrim(line.substr(i+1));
			if (left.empty())
				continue;
			
			if (headerMap.find(left) != headerMap.end()) {
				//std::cout << "WARNING : Duplicate header keyword " << left << std::endl;
			} else {
				headerMap[left] = right;
			}
		}
	}
Ejemplo n.º 6
0
int main( int ac, char** av )
{
    try
    {
        comma::command_line_options options( ac, av );
        if( options.exists( "--help,-h" ) ) { usage(); }
        verbose = options.exists( "--verbose,-v" );
        bool is_or = options.exists( "--or" );
        csv = comma::csv::options( options );
        fields = comma::split( csv.fields, ',' );
        if( fields.size() == 1 && fields[0].empty() ) { fields.clear(); }
        std::vector< std::string > unnamed = options.unnamed( "--first-matching,--or,--sorted,--input-sorted,--not-matching,--output-all,--all,--strict,--verbose,-v", "-.*" );
        //for( unsigned int i = 0; i < unnamed.size(); constraints_map.insert( std::make_pair( comma::split( unnamed[i], ';' )[0], unnamed[i] ) ), ++i );
        bool strict = options.exists( "--strict" );
        bool first_matching = options.exists( "--first-matching" );
        bool not_matching = options.exists( "--not-matching" );
        bool all = options.exists( "--output-all,--all" );
        for( unsigned int i = 0; i < unnamed.size(); ++i )
        {
            std::string field = comma::split( unnamed[i], ';' )[0];
            bool found = false;
            for( unsigned int j = 0; j < fields.size() && !found; found = field == fields[j], ++j );
            if( !found )
            {
                if( strict ) { std::cerr << "csv-select: on constraint: \"" << unnamed[i] << "\" field \"" << field << "\" not found in fields: " << csv.fields << std::endl; return 1; }
                std::cerr << "csv-select: warning: on constraint: \"" << unnamed[i] << "\" field \"" << field << "\" not found in fields: " << csv.fields << std::endl;
                continue;
            }
            constraints_map.insert( std::make_pair( field, unnamed[i] ) );
        }
        comma::signal_flag is_shutdown;
        if( csv.binary() )
        {
            #ifdef WIN32
            _setmode( _fileno( stdout ), _O_BINARY );
            #endif
            init_input( csv.format(), options );
            comma::csv::binary_input_stream< input_t > istream( std::cin, csv, input );
            while( !is_shutdown && ( istream.ready() || ( std::cin.good() && !std::cin.eof() ) ) )
            {
                const input_t* p = istream.read();
                if( !p || p->done( is_or ) ) { break; }
                char match = ( p->is_a_match( is_or ) == !not_matching ) ? 1 : 0;
                if( match || all )
                {
                    std::cout.write( istream.last(), csv.format().size() );
                    if( all ) { std::cout.write( &match, 1 ); }
                    if( csv.flush ) { std::cout.flush(); }
                    if( first_matching ) { break; }
                }
            }
        }
        else
        {
            std::string line;
            while( !is_shutdown && std::cin.good() && !std::cin.eof() )
            {
                std::getline( std::cin, line );
                line = comma::strip( line, '\r' ); // windows, sigh...
                if( !line.empty() ) { break; }
            }
            if( line.empty() ) { return 0; }
            comma::csv::format format = options.exists( "--format" )
                                      ? comma::csv::format( options.value< std::string >( "--format" ) )
                                      : guess_format( line );
            init_input( format, options );
            comma::csv::ascii_input_stream< input_t > istream( std::cin, csv, input );
            // todo: quick and dirty: no time to debug why the commented section does not work (but that's the right way)
            std::istringstream iss( line );
            comma::csv::ascii_input_stream< input_t > isstream( iss, csv, input );
            const input_t* p = isstream.read();
            if( !p || p->done( is_or ) ) { return 0; }
            bool match = p->is_a_match( is_or ) == !not_matching;
            if( match || all )
            {
                std::cout << line;
                if( all ) { std::cout << csv.delimiter << match; }
                std::cout << std::endl;
                if( first_matching ) { return 0; }
            }
            while( !is_shutdown && ( istream.ready() || ( std::cin.good() && !std::cin.eof() ) ) )
            {
                const input_t* p = istream.read();
                if( !p || p->done( is_or ) ) { break; }
                bool match = p->is_a_match( is_or ) == !not_matching;
                if( match || all )
                {
                    std::cout << comma::join( istream.last(), csv.delimiter );
                    if( all ) { std::cout << csv.delimiter << match; }
                    std::cout << std::endl;
                    if( first_matching ) { return 0; }
                }
            }
        }
        return 0;
    }
    catch( std::exception& ex ) { std::cerr << "csv-select: caught: " << ex.what() << std::endl; }
    catch( ... ) { std::cerr << "csv-select: unknown exception" << std::endl; }
    return 1;
}