Skip to content

Commit

Permalink
Property: range loop refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Joilnen authored and paroj committed Apr 3, 2024
1 parent dde297d commit 10e3bde
Showing 1 changed file with 45 additions and 52 deletions.
97 changes: 45 additions & 52 deletions Components/Property/src/OgreProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ namespace Ogre
//---------------------------------------------------------------------
PropertySet::~PropertySet()
{
for (PropertyMap::iterator i = mPropertyMap.begin(); i != mPropertyMap.end(); ++i)
for (auto& p : mPropertyMap)
{
OGRE_DELETE i->second;
OGRE_DELETE p.second;
}
mPropertyMap.clear();
}
Expand All @@ -78,7 +78,7 @@ namespace Ogre
{
std::pair<PropertyMap::iterator, bool> retPair = mPropertyMap.emplace(prop->getName(), prop);
if (!retPair.second)
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Duplicate property entry!",
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Duplicate property entry!",
"PropertySet::addProperty");
}
//---------------------------------------------------------------------
Expand All @@ -94,7 +94,7 @@ namespace Ogre
if (i != mPropertyMap.end())
return i->second;
else
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Property not found!",
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Property not found!",
"PropertySet::getProperty");
}
//---------------------------------------------------------------------
Expand All @@ -106,65 +106,65 @@ namespace Ogre
PropertyValueMap PropertySet::getValueMap() const
{
PropertyValueMap ret;
for (PropertyMap::const_iterator i = mPropertyMap.begin(); i != mPropertyMap.end(); ++i)
for (const auto& p : mPropertyMap)
{
PropertyValue val;
val.propType = i->second->getType();
val.propType = p.second->getType();
switch(val.propType)
{
case PROP_SHORT:
val.val = Ogre::Any(static_cast<Property<short>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<short>*>(p.second)->get());
break;
case PROP_UNSIGNED_SHORT:
val.val = Ogre::Any(static_cast<Property<unsigned short>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<unsigned short>*>(p.second)->get());
break;
case PROP_INT:
val.val = Ogre::Any(static_cast<Property<int>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<int>*>(p.second)->get());
break;
case PROP_UNSIGNED_INT:
val.val = Ogre::Any(static_cast<Property<unsigned int>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<unsigned int>*>(p.second)->get());
break;
case PROP_LONG:
val.val = Ogre::Any(static_cast<Property<long>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<long>*>(p.second)->get());
break;
case PROP_UNSIGNED_LONG:
val.val = Ogre::Any(static_cast<Property<unsigned long>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<unsigned long>*>(p.second)->get());
break;
case PROP_REAL:
val.val = Ogre::Any(static_cast<Property<Real>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Real>*>(p.second)->get());
break;
case PROP_STRING:
val.val = Ogre::Any(static_cast<Property<String>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<String>*>(p.second)->get());
break;
case PROP_VECTOR2:
val.val = Ogre::Any(static_cast<Property<Ogre::Vector2>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Vector2>*>(p.second)->get());
break;
case PROP_VECTOR3:
val.val = Ogre::Any(static_cast<Property<Ogre::Vector3>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Vector3>*>(p.second)->get());
break;
case PROP_VECTOR4:
val.val = Ogre::Any(static_cast<Property<Ogre::Vector4>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Vector4>*>(p.second)->get());
break;
case PROP_COLOUR:
val.val = Ogre::Any(static_cast<Property<Ogre::ColourValue>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::ColourValue>*>(p.second)->get());
break;
case PROP_BOOL:
val.val = Ogre::Any(static_cast<Property<bool>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<bool>*>(p.second)->get());
break;
case PROP_QUATERNION:
val.val = Ogre::Any(static_cast<Property<Ogre::Quaternion>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Quaternion>*>(p.second)->get());
break;
case PROP_MATRIX3:
val.val = Ogre::Any(static_cast<Property<Ogre::Matrix3>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Matrix3>*>(p.second)->get());
break;
case PROP_MATRIX4:
val.val = Ogre::Any(static_cast<Property<Ogre::Matrix4>*>(i->second)->get());
val.val = Ogre::Any(static_cast<Property<Ogre::Matrix4>*>(p.second)->get());
break;
case PROP_UNKNOWN:
default:
break;
};
ret[i->second->getName()] = val;
ret[p.second->getName()] = val;
}

return ret;
Expand All @@ -174,83 +174,76 @@ namespace Ogre
//---------------------------------------------------------------------
void PropertySet::setValueMap(const PropertyValueMap& values)
{
for (PropertyValueMap::const_iterator i = values.begin(); i != values.end(); ++i)
for (const auto& v : values)
{
PropertyMap::iterator j = mPropertyMap.find(i->first);
PropertyMap::iterator j = mPropertyMap.find(v.first);
if (j != mPropertyMap.end())
{
// matching properties
// check type
if (j->second->getType() != i->second.propType)
if (j->second->getType() != v.second.propType)
{
StringStream msg;
msg << "Property " << i->first << " mismatched type; incoming type: '"
<< PropertyDef::getTypeName(i->second.propType) << "', property type: '"
msg << "Property " << v.first << " mismatched type; incoming type: '"
<< PropertyDef::getTypeName(v.second.propType) << "', property type: '"
<< PropertyDef::getTypeName(j->second->getType()) << "'";
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, msg.str(), "PropertySet::setValueMap");
}
switch(i->second.propType)
switch(v.second.propType)
{
case PROP_SHORT:
static_cast<Property<short>*>(j->second)->set(Ogre::any_cast<short>(i->second.val));
static_cast<Property<short>*>(j->second)->set(Ogre::any_cast<short>(v.second.val));
break;
case PROP_UNSIGNED_SHORT:
static_cast<Property<short>*>(j->second)->set(Ogre::any_cast<unsigned short>(i->second.val));
static_cast<Property<short>*>(j->second)->set(Ogre::any_cast<unsigned short>(v.second.val));
break;
case PROP_INT:
static_cast<Property<int>*>(j->second)->set(Ogre::any_cast<int>(i->second.val));
static_cast<Property<int>*>(j->second)->set(Ogre::any_cast<int>(v.second.val));
break;
case PROP_UNSIGNED_INT:
static_cast<Property<int>*>(j->second)->set(Ogre::any_cast<unsigned int>(i->second.val));
static_cast<Property<int>*>(j->second)->set(Ogre::any_cast<unsigned int>(v.second.val));
break;
case PROP_LONG:
static_cast<Property<long>*>(j->second)->set(Ogre::any_cast<long>(i->second.val));
static_cast<Property<long>*>(j->second)->set(Ogre::any_cast<long>(v.second.val));
break;
case PROP_UNSIGNED_LONG:
static_cast<Property<long>*>(j->second)->set(Ogre::any_cast<unsigned long>(i->second.val));
static_cast<Property<long>*>(j->second)->set(Ogre::any_cast<unsigned long>(v.second.val));
break;
case PROP_REAL:
static_cast<Property<Real>*>(j->second)->set(Ogre::any_cast<Real>(i->second.val));
static_cast<Property<Real>*>(j->second)->set(Ogre::any_cast<Real>(v.second.val));
break;
case PROP_STRING:
static_cast<Property<String>*>(j->second)->set(Ogre::any_cast<String>(i->second.val));
static_cast<Property<String>*>(j->second)->set(Ogre::any_cast<String>(v.second.val));
break;
case PROP_VECTOR2:
static_cast<Property<Ogre::Vector2>*>(j->second)->set(Ogre::any_cast<Ogre::Vector2>(i->second.val));
static_cast<Property<Ogre::Vector2>*>(j->second)->set(Ogre::any_cast<Ogre::Vector2>(v.second.val));
break;
case PROP_VECTOR3:
static_cast<Property<Ogre::Vector3>*>(j->second)->set(Ogre::any_cast<Ogre::Vector3>(i->second.val));
static_cast<Property<Ogre::Vector3>*>(j->second)->set(Ogre::any_cast<Ogre::Vector3>(v.second.val));
break;
case PROP_VECTOR4:
static_cast<Property<Ogre::Vector4>*>(j->second)->set(Ogre::any_cast<Ogre::Vector4>(i->second.val));
static_cast<Property<Ogre::Vector4>*>(j->second)->set(Ogre::any_cast<Ogre::Vector4>(v.second.val));
break;
case PROP_COLOUR:
static_cast<Property<Ogre::ColourValue>*>(j->second)->set(Ogre::any_cast<Ogre::ColourValue>(i->second.val));
static_cast<Property<Ogre::ColourValue>*>(j->second)->set(Ogre::any_cast<Ogre::ColourValue>(v.second.val));
break;
case PROP_BOOL:
static_cast<Property<bool>*>(j->second)->set(Ogre::any_cast<bool>(i->second.val));
static_cast<Property<bool>*>(j->second)->set(Ogre::any_cast<bool>(v.second.val));
break;
case PROP_QUATERNION:
static_cast<Property<Ogre::Quaternion>*>(j->second)->set(Ogre::any_cast<Ogre::Quaternion>(i->second.val));
static_cast<Property<Ogre::Quaternion>*>(j->second)->set(Ogre::any_cast<Ogre::Quaternion>(v.second.val));
break;
case PROP_MATRIX3:
static_cast<Property<Ogre::Matrix3>*>(j->second)->set(Ogre::any_cast<Ogre::Matrix3>(i->second.val));
static_cast<Property<Ogre::Matrix3>*>(j->second)->set(Ogre::any_cast<Ogre::Matrix3>(v.second.val));
break;
case PROP_MATRIX4:
static_cast<Property<Ogre::Matrix4>*>(j->second)->set(Ogre::any_cast<Ogre::Matrix4>(i->second.val));
static_cast<Property<Ogre::Matrix4>*>(j->second)->set(Ogre::any_cast<Ogre::Matrix4>(v.second.val));
break;
case PROP_UNKNOWN:
default:
break;

};


}
}


}

}

0 comments on commit 10e3bde

Please sign in to comment.