本文整理汇总了C++中KeyValue::SetInteger方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyValue::SetInteger方法的具体用法?C++ KeyValue::SetInteger怎么用?C++ KeyValue::SetInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValue
的用法示例。
在下文中一共展示了KeyValue::SetInteger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
//.........这里部分代码省略.........
}
// Adds null terminator to end of string
string[stringPos] = NULL;
Next(pos); // Advances to the character after the ending quotes
// Tells the key value what it is holding
val->SetKeyValueType(TYPE_STRING);
val->SetString(string);
}
else if(isdigit(m_fileContents[pos.pos]) || m_fileContents[pos.pos] == '-')
{
int integer = 0, fraction = 0;
// string big enough to hold an 32 bit integer
char num[11];
bool isNegitive = false;
if(m_fileContents[pos.pos] == '-')
{
// Tells that the number is negitive
isNegitive = true;
//Advanes to the actual first number
Next(pos);
//Gets rid of any spaces that might be inbetween the negitive sign
// and the start of the number
while(isspace(m_fileContents[pos.pos]))
Next(pos);
}
// Read until a space is hit or a . is hit for a real number or the semi colon
int i = 0;
while(isdigit(m_fileContents[pos.pos]))
{
num[i++] = m_fileContents[pos.pos];
Next(pos);
if(i >= 10) // Bigger number then the 2 billion of a 4 byte integer
{
cerr << "Integer Overflow. Line: " << pos.line << endl;
break;
}
}
// Puts null terminator at the end of the string
num[i] = 0;
// figures out the integer value
integer = isNegitive ? -atoi(num) : atoi(num);
// if there is a fraction part to the number
if(m_fileContents[pos.pos] == '.')
{
Next(pos);
i = 0;
while(isdigit(m_fileContents[pos.pos]))
{
num[i++] = m_fileContents[pos.pos];
Next(pos);
if(i >= 10) // Bigger number then the 2 billion of a 4 byte integer
{
// Prints error message
cerr << "Integer Overflow. Line: " << pos.line << endl;
// Advances the position past the rest of the number
while(isdigit(m_fileContents[pos.pos]))
Next(pos);
break;
}
}
// add null termintaor to string
num[i] = 0;
// figures out the fractal part
fraction = atoi(num);
//Tells the key value what it is holding
val->SetKeyValueType(TYPE_REAL);
if(isNegitive)
val->SetReal(integer - fraction / (float)pow((double)10, (double)strlen(num)));
else
val->SetReal(integer + fraction / (float)pow((double)10, (double)strlen(num)));
}
else
{
// Tells the key value what it is holding
val->SetKeyValueType(TYPE_INTEGER);
// Update position to after the
val->SetInteger(integer);
}
}
return val;
}