Ejemplo n.º 1
0
std::vector<std::string> qdbbot::getBashNums(std::stringstream& src)
{
	std::vector<std::string> nums;
	std::cout << "qdbbot::getBashNums: entering loop" << std::endl;
	while(!src.eof())
	{
		//char* buf = new char[GLBUFFERSIZE];
		//src.getline(buf, GLBUFFERSIZE);
	
		std::string line;
		std::getline(src, line, '\n');

		if(src.bad()){}
			//try to fail gracefully

		//delete buf;


		if(line.find("<span class=qt") != std::string::npos)
		{
			std::cout << "qdbbot::getBashNums: found a num" << std::endl;
			nums.push_back(getNum(line));
		}
	}

	std::cout << "basbot::getBashNums: finished parseing nums" << std::endl;
	return nums;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifEclipseUserDataParserTools::headerReader(std::stringstream& streamData, std::string& line)
{
    std::vector<std::string> header;

    while (!isANumber(line) && !streamData.eof())
    {
        header.push_back(line);
        std::getline(streamData, line);
    }
    return header;
}
Ejemplo n.º 3
0
void
print_stderr(std::stringstream& aStr)
{
#if defined(ANDROID)
  // On Android logcat output is truncated to 1024 chars per line, and
  // we usually use std::stringstream to build up giant multi-line gobs
  // of output. So to avoid the truncation we find the newlines and
  // print the lines individually.
  char line[1024];
  while (!aStr.eof()) {
    aStr.getline(line, sizeof(line));
    if (!aStr.eof() || strlen(line) > 0) {
      printf_stderr("%s\n", line);
    }
    if (aStr.fail()) {
      // line was too long, skip to next newline
      aStr.clear();
      aStr.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }
  }
#else
  printf_stderr("%s", aStr.str().c_str());
#endif
}
Ejemplo n.º 4
0
	/**
	 * Helper function for show_wml_messages(), which gathers
	 * the messages from a stringstream.
	 */
	void t_pump::fill_wml_messages_map(std::map<std::string, int>& msg_map, std::stringstream& source)
	{
		while(true) {
			std::string msg;
			std::getline(source, msg);

			if(source.eof()) {
				break;
			}

			if(msg == "") {
				continue;
			}

			if(msg_map.find(msg) == msg_map.end()) {
				msg_map[msg] = 1;
			} else {
				msg_map[msg]++;
			}
		}
		// Make sure the eof flag is cleared otherwise no new messages are shown
		source.clear();
	}
Ejemplo n.º 5
0
// ---------------------------------------------------------------------------
// DeserializeTree
//		Given the functionset, and a stringstream to read from this will
//		deserialize a tree from its 'text' form. Returns true on success.
//
//	Limitations:
//		Function names cannot have spaces or it will give errors deserializing
//
bool DeserializeTree( const GPFunctionLookup& functions, GPTree*& tree, std::stringstream& in_serialized )
{
	tree = NULL;
	typedef std::map< int, IntermediateNode > IntermediateNodes;
	IntermediateNodes nodes;

	in_serialized.seekg( 0, std::ios::beg );

	while( !in_serialized.eof() )
	{
		// read in one node
		std::string functionName;
		int this_node_index = -1;

		try
		{
			in_serialized >> this_node_index;
		}
		catch( const std::exception &e )
		{
			continue;
		}

		if ( nodes.find( this_node_index ) != nodes.end() || this_node_index == -1 )
		{
			continue;
		}

		in_serialized >> functionName;
		
		// grab the delayed version since we might need it. we can get the original function from the delayed info.
		const GPFuncID delayed_function_id = functions.GetFunctionIDByName( functionName.c_str(), true );
		if ( delayed_function_id == GPFunctionLookup::NULLFUNC ) 
		{
			return false;
		}
		const GPFunctionDesc&	delayed_function		= functions.GetFunctionByID( delayed_function_id );
		const GPFuncID			original_function_id	= delayed_function.m_original_function_id;

		IntermediateNode int_node;
		int_node.delayedID			= delayed_function_id;
		int_node.functionID			= original_function_id;
		int_node.finalNode			= NULL;
		int_node.referencedByIndex	= -1;
		int_node.originalReturnType	= functions.GetFunctionByID( original_function_id ).m_return_type;
		int_node.delayedReturnType	= delayed_function.m_return_type;

		for( int i = 0; i < delayed_function.m_nparams; ++i )
		{
			in_serialized >> int_node.params[ i ];
		}
		
		nodes[ this_node_index ] = int_node;
	}

	//
	// Create some placeholder nodes for the entire tree
	for( IntermediateNodes::iterator iter = nodes.begin(); iter != nodes.end(); ++iter )
	{
		IntermediateNode&		this_node		= iter->second;

		this_node.finalNode = new GPTreeNode(	this_node.functionID, 
												NULL,
												NULL,
												NULL
											);
	}

	//
	// for every node found, set its parent
	bool tree_is_intact = true;
	for( IntermediateNodes::iterator iter = nodes.begin(); iter != nodes.end() && tree_is_intact; ++iter )
	{
		IntermediateNode&		this_node		= iter->second;
		const GPFunctionDesc&	this_function	= functions.GetFunctionByID( this_node.functionID );

		for( int i = 0; i < this_function.m_nparams; ++i )
		{
			// make sure the referenced node exists!
			if ( nodes.find( this_node.params[ i ] ) == nodes.end() ) 
			{
				tree_is_intact = false;
				break;
			}

			IntermediateNode&	parameter_node		= nodes[ this_node.params[ i ] ];
			GPTypeID		param_type_required	= this_function.m_param_types[ i ];

			//
			// up until now we dont know if any node needs to use the delayed version of its function
			// since we're now linking the tree together, we can swap a node if its parent requires
			// it to be delayed.
			if ( parameter_node.originalReturnType != param_type_required )
			{
				assert( parameter_node.delayedReturnType	== param_type_required );

				parameter_node.finalNode->functionID = parameter_node.delayedID;
			}

			parameter_node.referencedByIndex = iter->first;
			parameter_node.finalNode->parent = this_node.finalNode;
			this_node.finalNode->parameters[ i ] = nodes[ this_node.params[ i ] ].finalNode;
		}
	}

	//
	// if we encountered an error setting the tree up, we need to clean up dangling ptrs
	if ( !tree_is_intact )
	{
		for( IntermediateNodes::iterator iter = nodes.begin(); iter != nodes.end(); ++iter )
		{
			IntermediateNode& this_node = iter->second;

			delete this_node.finalNode;
		}

		return false;
	}

	//
	// if all is done, find and return the parent node
	for( IntermediateNodes::iterator iter = nodes.begin(); iter != nodes.end(); ++iter )
	{
		IntermediateNode&		this_node		= iter->second;

		if ( this_node.referencedByIndex == -1 )
		{
			tree = new GPTree( GPTree::CountSubtree( this_node.finalNode ) );
			tree->Replace( NULL, this_node.finalNode );
			break;
		}
	}

	// SHOULD NEVER HIT THIS ASSERT?
	assert( tree != NULL );

	return true;
}
//------------------------------------------------------------------------------
LHDictionary::LHDictionary(std::stringstream& fileIN)
{     
    ++numberOfDicts;
    std::string lastKey = "";
    int objCounter = 0;
    std::string objText;
    
    //printf("DICT START\n");
    //printf("........................................................\n");
    //std::cout << fileIN.str() << std::endl;
    //printf("................................................................\n");    
    //file needs to start with <dict> else its not a LHDictionary file
        
    while(!fileIN.eof())
    {
        std::string line;
        getline(fileIN,line);
            
        //printf("D: c:%d %s\n", objCounter, line.c_str());
            
        if (std::string::npos != line.find("<key>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                lastKey = valueForField(line);                    
            }
        }
        else if (std::string::npos != line.find("<string>")){
                
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                setObjectForKey(new LHObject(valueForField(line)), lastKey);
            }
        }
        else if (std::string::npos != line.find("<real>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                setObjectForKey(new LHObject(floatFromString(valueForField(line))), lastKey);
            }
        }
        else if (std::string::npos != line.find("<integer>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                setObjectForKey(new LHObject(intFromString(valueForField(line))), lastKey);
            }
        }
        else if (std::string::npos != line.find("<true/>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                setObjectForKey(new LHObject(true), lastKey);
            }
        }
        else if (std::string::npos != line.find("<false/>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }else{
                setObjectForKey(new LHObject(false), lastKey);
            }
        }
        else if (std::string::npos != line.find("<dict>")){
            ++objCounter;
            if(1 < objCounter){
                objText+= line+"\n";
            }
        }
        else if (std::string::npos != line.find("</dict>")){
            if(1 < objCounter){
                objText+= line+"\n";
            }
                
            --objCounter;
            if(1 == objCounter)
            {
                std::stringstream infoText(objText);
                setObjectForKey(new LHObject(new LHDictionary(infoText)), lastKey);
                objText = "";
            }
                
            if(0 > objCounter)
            {
                objText = "";
                objCounter = 1;
            }
        }
        else if (std::string::npos != line.find("<dict/>")){
            std::stringstream dummyText;
            setObjectForKey(new LHObject(new LHDictionary(dummyText)), lastKey);
        }
        else if (std::string::npos != line.find("<array>")){
            ++objCounter;
            if(1 != objCounter){
                    objText+= line+"\n";
            }
        }
        else if (std::string::npos != line.find("</array>")){
            if(1 != objCounter){
                objText+= line+"\n";
            }
            
            --objCounter;
                
            if(1 == objCounter)
            {
                std::stringstream infoText(objText);
                setObjectForKey(new LHObject(new LHArray(infoText)), lastKey);
                objText = "";
            }
                
            if(0 > objCounter)
            {
                objText = "";
                objCounter = 1;
            }
        }
        else if (std::string::npos != line.find("<array/>")){
            setObjectForKey(new LHObject(new LHArray()), lastKey);
            //objText = "";
            //objCounter = 1;
        }
    }
    
    //printf("DICT END   ................................................................\n");    
}