Skip to content

Commit

Permalink
Main: deprecate StringConverter::isNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Aug 26, 2024
1 parent 371b4d4 commit f62395c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 88 deletions.
4 changes: 2 additions & 2 deletions OgreMain/include/OgreStringConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ namespace Ogre {

/// @deprecated use StringUtil::split
OGRE_DEPRECATED static StringVector parseStringVector(const String& val) { return StringUtil::split(val); }
/** Checks the String is a valid number value. */
static bool isNumber(const String& val);
/// @deprecated use @ref parse()
OGRE_DEPRECATED static bool isNumber(const String& val);

static locale_t _numLocale;
private:
Expand Down
122 changes: 36 additions & 86 deletions OgreMain/src/OgreScriptTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,9 +2003,9 @@ namespace Ogre{
}

}
else if(StringConverter::isNumber(atom->value))
else if(getValue(*i0, uival))
{
mPass->setPassIterationCount(Ogre::StringConverter::parseInt(atom->value));
mPass->setPassIterationCount(uival);

AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1);
if(i1 != prop->values.end() && (*i1)->type == ANT_ATOM)
Expand Down Expand Up @@ -2043,11 +2043,9 @@ namespace Ogre{
AbstractNodeList::const_iterator i2 = getNodeAt(prop->values, 2);
if(i2 != prop->values.end() && (*i2)->type == ANT_ATOM)
{
atom = (AtomAbstractNode*)(*i2).get();
if(StringConverter::isNumber(atom->value))
if(getValue(*i2, uival))
{
mPass->setLightCountPerIteration(
static_cast<unsigned short>(StringConverter::parseInt(atom->value)));
mPass->setLightCountPerIteration(static_cast<unsigned short>(uival));

AbstractNodeList::const_iterator i3 = getNodeAt(prop->values, 3);
if(i3 != prop->values.end() && (*i3)->type == ANT_ATOM)
Expand Down Expand Up @@ -2136,43 +2134,19 @@ namespace Ogre{

Real constant = 0.0f, linear = 1.0f, quadratic = 0.0f;

if(i1 != prop->values.end() && (*i1)->type == ANT_ATOM)
{
AtomAbstractNode *atom = (AtomAbstractNode*)(*i1).get();
if(StringConverter::isNumber(atom->value))
constant = StringConverter::parseReal(atom->value);
else
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
}
else
if(i1 == prop->values.end() || !getValue(*i1, constant))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
(*i1)->getValue() + " is not a valid number");
}

if(i2 != prop->values.end() && (*i2)->type == ANT_ATOM)
{
AtomAbstractNode *atom = (AtomAbstractNode*)(*i2).get();
if(StringConverter::isNumber(atom->value))
linear = StringConverter::parseReal(atom->value);
else
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
}
else
if(i2 == prop->values.end() || !getValue(*i2, linear))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
(*i2)->getValue() + " is not a valid number");
}

if(i3 != prop->values.end() && (*i3)->type == ANT_ATOM)
{
AtomAbstractNode *atom = (AtomAbstractNode*)(*i3).get();
if(StringConverter::isNumber(atom->value))
quadratic = StringConverter::parseReal(atom->value);
else
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
}
else
if(i3 == prop->values.end() && !getValue(*i3, quadratic))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
(*i3)->getValue() + " is not a valid number");
Expand Down Expand Up @@ -2717,27 +2691,19 @@ namespace Ogre{
else
{
AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1);
if((*i1)->type == ANT_ATOM && StringConverter::isNumber(((AtomAbstractNode*)(*i1).get())->value))
uint32 nframes = 0;
if(getValue(*i1, nframes))
{
// Short form
AbstractNodeList::const_iterator i0 = getNodeAt(prop->values, 0), i2 = getNodeAt(prop->values, 2);
if((*i0)->type == ANT_ATOM && (*i1)->type == ANT_ATOM)
String val0;
Real val2;
if(getValue(*i0, val0) && getValue(*i2, val2))
{
String val0;
uint32 val1;
Real val2;
if(getString(*i0, &val0) && getUInt(*i1, &val1) && getReal(*i2, &val2))
{
ProcessResourceNameScriptCompilerEvent evt(ProcessResourceNameScriptCompilerEvent::TEXTURE, val0);
compiler->_fireEvent(&evt, 0);
ProcessResourceNameScriptCompilerEvent evt(ProcessResourceNameScriptCompilerEvent::TEXTURE, val0);
compiler->_fireEvent(&evt, 0);

mUnit->setAnimatedTextureName(evt.mName, val1, val2);
}
else
{
compiler->addError(ScriptCompiler::CE_NUMBEREXPECTED, prop->file, prop->line,
"anim_texture short form requires a texture name, number of frames, and animation duration");
}
mUnit->setAnimatedTextureName(evt.mName, nframes, val2);
}
else
{
Expand Down Expand Up @@ -3777,21 +3743,20 @@ namespace Ogre{
return;
}

String name;
uint32 index = 0;

AtomAbstractNode *atom0 = (AtomAbstractNode*)(*i0).get(), *atom1 = (AtomAbstractNode*)(*i1).get();
if(!named && !StringConverter::isNumber(atom0->value))
{
compiler->addError(ScriptCompiler::CE_NUMBEREXPECTED, prop->file, prop->line,
"parameter index expected");
return;
}

String name;
size_t index = 0;
// Assign the name/index
if(named)
name = atom0->value;
else
index = StringConverter::parseInt(atom0->value);
else if(!getValue(*i0, index))
{
compiler->addError(ScriptCompiler::CE_NUMBEREXPECTED, prop->file, prop->line,
atom0->value);
return;
}

// Determine the type
if(atom1->value == "matrix4x4")
Expand Down Expand Up @@ -3899,7 +3864,7 @@ namespace Ogre{

if(prop->values.size() >= 2)
{
size_t index = 0;
uint32 index = 0;
AbstractNodeList::const_iterator i0 = getNodeAt(prop->values, 0),
i1 = getNodeAt(prop->values, 1), i2 = getNodeAt(prop->values, 2), i3 = getNodeAt(prop->values, 3);
if((*i0)->type != ANT_ATOM || (*i1)->type != ANT_ATOM)
Expand All @@ -3909,18 +3874,16 @@ namespace Ogre{
return;
}
AtomAbstractNode *atom0 = (AtomAbstractNode*)(*i0).get(), *atom1 = (AtomAbstractNode*)(*i1).get();
if(!named && !StringConverter::isNumber(atom0->value))

if(named)
name = atom0->value;
else if(!getValue(*i0, index))
{
compiler->addError(ScriptCompiler::CE_NUMBEREXPECTED, prop->file, prop->line,
"parameter index expected");
return;
}

if(named)
name = atom0->value;
else
index = StringConverter::parseInt(atom0->value);

// Look up the auto constant
StringUtil::toLowerCase(atom1->value);
const GpuProgramParameters::AutoConstantDefinition *def =
Expand Down Expand Up @@ -4613,6 +4576,7 @@ namespace Ogre{
obj->context = mTechnique;

String sval;
uint32 uival;

for(auto & i : obj->children)
{
Expand Down Expand Up @@ -4691,20 +4655,13 @@ namespace Ogre{
}
// advance to next to get scaling
it = getNodeAt(prop->values, static_cast<int>(atomIndex++));
if(prop->values.end() == it || (*it)->type != ANT_ATOM)
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
return;
}
atom = (AtomAbstractNode*)(*it).get();
if (!StringConverter::isNumber(atom->value))
if(prop->values.end() == it || !getValue(*it, *pFactor))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
return;
}

*pSize = 0;
*pFactor = StringConverter::parseReal(atom->value);
*pSetFlag = true;
}
break;
Expand Down Expand Up @@ -4733,32 +4690,25 @@ namespace Ogre{
{
// advance to next to get the ID
it = getNodeAt(prop->values, static_cast<int>(atomIndex++));
if(prop->values.end() == it || (*it)->type != ANT_ATOM)
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
return;
}
atom = (AtomAbstractNode*)(*it).get();
if (!StringConverter::isNumber(atom->value))
if(prop->values.end() == it || !getValue(*it, uival))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
return;
}

depthBufferId = Math::uint16Cast(StringConverter::parseInt(atom->value));
depthBufferId = Math::uint16Cast(uival);
}
break;
default:
if (StringConverter::isNumber(atom->value))
if (StringConverter::parse(atom->value, uival))
{
if (atomIndex == 2)
{
width = StringConverter::parseInt(atom->value);
width = uival;
widthSet = true;
}
else if (atomIndex == 3)
{
height = StringConverter::parseInt(atom->value);
height = uival;
heightSet = true;
}
else
Expand Down

0 comments on commit f62395c

Please sign in to comment.