예제 #1
0
// Âà´«IntToString
string Function::convertIntToString(int &targetInt) 
{
	string tempString;
	stringstream stringStream(tempString);
	stringStream << targetInt;
	return stringStream.str();
}
예제 #2
0
파일: Config.cpp 프로젝트: rlee32/lbmpp
void Config::readSettings(const std::string& filename)
{
    std::ifstream fileStream(filename);
    std::string loadInitialFieldFromFile = "no";
    if(fileStream.is_open())
    {
        std::string line;
        while(getline(fileStream, line))
        {
            std::istringstream stringStream(line);
            std::string parameter;
            // If content available
            if(stringStream >> parameter)
            {
                if (parameter[0] == '#')
                {
                    continue;
                }
                else if(parameter == "cell_count")
                {
                    stringStream >> cell_count[0];
                    stringStream >> cell_count[1];
                }
                else if(parameter == "M")
                {
                    stringStream >> M;
                }
std::string StopWordProcessor::processQuery(std::string query)
{
	// Split query
	std::istringstream stringStream(query);
	std::istream_iterator<std::string> begin(stringStream), end;
	std::vector<std::string> tokens(begin, end);

	// Loop tokens
	for (int i = 0; i < tokens.size(); i++) {
		// check if token is in list, 
		// del stem word
		if (this->words.count(tokens[i]) > 0) {
			tokens[i] = "";
		}
	}

	std::string stemmedQuery = "";
	for (int i = 0; i < tokens.size(); i++) {
		if (tokens[i] != "") {
			stemmedQuery += tokens[i];
			if (i != tokens.size() - 1) {
				stemmedQuery += " ";
			}
		}
	}
	return stemmedQuery;
}
예제 #4
0
ConfigFileParser::ConfigFileParser(std::string filename) {
  std::ifstream file(filename, std::ifstream::in);
  std::string line, stringBuffer;
  if (!file.is_open()) {
    throw std::invalid_argument("File " + filename + " not found.");
  } else {
    while (file.good()) {
      std::getline(file, line);
      std::stringstream stringStream(line);

      if (line.length() > 0) {
        vector<std::string> strings;
        for (unsigned int i = 0; i < line.length(); i++) {
          if (line[i] == ' ') {
            strings.push_back(stringBuffer);
            stringBuffer = "";
          } else {
            std::string character(1, line[i]);
            const char* characterConstant = character.c_str();
            stringBuffer.append(characterConstant);
          }
        }
        strings.push_back(stringBuffer);
        stringBuffer = "";
        if(strings.size() >= 2){
          configMap[strings.at(0)] = strings.at(1);
        } else {
          throw std::runtime_error("Config parser is expecting two items per line.");
        }
      }
    }
    file.close();
  }
}
예제 #5
0
void TPicturesProject::readGoodDatFile(QFile & file)
{
    file.open(QIODevice::ReadOnly);
    QTextStream fileStream(&file);

    while(!fileStream.atEnd()) {
        QString string(fileStream.readLine());
        QTextStream stringStream(&string, QIODevice::ReadOnly);

        markedPictures.push_back(TMarkedPicture());
        TMarkedPictures::reference currentMarkedPicture = markedPictures.back();

        QString pictureFileName;
        stringStream >> pictureFileName;
        QFileInfo pictureFileInfo(pictureFileName);
        currentMarkedPicture.name = pictureFileInfo.fileName();

        int objectsSize = 0;
        stringStream >> objectsSize;
        for (int i = 0; i < objectsSize; ++i) {
            int left = 0;
            stringStream >> left;
            int top = 0;
            stringStream >> top;
            int width = 0;
            stringStream >> width;
            int height = 0;
            stringStream >> height;
            currentMarkedPicture.objects.push_back(QRect(left, top, width, height));
        }
    }
}
예제 #6
0
void CcrtdnParty::toPacket(PVariable value)
{
	if(!value) return;
	//Cannot currently easily be handled by ParameterConversion::toPacket
	value->binaryValue.resize(8, 0);
	if(value->stringValue.empty()) return;
	std::istringstream stringStream(value->stringValue);
	std::string element;

	//"TEMP,START_TIME,DAY,MONTH,YEAR,END_TIME,DAY,MONTH,YEAR"
	for(uint32_t i = 0; std::getline(stringStream, element, ',') && i < 9; i++)
	{
		//Temperature
		if(i == 0) value->binaryValue.at(0) = std::lround(2 * Math::getDouble(element));
		//Start time
		else if(i == 1) value->binaryValue.at(1) = Math::getNumber(element) / 30;
		//Start day
		else if(i == 2) value->binaryValue.at(2) = Math::getNumber(element);
		//Start month
		else if(i == 3) value->binaryValue.at(7) = Math::getNumber(element) << 4;
		//Start year
		else if(i == 4) value->binaryValue.at(3) = Math::getNumber(element);
		//End time
		else if(i == 5) value->binaryValue.at(4) = Math::getNumber(element) / 30;
		//End day
		else if(i == 6) value->binaryValue.at(5) = Math::getNumber(element);
		//End month
		else if(i == 7) value->binaryValue.at(7) |= Math::getNumber(element);
		//End year
		else if(i == 8) value->binaryValue.at(6) = Math::getNumber(element);
	}
	value->type = VariableType::tBinary;
}
예제 #7
0
string Function::convertDoubleToString(double &targetDouble)
{
	string tempString;
	stringstream stringStream(tempString);
	stringStream << targetDouble;
	return stringStream.str();
}
예제 #8
0
파일: aJSON.cpp 프로젝트: NonnEmilia/rmap
// Parse an object - create a new root, and populate.
aJsonObject*
aJsonClass::parse(char *value)
{
  aJsonStringStream stringStream(value, NULL);
  aJsonObject* result = parse(&stringStream);
  return result;
}
예제 #9
0
// splits a string into a vector of strings delimited by white space
std::vector<std::string> tokenizeString(std::string input)
{
	std::stringstream stringStream(input);
	std::istream_iterator<std::string> begin(stringStream);
	std::istream_iterator<std::string> end;
	std::vector<std::string> stringVector(begin, end);
	return stringVector;
}
예제 #10
0
void Reading::ValidateJson(string jsonInput)
{
	_validReading = false;

	stringstream stringStream(jsonInput);
	string validationString = "";

	stringStream >> validationString;
	if (validationString != "{")
	{
		_errorMessage = "Improper JSON format";
		return;
	}

	stringStream >> validationString;
	if (validationString != "\"")
	{
		_errorMessage = "Improper JSON format";
		return;
	}

	stringStream >> validationString;
	if (validationString != "motorVoltage")
	{
		_errorMessage = "Not a temperature reading";
		return;
	}

	stringStream >> validationString;
	if (validationString != "\"")
	{
		_errorMessage = "Improper JSON format";
		return;
	}

	stringStream >> validationString;
	if (validationString != ":")
	{
		_errorMessage = "Improper JSON format";
		return;
	}

	double tempTemperature = 0;
	stringStream >> tempTemperature;

	stringStream >> validationString;
	if (validationString != "}")
	{
		_errorMessage = "Improper JSON format";
		return;
	}

	_temperature = tempTemperature;
	_validReading = true;
	_errorMessage = "";
	return;
}
예제 #11
0
    void readfile(string filename){
        this->numberOfRecordsCounted = 1;

        ifstream infile(filename); //Open the file
        string str; // Declares a string and is used for temporary storage
        if (infile.is_open()){
            while (getline(infile,str)){
                string dateString;
                string ssnString;
                string firstName;
                string lastName;
                string stateString;

                string token;
                stringstream stringStream(str);

                //Get Birthday
                if (getline(stringStream, token, ' ')){
                    dateString = token;
                }
                //Get SSN
                if (getline(stringStream, token, ' ')){
                    ssnString = token;
                }
                //Get First Name
                if (getline(stringStream, token, ' ')){
                    firstName = token;
                }
                //Get Last Name
                if (getline(stringStream, token, ' ')){
                    lastName = token;
                }
                //Get State
                if (getline(stringStream, token, ' ')){
                    stateString = token;
                }
                //cout << "Birthdate: " << dateString << " ssn: " << ssnString << " firstname: " << firstName << " lastname: " << lastName << " state: " << stateString << endl;
                Date* birthdate = new Date(dateString); //Creates a new date object

                State* state = new State(stateString); //creating a new state
                //cout << stateString << endl;
                state = this->states->insert(state)->getData(); //add it to the list BUT if there is already a state of the same name in it, return that state instead

                Person* person = new Person(ssnString, firstName, lastName, birthdate, state);
                state->addPerson(person);
                this->people->insert(person);

                this->numberOfRecordsCounted ++;

            }
            infile.close();
        }
        else{
            cout << "Error: Unable to open file" << endl;
        }
    }
예제 #12
0
// split
vector<string> Function::split(const std::string &sourceString, char delim, std::vector<std::string> &resultVector) 
{
	stringstream stringStream(sourceString);
	string item;
	while (getline(stringStream, item, delim)) 
	{
		resultVector.push_back(item);
	}
	return resultVector;
}
예제 #13
0
	//[-------------------------------------------------------]
	//[ Public static methods                                 ]
	//[-------------------------------------------------------]
	void StringHelper::splitString(const std::string& stringToSplit, char separator, std::vector<std::string>& elements)
	{
		// Implementation from http://stackoverflow.com/a/236803
		std::stringstream stringStream(stringToSplit);
		std::string item;
		while (std::getline(stringStream, item, separator))
		{
			elements.push_back(item);
		}
	}
예제 #14
0
파일: split.cpp 프로젝트: UCBASiCS/FFAST
std::vector<std::string>& split(const std::string& string, char delimeter, std::vector<std::string>& elements)
{
    std::stringstream stringStream(string);
    std::string item;

    while (std::getline(stringStream, item, delimeter))
    {
        elements.push_back(item);
    }

    return elements;
}
예제 #15
0
char*
aJsonClass::print(aJsonObject* item)
{
  char* outBuf = (char*) malloc(PRINT_BUFFER_LEN); /* XXX: Dynamic size. */
  if (outBuf == NULL)
    {
      return NULL;
    }
  aJsonStringStream stringStream(NULL, outBuf, PRINT_BUFFER_LEN);
  print(item, &stringStream);
  return outBuf;
}
예제 #16
0
 KeyboardShortcut::KeyboardShortcut(const wxString& string) {
     wxStringInputStream stringStream(string);
     wxTextInputStream stream(stringStream, ':');
     
     wxUniChar colon;
     stream >> m_key;
     stream >> m_modifier1;
     stream >> m_modifier2;
     stream >> m_modifier3;
     
     sortModifierKeys(m_modifier1, m_modifier2, m_modifier3);
 }
예제 #17
0
void mslLoader::OBJloader::loadValue(const std::string& in_string)
{
    std::istringstream stringStream(in_string);
    std::string bufferString;

    mslMesh::point3Ddouble bufferPoint;
    mslMesh::faceWithNormal3D<int> bufferFace;

    if(in_string.find("o ") != std::string::npos)
    {
        stringStream >> meshName >> meshName;
        return;
    }
예제 #18
0
파일: aJSON.cpp 프로젝트: NonnEmilia/rmap
char*
aJsonClass::print(aJsonObject* item, size_t outBufSize )
{
  char* outBuf = (char*) malloc(outBufSize); /* XXX: Dynamic size. */
  if (outBuf == NULL)
    {
      IF_SDEBUG(Serial.print("#err aJson malloc: "));
      IF_SDEBUG(Serial.println(outBufSize));
      return NULL;
    }
  aJsonStringStream stringStream(NULL, outBuf, outBufSize);
  print(item, &stringStream);
  return outBuf;
}
예제 #19
0
void TravellingSalesman::loadPaths(istream& stream) {
		string checker;
		stream >> checker;
		if(checker.compare("NAME:") == 0) {
			loadSpecialPaths(stream);
		} else {
			std::istringstream stringStream(checker);
			int size;
			stringStream >> size;
			numberOfCities = size;
			loadNormalPaths(stream);
		}


	}
예제 #20
0
FileReader::FileReader(const char *fileName) {
	this->fileName = fileName;
	this->fileUtils = CCFileUtils::sharedFileUtils();

	this->data = (char*) fileUtils->getFileData(
			fileUtils->fullPathFromRelativePath(fileName), "r", &dataSize);

	string contents;
	contents.append(data);
	istringstream stringStream(contents);
	string line;
	while (getline(stringStream, line)) {
		lines.push_back(line);
	}
	currentLine = 0;
}
예제 #21
0
 std::string ErrorReporter::getLineOfInput(unsigned int lineNumber)
 {
     if (m_input.empty())
         return "";
     
     std::stringstream stringStream(m_input);
     std::string line;
     
     unsigned int i = 0;
     while(std::getline(stringStream, line, '\n')) {
         if (i == lineNumber)
             return line;
         
         ++i;
     }
     
     return "";
 }
예제 #22
0
std::vector<std::string> Utils::split(const std::string &_s, const std::string& delim)
{
	std::vector<std::string> parts;
	std::stringstream stringStream(_s);
	std::string line;
	while(std::getline(stringStream, line)) 
	{
		std::size_t prev = 0, pos;
		while ((pos = line.find_first_of(delim, prev)) != std::string::npos)
		{
			if (pos > prev)
				parts.push_back(line.substr(prev, pos-prev));
			prev = pos+1;
		}
		if (prev < line.length())
			parts.push_back(line.substr(prev, std::string::npos));
	}

	return parts;
}
예제 #23
0
파일: Map.cpp 프로젝트: ekispece/Fabulam
Fabulam::Map &Fabulam::Map::load(std::string fileName)
{
    ifstream mapFile;
    mapFile.open(fileName);
    string charBuffer;

    while(getline(mapFile, charBuffer))
    {
        stringstream stringStream(charBuffer);
        char ch;
        vector<short int> line;
        while (stringStream >> ch)
        {
            line.push_back((int)ch);
        }
        mapStructure.push_back(line);
    }
    mapFile.close();

    return *this;
}
예제 #24
0
bool getBlockTemplate(epee::net_utils::http::http_simple_client* client, const std::string* address, const std::string* walletAddress, size_t extraNonceSize, BlockTemplate* blockTemplate) {
  cryptonote::COMMAND_RPC_GETBLOCKTEMPLATE::request request;
  request.reserve_size = extraNonceSize;
  request.wallet_address = *walletAddress;
  cryptonote::COMMAND_RPC_GETBLOCKTEMPLATE::response response;
  bool result = epee::net_utils::invoke_http_json_rpc(*address + "/json_rpc", "getblocktemplate", request, response, *client);
  if (!result || (!response.status.empty() && response.status != CORE_RPC_STATUS_OK)) {
    return false;
  }

  std::string blockString;
  epee::string_tools::parse_hexstr_to_binbuff(response.blocktemplate_blob, blockString);
  std::istringstream stringStream(blockString);
  binary_archive<false> archive(stringStream);
  if (!serialization::serialize(archive, blockTemplate->block)) {
    return false;
  }

  blockTemplate->difficulty = response.difficulty;
  blockTemplate->height = response.height;
  return true;
}
예제 #25
0
파일: CUNO.cpp 프로젝트: marerh/Homegear
void CUNO::processData(std::vector<uint8_t>& data)
{
	try
	{
		if(data.empty()) return;
		std::string packets;
		packets.insert(packets.end(), data.begin(), data.end());

		std::istringstream stringStream(packets);
		std::string packetHex;
		while(std::getline(stringStream, packetHex))
		{
			if(packetHex.size() > 21) //21 is minimal packet length (=10 Byte + CUNO "A")
        	{
				std::shared_ptr<BidCoSPacket> packet(new BidCoSPacket(packetHex, BaseLib::HelperFunctions::getTime()));
				raisePacketReceived(packet);
        	}
        	else if(!packetHex.empty())
        	{
        		if(packetHex == "LOVF") _out.printWarning("Warning: CUNO with id " + _settings->id + " reached 1% limit. You need to wait, before sending is allowed again.");
        		else if(packetHex == "A") continue;
        		else _out.printWarning("Warning: Too short packet received: " + packetHex);
        	}
		}
	}
    catch(const std::exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(BaseLib::Exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
예제 #26
0
	vector<InstructionToken> BaseParser::Tokenize(const string& input, const string& delimiters) {
		stringstream stringStream(input);
		vector<InstructionToken> result;
		string line;
		while (getline(stringStream, line))
		{
			size_t prev = 0, pos;
			while ((pos = line.find_first_of(delimiters, prev)) != std::string::npos)
			{
				if (pos > prev) {

					result.push_back(InstructionToken(line.substr(prev, pos - prev)));
				}

				prev = pos + 1;
			}
			if (prev < line.length()) {
				result.push_back(InstructionToken(line.substr(prev, std::string::npos)));
			}

		}
		return result;
	}
예제 #27
0
파일: OLabel.cpp 프로젝트: Uliori/Origami
void OLabel::getLines()
{
    m_Lines.clear();
    m_LinesWidth.clear();
    
    std::stringstream stringStream(m_Text);
    std::string line;
    std::vector<std::string> wordVector;
    
    float rectWidth = m_Size.x - borders.x - borders.z;
    
    float currentLineLength = 0;
    while(std::getline(stringStream, line))
    {
        m_Lines.push_back("");
        m_LinesWidth.push_back(0);
        
        std::size_t prev = 0, pos;
        while ((pos = line.find_first_of(" ", prev)) != std::string::npos) //while there is a separator
        {
            if (pos > prev) { // a new word
                //handle the word
                std::string word = line.substr(prev, pos-prev);
                handleAWord(word, currentLineLength, rectWidth);
            }
            prev = pos+1;
            
            //handle the space
            handleAWord(" ", currentLineLength, rectWidth);
        }
        if (prev < line.length()){ //the latest word in a line
            //handle the word
            std::string word = line.substr(prev, std::string::npos);
            handleAWord(word, currentLineLength, rectWidth);
        }
    }
}
예제 #28
0
void Cfm::toPacket(PVariable value)
{
	if(!value) return;
	value->binaryValue.resize(14, 0);
	if(value->stringValue.empty() || value->stringValue == "0") return;
	std::istringstream stringStream(value->stringValue);
	std::string element;

	for(uint32_t i = 0; std::getline(stringStream, element, ',') && i < 13; i++)
	{
		if(i == 0)
		{
			value->binaryValue.at(0) = std::lround(200 * Math::getDouble(element));
		}
		else if(i == 1)
		{
			value->binaryValue.at(1) = Math::getNumber(element);
		}
		else if(i == 2)
		{
			value->integerValue = std::lround(Math::getDouble(element) * 10);
			IntegerTinyFloat cast(_bl);
			cast.toPacket(value);
			std::vector<uint8_t> time;
			_bl->hf.memcpyBigEndian(time, value->integerValue);
			if(time.size() == 1) value->binaryValue.at(13) = time.at(0);
			else
			{
				value->binaryValue.at(12) = time.at(0);
				value->binaryValue.at(13) = time.at(1);
			}
		}
		else value->binaryValue.at(i - 1) = Math::getNumber(element);
	}
	value->type = VariableType::tBinary;
}
예제 #29
0
파일: aJSON.cpp 프로젝트: NonnEmilia/rmap
void
aJsonClass::print(aJsonObject* item, char* outBuf, size_t outBufSize)
{
  aJsonStringStream stringStream(NULL, outBuf, outBufSize);
  print(item, &stringStream);
}