IIrrXMLReader::getAttributeValueAsInt and IIrrXMLReader::getAttributeValueAsFloat can now return a custom default-value when the attribute is not found.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5342 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2016-09-30 13:56:24 +00:00
parent 39c0393023
commit 85e14866a6
3 changed files with 25 additions and 20 deletions

View File

@ -1,6 +1,7 @@
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- IIrrXMLReader::getAttributeValueAsInt and IIrrXMLReader::getAttributeValueAsFloat can now return a custom default-value when the attribute is not found.
- core::string::split now handles ignoreEmptyTokens=false correct. Thanks @manni63 for bugreport: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=51551&p=299375#p299375 - core::string::split now handles ignoreEmptyTokens=false correct. Thanks @manni63 for bugreport: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=51551&p=299375#p299375
- Bugfix: Previously when some material had a texture matrix and another didn't those materials were still considered identical. Which had prevented correct switching between materials with and without texture matrices. - Bugfix: Previously when some material had a texture matrix and another didn't those materials were still considered identical. Which had prevented correct switching between materials with and without texture matrices.
- IWriteFile::write now returning size_t (like fwrite in c-lib). Also sizeToWrite parameter changed from u32 to size_t. - IWriteFile::write now returning size_t (like fwrite in c-lib). Also sizeToWrite parameter changed from u32 to size_t.

View File

@ -316,27 +316,31 @@ namespace io
//! Returns the value of an attribute as integer. //! Returns the value of an attribute as integer.
/** \param name Name of the attribute. /** \param name Name of the attribute.
\return Value of the attribute as integer, and 0 if an attribute with this name does not exist or \param defaultNotFound Value returned when name does not exist
the value could not be interpreted as integer. */ \return Value of the attribute as integer or value of defaultNotFound
virtual int getAttributeValueAsInt(const char_type* name) const = 0; when name was not found or 0 when value could not be interpreted as integer */
virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0;
//! Returns the value of an attribute as integer. //! Returns the value of an attribute as integer.
/** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
\return Value of the attribute as integer, and 0 if an attribute with this index does not exist or \param defaultNotFound Value returned when index does not exist.
the value could not be interpreted as integer. */ \return Value of the attribute as integer or value of defaultNotFound parameter for invalid index
virtual int getAttributeValueAsInt(int idx) const = 0; or 0 when value could not be interpreted as integer */
virtual int getAttributeValueAsInt(int idx, int defaultNotFound=0) const = 0;
//! Returns the value of an attribute as float. //! Returns the value of an attribute as float.
/** \param name: Name of the attribute. /** \param name: Name of the attribute.
\return Value of the attribute as float, and 0 if an attribute with this name does not exist or \param defaultNotFound Value returned when name does not exist.
the value could not be interpreted as float. */ \return Value of the attribute as float or value of defaultNotFound parameter on failure
virtual float getAttributeValueAsFloat(const char_type* name) const = 0; or 0 when value could not be interpreted as float. */
virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0;
//! Returns the value of an attribute as float. //! Returns the value of an attribute as float.
/** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
\return Value of the attribute as float, and 0 if an attribute with this index does not exist or \param defaultNotFound Value returned when index does not exist.
the value could not be interpreted as float. */ \return Value of the attribute as float or value of defaultNotFound parameter on failure
virtual float getAttributeValueAsFloat(int idx) const = 0; or 0 when value could not be interpreted as float. */
virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0;
//! Returns the name of the current node. //! Returns the name of the current node.
/** Only valid, if the node type is EXN_ELEMENT. /** Only valid, if the node type is EXN_ELEMENT.

View File

@ -136,11 +136,11 @@ public:
//! Returns the value of an attribute as integer. //! Returns the value of an attribute as integer.
virtual int getAttributeValueAsInt(const char_type* name) const _IRR_OVERRIDE_ virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound) const _IRR_OVERRIDE_
{ {
const SAttribute* attr = getAttributeByName(name); const SAttribute* attr = getAttributeByName(name);
if (!attr) if (!attr)
return 0; return defaultNotFound;
core::stringc c(attr->Value.c_str()); core::stringc c(attr->Value.c_str());
return core::strtol10(c.c_str()); return core::strtol10(c.c_str());
@ -148,11 +148,11 @@ public:
//! Returns the value of an attribute as integer. //! Returns the value of an attribute as integer.
virtual int getAttributeValueAsInt(int idx) const _IRR_OVERRIDE_ virtual int getAttributeValueAsInt(int idx, int defaultNotFound) const _IRR_OVERRIDE_
{ {
const char_type* attrvalue = getAttributeValue(idx); const char_type* attrvalue = getAttributeValue(idx);
if (!attrvalue) if (!attrvalue)
return 0; return defaultNotFound;
core::stringc c(attrvalue); core::stringc c(attrvalue);
return core::strtol10(c.c_str()); return core::strtol10(c.c_str());
@ -160,11 +160,11 @@ public:
//! Returns the value of an attribute as float. //! Returns the value of an attribute as float.
virtual float getAttributeValueAsFloat(const char_type* name) const _IRR_OVERRIDE_ virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound) const _IRR_OVERRIDE_
{ {
const SAttribute* attr = getAttributeByName(name); const SAttribute* attr = getAttributeByName(name);
if (!attr) if (!attr)
return 0; return defaultNotFound;
core::stringc c = attr->Value.c_str(); core::stringc c = attr->Value.c_str();
return core::fast_atof(c.c_str()); return core::fast_atof(c.c_str());
@ -172,11 +172,11 @@ public:
//! Returns the value of an attribute as float. //! Returns the value of an attribute as float.
virtual float getAttributeValueAsFloat(int idx) const _IRR_OVERRIDE_ virtual float getAttributeValueAsFloat(int idx, float defaultNotFound) const _IRR_OVERRIDE_
{ {
const char_type* attrvalue = getAttributeValue(idx); const char_type* attrvalue = getAttributeValue(idx);
if (!attrvalue) if (!attrvalue)
return 0; return defaultNotFound;
core::stringc c = attrvalue; core::stringc c = attrvalue;
return core::fast_atof(c.c_str()); return core::fast_atof(c.c_str());