Beispiel #1
0
//--------------------------------------------------------------------------------
//	@	InitializeWindow()
//--------------------------------------------------------------------------------
//		Initialize WINDOW
//--------------------------------------------------------------------------------
static bool InitializeWindow()
{
	//Fullscreen?
    std::string str;
    bool fullscreen = false;
    if (global::SETTINGS->GetValue("fullscreen", str))
    {
        fullscreen = ToBool(str);
    }

	//Dimensions
    uint32 h = 200, w = 200;
    if (global::SETTINGS->GetValue("screen_height", str))
    {
        StringToNumber(h, str, std::dec);
    }
    if (global::SETTINGS->GetValue("screen_width", str))
    {
        StringToNumber(w, str, std::dec);
    }

	global::WINDOW = new WindowManager(	w, h, fullscreen, "My Game");

    //If everything initialized fine
    return true;

}	//End: InitializeWindow()
Beispiel #2
0
void list_implementation()//list implementation
{
	list<Question> all_problems;
	list<Question> problems;
	list<Question>::iterator l_itr;
	vector<Question> temp;
	int correct_count = 0;
	ifstream myfile;
	myfile.open ("Testfile.txt");
	Question read_in("Temp", 1, "answ1", "answ2","answ3");
	for(int i=0;i<15;++i)//reads in to list
	{
		myfile>>read_in;
		all_problems.push_back(read_in);
	}
	for(l_itr=all_problems.begin(); l_itr != all_problems.end();++l_itr)//converts to vector to shuffle
	{
		temp.push_back(*l_itr);
	}
	srand(time(0));//ensures truly random shuffle by seeding system time 
	random_shuffle(temp.begin(),temp.end());//shuffles temp vector
	for(int i=0;i<10;++i)//reads into new list
	{
		problems.push_back(temp[i]);
	}
	cout<<"Loop here\n";
	for(l_itr=problems.begin(); l_itr != problems.end() ;++l_itr)//asks question + gets answers
	{
		bool correct = false;
		int answer = 0;
		string input;
		cout<<*l_itr;
		cin>>input;
		if(!is_number(input) || StringToNumber(input)<0 || StringToNumber(input)>5)
			throw runtime_error("Bad answer input");
		else
			answer = StringToNumber(input);
		if(answer == l_itr->correct_answer_num())
		{
			++correct_count;
			cout<<"Awesome work! onto the next question\n";
		}
		else
			cout<<"Aw too bad you missed that one, try another!\n";
	}
	if(correct_count>6)
		cout<<"You got "<<correct_count<<" Right, and passed Nice job!\n";
	else
		cout<<"You got "<<correct_count<<" Right, and failed, better luck next time\n";
	return;
}
QString QAutoGenDialog::GetRandomParameter(const QString & strParam, const QString & strValue, const ModelParameter & param)
{
	QString strRet;
	QStringList listRandom = QStringList::split(';', strValue);
	unsigned int iRandom = RandUInt(0, listRandom.size());
	int iSep = strValue.find(':');
	switch (param.eType & 0xF)
	{
	case ModelParameterTypeInt:
		if (iSep > -1)
			strRet = QString("%1").arg(RandInt((long)StringToNumber(strValue.left(iSep)), (long)StringToNumber(strValue.mid(iSep+1))));
		else if (!listRandom.empty())
			strRet = listRandom[iRandom];
		break;
	case ModelParameterTypeFloat:
		if (iSep > -1)
			strRet = QString("%1").arg(RandDouble(StringToNumber(strValue.left(iSep)), StringToNumber(strValue.mid(iSep+1))));
		else if (!listRandom.empty())
			strRet = listRandom[iRandom];
		break;
	case ModelParameterTypeAddress:
		strRet = GetRandomAddress(strParam);
		break;
	case ModelParameterTypeAddresses: // TODO: generate random address list
		if (!listRandom.empty())
			strRet = listRandom[iRandom];
		break;
	case ModelParameterTypeCoords:
		if (iSep > -1)
		{
			Coords ptMin, ptMax;
			ptMin.FromString(strValue.left(iSep));
			ptMax.FromString(strValue.mid(iSep+1));
			strRet = Coords(RandInt(ptMin.m_iLong, ptMax.m_iLong), RandInt(ptMin.m_iLat, ptMax.m_iLat)).ToString();
		}
		else if (!listRandom.empty())
			strRet = listRandom[iRandom];
		else
			strRet = GetRandomPosition(strParam);
		break;
	default:
		if (!listRandom.empty())
			strRet = listRandom[iRandom];
		break;
	}
	return strRet;
}
Beispiel #4
0
 void SetUp()
 {
     int n;
     sscanf(kIntString, "%d", &n); // NOLINT(runtime/printf)
     ASSERT_EQ(kInt, n);
     ASSERT_TRUE(StringToNumber(kIntString, &n));
     ASSERT_EQ(kInt, n);
 }
Beispiel #5
0
int HttpMessage::GetContentLength() {
    std::string content_length;
    if (!GetHeader("Content-Length", &content_length)) {
        return -1;
    }
    int length = 0;
    bool ret = StringToNumber(content_length, &length);
    return (ret && length >= 0) ? length : -1;
};
Beispiel #6
0
void Resume::ReadVlcResumeFile()
{

	Sleep(100); //wait for VLC to write file (TODO: make threaded)

	//get username
	TCHAR username[UNLEN + 1];
	DWORD username_len = UNLEN + 1;
	GetUserName(username, &username_len);

	RString strTemp;
	RString strVlcFile;

	//build path to vlc info file
	RString strFilePath = _T("C:\\Users\\");
	strFilePath += username;
	strFilePath += _T("\\AppData\\Roaming\\vlc\\vlc-qt-interface.ini");

	//read VLC resume file into str
	if (!FileToString(strFilePath, strVlcFile))
		return;

	if (GetFirstMatch(strVlcFile, _T("list=([^$]*?$)"), &strTemp))
	{
		strTemp.Replace(_T(" "), _T(""));
		RArray<const TCHAR*> moviesTemp = SplitString(strTemp, _T(","), true);
		size = moviesTemp.GetSize();
		if (size > MAX_SIZE) size = MAX_SIZE;

		for(int i=0; i<size; i++)
		{
			//remove % codes and turn + to space
			RString strTempMovie = URLDecode(moviesTemp[i]);

			//remove file:/// or file://
			if (strTempMovie.Left(8) == _T("file:///"))
				strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 8);
			else
				strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 5);

			strTempMovie.Replace(_T("/"), _T("\\\\"));
			movies[i] = strTempMovie;
		}
	}

	if (GetFirstMatch(strVlcFile, _T("times=([^$]*?$)"), &strTemp))
	{
		strTemp.Replace(_T(" "), _T(""));
		RArray<const TCHAR*> strTimes = SplitString(strTemp, _T(","), true);
		for(int i=0; i<strTimes.GetSize(); i++)
			times[i] = StringToNumber(strTimes[i])/1000;  //milliseconds to seconds
	}

	UpdateResumeTimes();
}
Beispiel #7
0
void vector_implementation()//Vector implementation
{
	vector<Question> vec_problems;
	int correct_count = 0;
	ifstream myfile_vec;
	myfile_vec.open ("Testfile.txt");
	Question read_in("Temp", 1, "answ1", "answ2","answ3");
	for(int i=0;i<15;++i)//reads in to vector
	{
		myfile_vec>>read_in;
		vec_problems.push_back(read_in);
	}
	srand(time(0));//ensures truly random shuffle by seeding system time
	random_shuffle(vec_problems.begin(),vec_problems.end());//shuffles vector
	for(int i=0;i<10;++i)//asks question + gets answer
	{
		bool correct = false;
		int answer = 0;
		string input;
		cout<<vec_problems[i];
		cin>>input;
		if(!is_number(input) || StringToNumber(input)<0 || StringToNumber(input)>5)
			throw runtime_error("Bad answer input");
		else
			answer = StringToNumber(input);
		if(answer == vec_problems[i].correct_answer_num())
		{
			++correct_count;
			cout<<"Awesome work! onto the next question\n";
		}
		else
			cout<<"Aw too bad you missed that one, try another!\n";
	}
	if(correct_count>6)
		cout<<"You got "<<correct_count<<" Right, and passed Nice job!\n";
	else
		cout<<"You got "<<correct_count<<" Right, and failed, better luck next time\n";
	return;
}
Beispiel #8
0
// This function is rarely used, so don't add another function pointer to
// reduce performance of most common case.
int FormatPrintArg::AsInt() const
{
    PrintSpecification spec;
    spec.specifier = 'd';
    char buffer[32];
    { // Put t into a separate scope ensure '\0' is append after written.
        BufferFormatPrintTarget t(buffer, sizeof(buffer));
        if (Write(&t, spec) <= 0)
            return -1;
    }
    int n;
    if (!StringToNumber(buffer, &n))
        return -1;
    return n;
}
Beispiel #9
0
std::string FloatConstantGenerator::GenFloatConstantImpl(
    const FieldDef &field) const {
  const auto &constant = field.value.constant;
  T v;
  auto done = StringToNumber(constant.c_str(), &v);
  FLATBUFFERS_ASSERT(done);
  if (done) {
#if (!defined(_MSC_VER) || (_MSC_VER >= 1800))
    if (std::isnan(v)) return NaN(v);
    if (std::isinf(v)) return Inf(v);
#endif
    return Value(v, constant);
  }
  return "#";  // compile time error
}
Beispiel #10
0
int SimpleCommModel::Init(const std::map<QString, QString> & mapParams)
{
	QString strValue;

	if (CarCommModel::Init(mapParams))
		return 1;

	strValue = GetParam(mapParams, SIMPLECOMMMODEL_REBROADCASTINTERVAL_PARAM, SIMPLECOMMMODEL_REBROADCASTINTERVAL_PARAM_DEFAULT);
	m_tRebroadcastInterval = MakeTime(ValidateNumber(StringToNumber(strValue), 0., HUGE_VAL));

	m_bRebroadcast = StringToBoolean(GetParam(mapParams, SIMPLECOMMMODEL_DOREBROADCAST_PARAM, SIMPLECOMMMODEL_DOREBROADCAST_PARAM_DEFAULT));

	m_bGateway = StringToBoolean(GetParam(mapParams, SIMPLECOMMMODEL_MOBILEGATEWAY_PARAM, SIMPLECOMMMODEL_MOBILEGATEWAY_PARAM_DEFAULT));

	m_bJitter = StringToBoolean(GetParam(mapParams, SIMPLECOMMMODEL_RBXJITTER_PARAM, SIMPLECOMMMODEL_RBXJITTER_PARAM_DEFAULT));

	return 0;
}
Beispiel #11
0
/********************************************
GetNumber
	Purpose
		Returns the number value for the cell.
		This number is retrieved from the cell's
		text property. 
		This function does not check to see
		if the property is set, so use the
		IsPropertySet function first.
	Params
		none
	Return 
		the number value of the cell
*********************************************/
double	CUGCell::GetNumber()
{
	if ( m_propSetFlags&UGCELL_STRING_SET )
	{
		if ( m_dataType == UGCELLDATA_NUMBER ||
			  m_dataType == UGCELLDATA_CURRENCY ||
			  m_dataType == UGCELLDATA_TIME )
		{
			return m_nNumber;
		}
		else
		{
			double returnVal;
			StringToNumber( &m_string, &returnVal );
			return returnVal;
		}
	}
	return 0;
}
TPParseTreeNode CFormulaParser::ParseSimpleExpression() {                                                                                                                                                                                                                                                                                                                                                                                                                                   
  // Numbers, identifiers
	int terminal = _tokenizer.GetToken();
	assert((terminal == kTokenIdentifier) || (terminal == kTokenNumber));
	TPParseTreeNode terminal_node = new CParseTreeNode(_tokenizer.LineRelative());
	if (terminal == kTokenIdentifier) {
		terminal_node->MakeIdentifier(_tokenizer.GetTokenString());
	}	else if (terminal == kTokenNumber) {
		CString number = _tokenizer.GetTokenString();
    // Deals with floating points, ints, hex and binary
		double value = StringToNumber(number);
		terminal_node->MakeConstant(value);
	}	else {
		assert(kThisMustNotHappen);
		terminal_node = NULL;	
	}
	write_log(preferences.debug_parser(), 
		"[FormulaParser] Terminal node %i\n", terminal_node);
	return terminal_node;
}
Beispiel #13
0
/********************************************
SetDataType
	Purpose
		Sets the data type that the cells
		text property is to be treaded as.
		valid values:
			UGCELLDATA_STRING
			UGCELLDATA_NUMBER
			UGCELLDATA_BOOL	
			UGCELLDATA_TIME	
			UGCELLDATA_CURRENCY
	Params
		type
	Return 
		UG_SUCCESS	success
		UG_ERROR	fail
*********************************************/
int	CUGCell::SetDataType(short type)
{
	if ( type == m_dataType && ( m_propSetFlags&UGCELL_DATATYPE_SET ))
		return UG_SUCCESS;

	if ( type == UGCELLDATA_NUMBER && m_propSetFlags&UGCELL_STRING_SET )
	{
		CString cellVal = GetText();
		StringToNumber( &cellVal, &m_nNumber );
		m_string = "";
	}
	else if ( type == UGCELLDATA_TIME && m_propSetFlags&UGCELL_STRING_SET )
	{
		CString cellVal = GetText();
		COleDateTime dateTime;
		dateTime.ParseDateTime( cellVal );
		m_nNumber = dateTime;
	}
	else if ( type == UGCELLDATA_CURRENCY && m_propSetFlags&UGCELL_STRING_SET )
	{
		if ( m_dataType == UGCELLDATA_NUMBER )
		{
			m_string.Format(_T("%.2f"), m_nNumber );
		}
		else
		{
			CString cellVal = GetText();
			COleCurrency currency;
			currency.ParseCurrency( cellVal );
			m_nNumber = (double)(currency.m_cur.int64 / 10000);
		}
	}

	m_dataType	= type;
	m_propSetFlags |= UGCELL_DATATYPE_SET;

	return UG_SUCCESS;
}
Beispiel #14
0
int32_t Value::GetAsNumber() const
{
    int32_t result;

    switch (mValueType)
    {
    case kInt:
    {
        result = mNumber;
        break;
    }
    case kText:
    {
        StringToNumber(mText, &result);
        break;
    }
    default:
        PDASSERT(0);
        break;
    }

    return result;
}
Beispiel #15
0
void ParseFileName(RString_ strFileName, RString &strTitle, RString &strYear, INT_PTR &nSeason, INT_PTR &nEpisode, RString &strAirDate, BYTE &bType)
{
	INT_PTR m, n;
	RString strTemp, strSeason, strEpisode;
	RString strYearTmp, strMonthTmp, strDayTmp;

	strTitle = strFileName;
	strYear.Empty();

	// only keep file name

	n = strTitle.ReverseFind(_T('\\'));
	if (n != -1)
		strTitle = strTitle.Mid(n + 1);
	//strTitle.MakeLower();

	// strip file extension (max 4 chars)

	n = strTitle.ReverseFind(_T('.'));
	if (n != -1 && strTitle.GetLength() - n < 6)
		strTitle = strTitle.Left(n);

	// replace []{} by ()

	strTitle.Replace(_T('['), _T('('));
	strTitle.Replace(_T(']'), _T(')'));
	strTitle.Replace(_T('{'), _T('('));
	strTitle.Replace(_T('}'), _T(')'));

	/*
	// replace anything not ,()0-9a-zA-Z by a space

	for (int i = 0; i < strTitle.GetLength(); i++)
	if (!(strTitle[i] == _T(',')) &&
	!(strTitle[i] == _T('\'')) &&
	!(strTitle[i] == _T('(')) &&
	!(strTitle[i] == _T(')')) &&
	!(strTitle[i] >= _T('0') && strTitle[i] <= _T('9')) &&
	!(strTitle[i] >= _T('A') && strTitle[i] <= _T('Z')) &&
	!(strTitle[i] >= _T('a') && strTitle[i] <= _T('z')))
	*((LPTSTR)(LPCTSTR)strTitle + i) = _T(' ');
	*/

	// remove urls

	RString strUrl;
	if (GetFirstMatch(strTitle, _T("([wW][wW][wW]\\.[^\\.]*?\\.[cC][oO][mM])"), &strUrl, NULL))
	{
		m = strTitle.Find(strUrl, 0);
		if (m >= 0)
			strTitle = strTitle.Left(m) + strTitle.Right(strTitle.GetLength() - (m + strUrl.GetLength()));
	}

	// replace ._ -by a space

	strTitle.Replace(_T('.'), _T(' '));
	strTitle.Replace(_T('_'), _T(' '));
	strTitle.Replace(_T('-'), _T(' '));

	// remove redundant space

	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	// find year between (), strip anything following it

	for (n = 0; (n = strTitle.Find(_T('('), n)) != -1; n++)
	{
		if (n + 5 < strTitle.GetLength() && strTitle[n + 5] == _T(')'))
		{
			strTemp = strTitle.Mid(n + 1, 4);
			if (StringToNumber(strTemp) > 1900)
			{
				strYear = strTemp;
				strTitle = strTitle.Left(n);
				break;
			}
		}
	}

	// remove anything between ()

	for (m = 0, n = 0; (m = strTitle.Find(_T('('), n)) != -1 &&
		(n = strTitle.Find(_T(')'), m)) != -1; m = 0, n = 0)
		strTitle = strTitle.Left(m) + strTitle.Mid(n + 1);

	// for TV shows. Find the season and episode and remove everything following it

	if (GetFirstMatch(strTitle, _T("([Ss]\\d?\\d[Ee]\\d?\\d)"), &strTemp, NULL))
	{
		m = strTitle.Find(strTemp, 0);
		if (GetFirstMatch(strTemp, _T("[Ss](\\d?\\d)[Ee](\\d?\\d)"), &strSeason, &strEpisode, NULL))
		{
			nSeason = StringToNumber(strSeason);
			nEpisode = StringToNumber(strEpisode);
			bType = DB_TYPE_TV;
		}

		if (m >= 0)
			strTitle = strTitle.Left(m);
	}

	// for TV shows by date and parse date aired

	if (GetFirstMatch(strTitle, _T("(\\d\\d\\d\\d) (\\d?\\d) (\\d?\\d)"), &strYearTmp, &strMonthTmp, &strDayTmp, NULL))
	{
		const RString Month[12] = { _T("Jan"), _T("Feb"), _T("Mar"), _T("Apr"),
			_T("May"), _T("Jun"), _T("Jul"), _T("Aug"), _T("Sep"), _T("Oct"), _T("Nov"), _T("Dec") };

		strAirDate = strDayTmp + _T(" ") + Month[StringToNumber(strMonthTmp) - 1] + _T(". ") + strYearTmp;
		bType = DB_TYPE_TV;
	}

	// find year not in (), but not as first word, strip anything following it

	strTitle.Replace(_T('('), _T(' '));
	strTitle.Replace(_T(')'), _T(' '));
	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	if (strYear.IsEmpty())
	{
		m = 0;
		while (m < strTitle.GetLength())
		{
			n = strTitle.Find(_T(' '), m);

			if (n == -1)
				n = strTitle.GetLength();

			if (m == n)
			{
				m = n + 1; continue;
			}

			if (n - m == 4)
			{
				strTemp = strTitle.Mid(m, n - m);
				if (StringToNumber(strTemp) > 1900 && m > 0)
				{
					strYear = strTemp;
					strTitle = strTitle.Left(m);
					break;
				}
			}

			m = n + 1;
		}
	}

	// strip 'season[s] \\d' and anything following it
	RString strSeasons;
	if (GetFirstMatch(strTitle, _T("([Ss]eason[s]? ?\\d?\\d(?: ?- ?\\d?\\d)?)"), &strSeasons, NULL))
	{
		m = strTitle.Find(strSeasons, 0);
		if (m >= 0)
			strTitle = strTitle.Left(m);
		bType = DB_TYPE_TV;
	}

	//Remove episode numbers of the form XXofYY - TODO: process to return episode number

	RString strOf;
	if (GetFirstMatch(strTitle, _T("(\\d?\\d[oO][fF]\\d?\\d)"), &strOf, NULL))
	{
		m = strTitle.Find(strOf, 0);
		if (m > 0)
			strTitle = strTitle.Left(m);
		bType = DB_TYPE_TV;
	}

	// strip common movie descriptors and everything after

	static const RString strDescriptors[] = { _T("webrip"), _T("dvdrip"), _T("dvdscr"), _T("xvid"), _T("bdrip"),
		_T("brrip"), _T("hdtv"), _T("pdtv"), _T("box set"), _T("box-set"), _T("x264") };
	foreach(strDescriptors, strD)
	{
		m = strTitle.FindNoCase(strD, 0);
		if (m > 0)
			strTitle = strTitle.Left(m);
	}
void ParseFileName(RString_ strFileName, RString &strTitle, RString &strYear)
{
	INT_PTR m, n;
	RString strTemp;

	strTitle = strFileName;
	strYear.Empty();

	// only keep file name

	n = strTitle.ReverseFind(_T('\\'));
	if (n != -1)
		strTitle = strTitle.Mid(n + 1);
	//strTitle.MakeLower();

	// strip file extension (max 4 chars)

	n = strTitle.ReverseFind(_T('.'));
	if (n != -1 && strTitle.GetLength() - n < 6)
		strTitle = strTitle.Left(n);

	// replace []{} by ()

	strTitle.Replace(_T('['), _T('('));
	strTitle.Replace(_T(']'), _T(')'));
	strTitle.Replace(_T('{'), _T('('));
	strTitle.Replace(_T('}'), _T(')'));

	/*
	// replace anything not ,()0-9a-zA-Z by a space

	for (int i = 0; i < strTitle.GetLength(); i++)
		if (!(strTitle[i] == _T(',')) &&
			!(strTitle[i] == _T('\'')) &&
			!(strTitle[i] == _T('(')) &&
			!(strTitle[i] == _T(')')) &&
			!(strTitle[i] >= _T('0') && strTitle[i] <= _T('9')) &&
			!(strTitle[i] >= _T('A') && strTitle[i] <= _T('Z')) &&
			!(strTitle[i] >= _T('a') && strTitle[i] <= _T('z')))
			*((LPTSTR)(LPCTSTR)strTitle + i) = _T(' ');
	*/

	// replace ._ by a space

	strTitle.Replace(_T('.'), _T(' '));
	strTitle.Replace(_T('_'), _T(' '));

	// remove redundant space

	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	// find year between (), strip anything following it

	for (n = 0; (n = strTitle.Find(_T('('), n)) != -1; n++)
	{
		if (n+5 < strTitle.GetLength() && strTitle[n+5] == _T(')'))
		{
			strTemp = strTitle.Mid(n+1, 4);
			if (StringToNumber(strTemp) > 1900)
			{
				strYear = strTemp;
				strTitle = strTitle.Left(n);
				break;
			}
		}
	}

	// remove anything between ()

	for (m = 0, n = 0; (m = strTitle.Find(_T('('), n)) != -1 &&
			(n = strTitle.Find(_T(')'), m)) != -1; m = 0, n = 0)
		strTitle = strTitle.Left(m) + strTitle.Mid(n+1);

	// find year not in (), but not as first word, strip anything following it

	strTitle.Replace(_T('('), _T(' '));
	strTitle.Replace(_T(')'), _T(' '));
	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	if (strYear.IsEmpty())
	{
		m = 0;
		while (true)
		{
			if (m >= strTitle.GetLength())
				break;

			n = strTitle.Find(_T(' '), m);

			if (n == -1)
				n = strTitle.GetLength();

			if (m == n)
				{m = n + 1; continue;}

			if (n - m == 4)
			{
				strTemp = strTitle.Mid(m, n - m);
				if (StringToNumber(strTemp) > 1900 && m > 0)
				{
					strYear = strTemp;
					strTitle = strTitle.Left(m);
					break;
				}
			}

			m = n + 1;
		}
	}

	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	// place some literals in front

	if (strTitle.GetLength() > 5 && strTitle.Right(5) == _T(", the"))
		strTitle = _T("the ") + strTitle.Left(strTitle.GetLength() - 5);
	if (strTitle.GetLength() > 5 && strTitle.Right(5) == _T(", The"))
		strTitle = _T("The ") + strTitle.Left(strTitle.GetLength() - 5);
	if (strTitle.GetLength() > 3 && strTitle.Right(3) == _T(", a"))
		strTitle = _T("a ") + strTitle.Left(strTitle.GetLength() - 3);
	if (strTitle.GetLength() > 3 && strTitle.Right(3) == _T(", A"))
		strTitle = _T("A ") + strTitle.Left(strTitle.GetLength() - 3);
	
	strTitle.Replace(_T(','), _T(' '));
	while (strTitle.Replace(_T("  "), _T(" ")));
	strTitle.Trim();

	//TRACE0(_T("ParseFileName\n  strFileName = ") + strFileName + _T("\n  strTitle = ") +
	//		strTitle + _T("\n  strYear = ") + strYear + _T("\n"));
}
Beispiel #17
0
TEST_F(StringNumberPerformanceTest, StringToIn64)
{
    int64_t n;
    for (int i = 0; i < 1000000; i++)
        StringToNumber(kInt64String, &n);
}
Beispiel #18
0
  bool TagBinaryCondition::Evaluate(const TagMap& tagMap) const
  {
    auto t=tagMap.find(tag);

    if (t==tagMap.end()) {
      return false;
    }

    if (valueType==string) {
      switch (binaryOperator) {
      case  operatorLess:
        return t->second<tagStringValue;
      case  operatorLessEqual:
        return t->second<=tagStringValue;
      case  operatorEqual:
        return t->second==tagStringValue;
      case operatorNotEqual:
        return t->second!=tagStringValue;
      case operatorGreaterEqual:
        return t->second>=tagStringValue;
      case  operatorGreater:
        return t->second>tagStringValue;
      default:
        assert(false);

        return false;
      }
    }
    else if (valueType==sizet) {
      size_t value;

      if (!StringToNumber(t->second,
                          value)) {
        return false;
      }

      switch (binaryOperator) {
      case  operatorLess:
        return value<tagSizeValue;
      case  operatorLessEqual:
        return value<=tagSizeValue;
      case  operatorEqual:
        return value==tagSizeValue;
      case operatorNotEqual:
        return value!=tagSizeValue;
      case operatorGreaterEqual:
        return value>=tagSizeValue;
      case  operatorGreater:
        return value>tagSizeValue;
      default:
        assert(false);

        return false;
      }
    }
    else {
      assert(false);

      return false;
    }
  }
Beispiel #19
0
TEST_F(StringNumberPerformanceTest, StringToDouble)
{
    double d;
    for (size_t i = 0; i < 100000; i++)
        StringToNumber(kDoubleString, &d);
}
bool CParsingConfig::Run(std::string strFileName)
{
    if(m_pConfigBox == NULL)
    {
        m_eParsingError = PE_NOT_SETTING_CONTAINER;
        return false;
    }

    std::ifstream inFile(strFileName);
    if(!inFile)
    {
        MakeDefaultConfigFile(strFileName);
        inFile.open(strFileName);
        
        if(!inFile.is_open())
        {
            m_eParsingError = PE_INCORRECT_FILE_PATH;
            return false;
        }
    }

    char szLine[500], szName[100], szValue[100], szTemp[100];
    char *pValue;
    int i;

    m_bLoading = true;

    m_nErrorLine = 0;
    while(!inFile.eof())
    {
        if(m_bLoading == false)
        {
            inFile.close();
            m_eParsingError = PE_STOP_BY_USER;
            return false;
        }

        m_nErrorLine++;
        inFile.getline(szLine, 500);

        for(i = 0; i < 500; i++) 
        {
            if(szLine[i] != ' ' && szLine[i] != '\t') break;
        }

        if(szLine[i] == '\n' || szLine[i] == '\0') continue;

        pValue = strtok(szLine, "=");
        if(!pValue) 
        {
            goto ParsingConfigFinish;
        }

        strncpy(szName, pValue, 100);

        pValue = strtok(NULL, "=");
        if(!pValue) 
        {
            goto ParsingConfigFinish;
        }

        while(*pValue != '\n' && *pValue != '\0')
        {
            if(*pValue == '"')
            {
                pValue++;
                if(CutString(pValue, szValue, '"') == false)
                {
                    goto ParsingConfigFinish;
                }
                break;
            }
            pValue++;
        }

        if(*pValue == '\n' || *pValue == '\0')
        {
            goto ParsingConfigFinish;
        }

        if(strstr(szName, NAME_OF_VALUE_COLUMN))
        {
            if(szValue[0] == '\0') m_pConfigBox->nValueCol = 1;
            else if(StringToNumber(szValue, m_pConfigBox->nValueCol) == false)
            {
                goto ParsingConfigFinish;
            }
        }
        else if(strstr(szName, NAME_OF_LEGEND_COLUMN))
        {
            if(szValue[0] == '\0') m_pConfigBox->nLegendCol = 0;
            else if(StringToNumber(szValue, m_pConfigBox->nLegendCol) == false)
            {
                goto ParsingConfigFinish;
            }
        }
        else if(strstr(szName, NAME_OF_X_MAG))
        {
            U32 nXmagLevel;
            if(szValue[0] == '\0') m_pConfigBox->eXmag = ML_1x;
            else if(StringToNumber(szValue, nXmagLevel) == false)
            {
                goto ParsingConfigFinish;
            }
            m_pConfigBox->eXmag = (MAG_LEVEL)nXmagLevel;
        }
        else if(strstr(szName, NAME_OF_Y_MAG))
        {
            U32 nYmagLevel;
            if(szValue[0] == '\0') m_pConfigBox->eYmag = ML_1x;
            else if(StringToNumber(szValue, nYmagLevel) == false)
            {
                goto ParsingConfigFinish;
            }
            m_pConfigBox->eYmag = (MAG_LEVEL)nYmagLevel;
        }
        else if(strstr(szName, NAME_OF_GRAPH_TYPE))
        {
            U32 nGraphType;
            if(szValue[0] == '\0') m_pConfigBox->eGraphType = GT_LINE;
            else if(StringToNumber(szValue, nGraphType) == false)
            {
                goto ParsingConfigFinish;
            }
            m_pConfigBox->eGraphType = (GRAPH_TYPE)nGraphType;
        }
        else if(pValue = strstr(szName, NAME_OF_PARAM))
        {
            // This must be like 'PARAM3_5 = "TestName"'.
            // 3 is parameter number and 5 is the real value of the parameter. 
            // "TestName" is alias of value 5.
            U32 nParamNum, nParamValue;
            pValue += strlen(NAME_OF_PARAM);

            // Get parameter number. 
            if(CutString(pValue, szTemp, '_') == false)
            {
                goto ParsingConfigFinish;
            }

            if(StringToNumber(szTemp, nParamNum) == false)
            {
                goto ParsingConfigFinish;
            }

            if(nParamNum >= MAX_NUM_OF_PARAM)
            {
                goto ParsingConfigFinish;
            }

            while(*pValue != '_') pValue++;
            pValue++;

            if(StringToNumber(pValue, nParamValue) == false)
            {
                goto ParsingConfigFinish;
            }

            m_pConfigBox->mapParamName[nParamNum][nParamValue] = szValue;                     
        }
    }

    m_bLoading = false;
    inFile.close();
    return true;

ParsingConfigFinish:
    m_bLoading = false;
    inFile.close();
    m_eParsingError = PE_LOG_FORMAT_ERROR;
    return false;
}
Beispiel #21
0
int CarModel::Init(const std::map<QString, QString> & mapParams)
{
	QString strValue;
	MapCarObject * pObject;
	Model * pModel;

	if (Model::Init(mapParams))
		return 1;

	strValue = GetParam(mapParams, CARMODEL_PARAM_DELAY, CARMODEL_PARAM_DELAY_DEFAULT);
	m_tDelay = MakeTime(ValidateNumber(StringToNumber(strValue), 0., HUGE_VAL));

	strValue = GetParam(mapParams, CARMODEL_PARAM_CARIP, CARMODEL_PARAM_CARIP_DEFAULT);
	if (!StringToIPAddress(strValue, m_ipCar))
		return 2;

	strValue = GetParam(mapParams, CARMODEL_PARAM_LOGCAR, CARMODEL_PARAM_LOGCAR_DEFAULT);
	m_bLogThisCar = StringToBoolean(strValue);

	strValue = GetParam(mapParams, CARMODEL_LINK_PARAM, CARMODEL_LINK_PARAM_DEFAULT);
	if (!g_pSimulator->m_ModelMgr.GetModel(strValue, pModel))
		return 5;
	m_pLinkModel = (CarLinkModel *)pModel;
	if (m_pLinkModel != NULL)
		m_pLinkModel->SetCar(m_ipCar);
	strValue = GetParam(mapParams, CARMODEL_PHYS_PARAM, CARMODEL_PHYS_PARAM_DEFAULT);
	if (!g_pSimulator->m_ModelMgr.GetModel(strValue, pModel))
		return 6;
	m_pPhysModel = (CarPhysModel *)pModel;
	if (m_pPhysModel != NULL)
		m_pPhysModel->SetCar(m_ipCar);

	strValue = GetParam(mapParams, CARMODEL_COMM_PARAM, CARMODEL_COMM_PARAM_DEFAULT);
	if (!g_pSimulator->m_ModelMgr.GetModel(strValue, pModel))
		return 4;
	m_pCommModel = (CarCommModel *)pModel;
	if (m_pCommModel != NULL)
		m_pCommModel->SetCar(m_ipCar);

	strValue = GetParam(mapParams, CARMODEL_TRACKSPEED_PARAM, CARMODEL_TRACKSPEED_PARAM_DEFAULT);
	m_bTrackSpeed = StringToBoolean(strValue);

	pObject = new MapCarObject(this);

//HACK: set color based on ip group
	in_addr_t temp = pObject->m_pCar->GetIPAddress();
	temp = temp>>8 & 0xFF;
	if(temp == 100) //red ones
	{
		QColor * redColor = new QColor(0xFF, 0x00, 0x00);
		pObject->SetColor(redColor->rgb());
	}
	else if(temp == 200) //black ones
	{
		QColor * redColor = new QColor(0x00, 0x00, 0x00);
		pObject->SetColor(redColor->rgb());
	}
	else //the others
	{
		pObject->SetColor(g_pMapObjects->GetColor());
	}
//end HACK

	m_iMapObjectID = g_pMapObjects->add(pObject);
	if (m_iMapObjectID == -1)
		delete pObject;

	g_pCarRegistry->addCar(this);

	m_iNextSeqNumber = 0;
	m_iNextRXSeqNumber = 0;



	return 0;
}
Beispiel #22
0
    void StartElement(const xmlChar *name, const xmlChar **atts)
    {
      if (strcmp((const char*)name,"node")==0) {
        const xmlChar *idValue=NULL;
        const xmlChar *latValue=NULL;
        const xmlChar *lonValue=NULL;

        context=contextNode;
        tags.clear();

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"id")==0) {
            idValue=atts[i+1];
          }
          else if (strcmp((const char*)atts[i],"lat")==0) {
            latValue=atts[i+1];
          }
          else if (strcmp((const char*)atts[i],"lon")==0) {
            lonValue=atts[i+1];
          }
        }

        if (idValue==NULL || lonValue==NULL || latValue==NULL) {
          std::cerr << "Not all required attributes found" << std::endl;
        }

        if (!StringToNumber((const char*)idValue,id)) {
          std::cerr << "Cannot parse id: '" << idValue << "'" << std::endl;
          return;
        }
        if (!StringToNumber((const char*)latValue,lat)) {
          std::cerr << "Cannot parse latitude: '" << latValue << "'" << std::endl;
          return;
        }
        if (!StringToNumber((const char*)lonValue,lon)) {
          std::cerr << "Cannot parse longitude: '" << lonValue << "'" << std::endl;
          return;
        }
      }
      else if (strcmp((const char*)name,"way")==0) {
        const xmlChar *idValue=NULL;

        context=contextWay;
        nodes.clear();
        members.clear();
        tags.clear();

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"id")==0) {
            idValue=atts[i+1];
          }
        }

        if (!StringToNumber((const char*)idValue,id)) {
          std::cerr << "Cannot parse id: '" << idValue << "'" << std::endl;
          return;
        }
      }
      if (strcmp((const char*)name,"relation")==0) {
        const xmlChar *idValue=NULL;

        context=contextRelation;
        tags.clear();
        nodes.clear();
        members.clear();

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"id")==0) {
            idValue=atts[i+1];
          }
        }

        if (!StringToNumber((const char*)idValue,id)) {
          std::cerr << "Cannot parse id: '" << idValue << "'" << std::endl;
          return;
        }
      }
      else if (strcmp((const char*)name,"tag")==0) {
        if (context!=contextWay && context!=contextNode && context!=contextRelation) {
          return;
        }

        const xmlChar *keyValue=NULL;
        const xmlChar *valueValue=NULL;

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"k")==0) {
            keyValue=atts[i+1];
          }
          else if (strcmp((const char*)atts[i],"v")==0) {
            valueValue=atts[i+1];
          }
        }

        if (keyValue==NULL || valueValue==NULL) {
          std::cerr << "Cannot parse tag, skipping..." << std::endl;
          return;
        }

        TagId id=typeConfig.GetTagId((const char*)keyValue);

        if (id!=tagIgnore) {
          tags[id]=(const char*)valueValue;
        }
      }
      else if (strcmp((const char*)name,"nd")==0) {
        if (context!=contextWay) {
          return;
        }

        OSMId         node;
        const xmlChar *idValue=NULL;

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"ref")==0) {
            idValue=atts[i+1];
          }
        }

        if (!StringToNumber((const char*)idValue,node)) {
          std::cerr << "Cannot parse id: '" << idValue << "'" << std::endl;
          return;
        }

        nodes.push_back(node);
      }
      else if (strcmp((const char*)name,"member")==0) {
        if (context!=contextRelation) {
          return;
        }

        RawRelation::Member member;
        const xmlChar       *typeValue=NULL;
        const xmlChar       *refValue=NULL;
        const xmlChar       *roleValue=NULL;

        for (size_t i=0; atts[i]!=NULL && atts[i+1]!=NULL; i+=2) {
          if (strcmp((const char*)atts[i],"type")==0) {
            typeValue=atts[i+1];
          }
          else if (strcmp((const char*)atts[i],"ref")==0) {
            refValue=atts[i+1];
          }
          else if (strcmp((const char*)atts[i],"role")==0) {
            roleValue=atts[i+1];
          }
        }

        if (typeValue==NULL) {
          std::cerr << "Member of relation " << id << " does not have a type" << std::endl;
          return;
        }

        if (refValue==NULL) {
          std::cerr << "Member of relation " << id << " does not have a valid reference" << std::endl;
          return;
        }

        if (roleValue==NULL) {
          std::cerr << "Member of relation " << id << " does not have a valid role" << std::endl;
          return;
        }

        if (strcmp((const char*)typeValue,"node")==0) {
          member.type=RawRelation::memberNode;
        }
        else if (strcmp((const char*)typeValue,"way")==0) {
          member.type=RawRelation::memberWay;
        }
        else if (strcmp((const char*)typeValue,"relation")==0) {
          member.type=RawRelation::memberRelation;
        }
        else {
          std::cerr << "Cannot parse member type: '" << typeValue << "'" << std::endl;
          return;
        }

        if (!StringToNumber((const char*)refValue,member.id)) {
          std::cerr << "Cannot parse ref '" << refValue << "' for relation " << id << std::endl;
        }

        if (roleValue!=NULL) {
          member.role=(const char*)roleValue;
        }

        members.push_back(member);
      }
    }
Beispiel #23
0
TEST(StringNumber, StringToNumber)
{
    int16_t i16;
    int32_t i32;
    int64_t i64;
    long long ll;
    unsigned long long ull;
    ASSERT_FALSE(StringToNumber("223372036854775807", &i32));
    ASSERT_TRUE(StringToNumber("223372036854775807", &i64));
    ASSERT_TRUE(StringToNumber("223372036854775807", &ll));
    ASSERT_TRUE(StringToNumber("223372036854775807", &ull));
    ASSERT_EQ(i64, 223372036854775807LL);
    ASSERT_EQ(ll, 223372036854775807LL);
    ASSERT_EQ(ull, 223372036854775807ULL);
    ASSERT_FALSE(StringToNumber("1147483647", &i16));
    ASSERT_TRUE(StringToNumber("1147483647", &i32));
    ASSERT_TRUE(StringToNumber("1147483647", &i64));
    ASSERT_EQ(i32, 1147483647);
    ASSERT_EQ(i64, 1147483647);

    uint32_t u32;
    ASSERT_TRUE(StringToNumber("1147483647", &u32));

    char buffer[1024];
    double d = 1.0003;

    ASSERT_STREQ(DoubleToString(d, buffer), "1.0003");
    d = std::numeric_limits<double>::infinity();
    ASSERT_STREQ(DoubleToString(d, buffer), "inf");
    d = -std::numeric_limits<double>::infinity();
    ASSERT_STREQ(DoubleToString(d, buffer), "-inf");
#ifdef __GNUC__ // divided by zero is not allowed in msvc
    d = NAN;
    ASSERT_STREQ(DoubleToString(d, buffer), "nan");
#endif

    float f = 1e+22;
    ASSERT_STREQ(FloatToString(f, buffer), "1e+22");
    f = 0.000325;
    ASSERT_STREQ(FloatToString(f, buffer), "0.000325");
    f = std::numeric_limits<double>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "inf");
    f = -std::numeric_limits<double>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "-inf");

#ifdef __GNUC__ // divided by zero is not allowed in msvc
    f = NAN;
    ASSERT_STREQ(FloatToString(f, buffer), "nan");

    f = INFINITY;
    ASSERT_STREQ(FloatToString(f, buffer), "inf");
#endif

    f = -std::numeric_limits<float>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "-inf");

    uint32_t i = 255;
    ASSERT_STREQ(UInt32ToHexString(i, buffer), "000000ff");

    std::string str = "1110.32505QQ";
    char* endptr;
    ASSERT_TRUE(ParseNumber(str.c_str(), &d, &endptr));
    ASSERT_TRUE(d == 1110.32505);
    ASSERT_FALSE(StringToNumber(str.c_str(), &d));

    ASSERT_TRUE(ParseNumber(str.c_str(), &f, &endptr));
    ASSERT_TRUE(f == 1110.32505f);
    ASSERT_FALSE(StringToNumber(str.c_str(), &f));

    ASSERT_TRUE(ParseNumber(str.c_str(), &i, &endptr));
    ASSERT_EQ(1110U, i);
    ASSERT_FALSE(StringToNumber(str.c_str(), &i));

    str = "1110.32505";
    d = 0;
    f = 0;
    i = 0;
    ASSERT_TRUE(StringToNumber(str.c_str(), &d));
    ASSERT_TRUE(d == 1110.32505);
    ASSERT_TRUE(StringToNumber(str.c_str(), &f));
    ASSERT_TRUE(f == 1110.32505f);
    ASSERT_FALSE(StringToNumber(str.c_str(), &i));
    str = "-1110";
    int32_t x;
    ASSERT_TRUE(StringToNumber(str.c_str(), &x));
    ASSERT_EQ(x, -1110);
}