From f62395c3148ca92548d870f0ca67ee5344acf39d Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Mon, 26 Aug 2024 01:19:39 +0200 Subject: [PATCH] Main: deprecate StringConverter::isNumber --- OgreMain/include/OgreStringConverter.h | 4 +- OgreMain/src/OgreScriptTranslator.cpp | 122 ++++++++----------------- 2 files changed, 38 insertions(+), 88 deletions(-) diff --git a/OgreMain/include/OgreStringConverter.h b/OgreMain/include/OgreStringConverter.h index 4a5e402d6c9..b8b5f404c98 100644 --- a/OgreMain/include/OgreStringConverter.h +++ b/OgreMain/include/OgreStringConverter.h @@ -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: diff --git a/OgreMain/src/OgreScriptTranslator.cpp b/OgreMain/src/OgreScriptTranslator.cpp index 6f22ea600ef..b190ccfb733 100644 --- a/OgreMain/src/OgreScriptTranslator.cpp +++ b/OgreMain/src/OgreScriptTranslator.cpp @@ -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) @@ -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(StringConverter::parseInt(atom->value))); + mPass->setLightCountPerIteration(static_cast(uival)); AbstractNodeList::const_iterator i3 = getNodeAt(prop->values, 3); if(i3 != prop->values.end() && (*i3)->type == ANT_ATOM) @@ -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"); @@ -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 { @@ -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") @@ -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) @@ -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 = @@ -4613,6 +4576,7 @@ namespace Ogre{ obj->context = mTechnique; String sval; + uint32 uival; for(auto & i : obj->children) { @@ -4691,20 +4655,13 @@ namespace Ogre{ } // advance to next to get scaling it = getNodeAt(prop->values, static_cast(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; @@ -4733,32 +4690,25 @@ namespace Ogre{ { // advance to next to get the ID it = getNodeAt(prop->values, static_cast(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