From 32585c5ed022d8df3fc4397ee2e9be01817812f4 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sat, 17 Aug 2019 17:52:32 +0000 Subject: [PATCH] Cleanup: Make some variables const. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5854 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IMeshBuffer.h | 2 +- include/SColor.h | 2 +- include/fast_atof.h | 4 +- include/irrArray.h | 2 +- include/irrMath.h | 6 +-- include/irrString.h | 8 ++-- include/line2d.h | 6 +-- include/quaternion.h | 2 +- include/vector2d.h | 2 +- source/Irrlicht/CAttributeImpl.h | 12 +++--- source/Irrlicht/CAttributes.cpp | 66 ++++++++++++++++---------------- source/Irrlicht/CAttributes.h | 2 +- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/include/IMeshBuffer.h b/include/IMeshBuffer.h index 84131f44..488eb029 100644 --- a/include/IMeshBuffer.h +++ b/include/IMeshBuffer.h @@ -158,7 +158,7 @@ namespace scene //! Calculate how many geometric primitives are used by this meshbuffer virtual u32 getPrimitiveCount() const { - u32 indexCount = getIndexCount(); + const u32 indexCount = getIndexCount(); switch (getPrimitiveType()) { case scene::EPT_POINTS: return indexCount; diff --git a/include/SColor.h b/include/SColor.h index f7790557..a6b81117 100644 --- a/include/SColor.h +++ b/include/SColor.h @@ -503,7 +503,7 @@ namespace video break; case ECF_R8G8B8: { - u8* p = (u8*)data; + const u8* p = (u8*)data; set(255, p[0],p[1],p[2]); } break; diff --git a/include/fast_atof.h b/include/fast_atof.h index 2e894353..b829eaec 100644 --- a/include/fast_atof.h +++ b/include/fast_atof.h @@ -324,8 +324,8 @@ inline const char* fast_atof_move(const char* in, f32& result) if ( LOCALE_DECIMAL_POINTS.findFirst(*in) >= 0 ) { const char* afterDecimal = ++in; - f32 decimal = strtof10(in, &afterDecimal); - size_t numDecimals = afterDecimal - in; + const f32 decimal = strtof10(in, &afterDecimal); + const size_t numDecimals = afterDecimal - in; if (numDecimals < IRR_ATOF_TABLE_SIZE) { value += decimal * fast_atof_table[numDecimals]; diff --git a/include/irrArray.h b/include/irrArray.h index 3e008e55..b8ffd705 100644 --- a/include/irrArray.h +++ b/include/irrArray.h @@ -76,7 +76,7 @@ public: allocated = new_size; // copy old data - s32 end = used < new_size ? used : new_size; + const s32 end = used < new_size ? used : new_size; for (s32 i=0; i allocated) reallocate(used + len); @@ -1435,7 +1435,7 @@ private: array = allocator.allocate(new_size); //new T[new_size]; allocated = new_size; - u32 amount = used < new_size ? used : new_size; + const u32 amount = used < new_size ? used : new_size; for (u32 i=0; i& destination, const char* source) { - u32 s = source ? (u32)strlen(source) : 0; + const u32 s = source ? (u32)strlen(source) : 0; return multibyteToWString(destination, source, s); } @@ -1493,7 +1493,7 @@ static size_t multibyteToWString(string& destination, const char* sourc #pragma warning(push) #pragma warning(disable: 4996) // 'mbstowcs': This function or variable may be unsafe. Consider using mbstowcs_s instead. #endif - size_t written = mbstowcs(destination.array, source, (size_t)sourceSize); + const size_t written = mbstowcs(destination.array, source, (size_t)sourceSize); #if defined(_MSC_VER) #pragma warning(pop) #endif diff --git a/include/line2d.h b/include/line2d.h index f44d14b6..ce34c419 100644 --- a/include/line2d.h +++ b/include/line2d.h @@ -329,13 +329,13 @@ class line2d template <> inline vector2df line2d::getClosestPoint(const vector2df& point, bool checkOnlySegments) const { - vector2df c = point - start; + const vector2df c = point - start; vector2df v = end - start; - f32 d = (f32)v.getLength(); + const f32 d = (f32)v.getLength(); if ( d == 0 ) // can't tell much when the line is just a single point return start; v /= d; - f32 t = v.dotProduct(c); + const f32 t = v.dotProduct(c); if ( checkOnlySegments ) { diff --git a/include/quaternion.h b/include/quaternion.h index e6cd14e2..97e2581c 100644 --- a/include/quaternion.h +++ b/include/quaternion.h @@ -692,7 +692,7 @@ inline vector3df quaternion::operator* (const vector3df& v) const // nVidia SDK implementation vector3df uv, uuv; - vector3df qvec(X, Y, Z); + const vector3df qvec(X, Y, Z); uv = qvec.crossProduct(v); uuv = qvec.crossProduct(uv); uv *= (2.0f * W); diff --git a/include/vector2d.h b/include/vector2d.h index 98075a8a..2d28ce72 100644 --- a/include/vector2d.h +++ b/include/vector2d.h @@ -315,7 +315,7 @@ public: \return An interpolated vector. This vector is not modified. */ vector2d getInterpolated(const vector2d& other, f64 d) const { - f64 inv = 1.0f - d; + const f64 inv = 1.0f - d; return vector2d((T)(other.X*inv + X*d), (T)(other.Y*inv + Y*d)); } diff --git a/source/Irrlicht/CAttributeImpl.h b/source/Irrlicht/CAttributeImpl.h index 173e2665..3796fed9 100644 --- a/source/Irrlicht/CAttributeImpl.h +++ b/source/Irrlicht/CAttributeImpl.h @@ -1275,7 +1275,7 @@ public: { u32 c; int characters; - int items = sscanf(text, "%08x%n", &c, &characters); + const int items = sscanf(text, "%08x%n", &c, &characters); if (items != 1 || characters != 8 ) { CNumbersAttribute::setString(text); @@ -1768,7 +1768,7 @@ public: virtual void getBinary(void* outdata, s32 maxLength) const _IRR_OVERRIDE_ { - s32 dataSize = maxLength; + const s32 dataSize = maxLength; c8* datac8 = (c8*)(outdata); s32 p = 0; const c8* dataString = Value.c_str(); @@ -1790,8 +1790,8 @@ public: virtual void setBinary(void* data, s32 maxLength) _IRR_OVERRIDE_ { - s32 dataSize = maxLength; - c8* datac8 = (c8*)(data); + const s32 dataSize = maxLength; + const c8* datac8 = (c8*)(data); char tmp[3]; tmp[2] = 0; Value = ""; @@ -2050,9 +2050,9 @@ public: case 8: { #ifdef _MSC_VER - unsigned __int64 tmp = _strtoui64(text, NULL, 16); + const unsigned __int64 tmp = _strtoui64(text, NULL, 16); #else - unsigned long long tmp = strtoull(text, NULL, 16); + const unsigned long long tmp = strtoull(text, NULL, 16); #endif val = (size_t)tmp; } diff --git a/source/Irrlicht/CAttributes.cpp b/source/Irrlicht/CAttributes.cpp index b080c837..7b1f06ec 100644 --- a/source/Irrlicht/CAttributes.cpp +++ b/source/Irrlicht/CAttributes.cpp @@ -78,7 +78,7 @@ void CAttributes::setAttribute(const c8* attributeName, const c8* value) //! or 0 if attribute is not set. core::stringc CAttributes::getAttributeAsString(const c8* attributeName, const core::stringc& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getString(); else @@ -90,7 +90,7 @@ core::stringc CAttributes::getAttributeAsString(const c8* attributeName, const c //! \param target: Buffer where the string is copied to. void CAttributes::getAttributeAsString(const c8* attributeName, char* target) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) { core::stringc str = att->getString(); @@ -146,7 +146,7 @@ void CAttributes::setAttribute(const c8* attributeName, const wchar_t* value) //! or 0 if attribute is not set. core::stringw CAttributes::getAttributeAsStringW(const c8* attributeName, const core::stringw& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getStringW(); else @@ -158,7 +158,7 @@ core::stringw CAttributes::getAttributeAsStringW(const c8* attributeName, const //! \param target: Buffer where the string is copied to. void CAttributes::getAttributeAsStringW(const c8* attributeName, wchar_t* target) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) { core::stringw str = att->getStringW(); @@ -201,7 +201,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::array CAttributes::getAttributeAsArray(const c8* attributeName, const core::array& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getArray(); else @@ -268,7 +268,7 @@ void CAttributes::setAttribute(const c8* attributeName, bool value) //! or 0 if attribute is not set. bool CAttributes::getAttributeAsBool(const c8* attributeName, bool defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getBool(); else @@ -293,7 +293,7 @@ void CAttributes::setAttribute(const c8* attributeName, s32 value) //! or 0 if attribute is not set. s32 CAttributes::getAttributeAsInt(const c8* attributeName, irr::s32 defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getInt(); else @@ -316,7 +316,7 @@ void CAttributes::setAttribute(const c8* attributeName, f32 value) //! or 0 if attribute is not set. f32 CAttributes::getAttributeAsFloat(const c8* attributeName, irr::f32 defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getFloat(); @@ -338,7 +338,7 @@ void CAttributes::setAttribute(const c8* attributeName, video::SColor value) //! \return Returns value of the attribute previously set by setAttribute() video::SColor CAttributes::getAttributeAsColor(const c8* attributeName, const video::SColor& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getColor(); else @@ -360,7 +360,7 @@ void CAttributes::setAttribute(const c8* attributeName, video::SColorf value) //! \return Returns value of the attribute previously set by setAttribute() video::SColorf CAttributes::getAttributeAsColorf(const c8* attributeName, const video::SColorf& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getColorf(); else @@ -382,7 +382,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::position2di& //! \return Returns value of the attribute previously set by setAttribute() core::position2di CAttributes::getAttributeAsPosition2d(const c8* attributeName, const core::position2di& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getPosition(); else @@ -404,7 +404,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::rect& v //! \return Returns value of the attribute previously set by setAttribute() core::rect CAttributes::getAttributeAsRect(const c8* attributeName, const core::rect& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getRect(); else @@ -426,7 +426,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::dimension2d< //! \return Returns value of the attribute previously set by setAttribute() core::dimension2d CAttributes::getAttributeAsDimension2d(const c8* attributeName, const core::dimension2d& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getDimension2d(); else @@ -458,7 +458,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::vector2df& v //! \return Returns value of the attribute previously set by setAttribute() core::vector3df CAttributes::getAttributeAsVector3d(const c8* attributeName, const core::vector3df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getVector(); else @@ -468,7 +468,7 @@ core::vector3df CAttributes::getAttributeAsVector3d(const c8* attributeName, con //! Gets an attribute as vector core::vector2df CAttributes::getAttributeAsVector2d(const c8* attributeName, const core::vector2df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getVector2d(); else @@ -489,7 +489,7 @@ void CAttributes::setAttribute(const c8* attributeName, void* data, s32 dataSize //! \param attributeName: Name of the attribute to get. void CAttributes::getAttributeAsBinaryData(const c8* attributeName, void* outData, s32 maxSizeInBytes) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) att->getBinary(outData, maxSizeInBytes); } @@ -509,7 +509,7 @@ void CAttributes::setAttribute(const c8* attributeName, const char* enumValue, c //! \return Returns value of the attribute previously set by setAttribute() const char* CAttributes::getAttributeAsEnumeration(const c8* attributeName, const c8* defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getEnum(); else @@ -519,7 +519,7 @@ const char* CAttributes::getAttributeAsEnumeration(const c8* attributeName, cons //! Gets an attribute as enumeration s32 CAttributes::getAttributeAsEnumeration(const c8* attributeName, const char* const* enumerationLiteralsToUse, s32 defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (enumerationLiteralsToUse && att) { @@ -539,7 +539,7 @@ s32 CAttributes::getAttributeAsEnumeration(const c8* attributeName, const char* //! \param attributeName: Name of the attribute to get. void CAttributes::getAttributeEnumerationLiteralsOfEnumeration(const c8* attributeName, core::array& outLiterals) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att && att->getType() == EAT_ENUM) outLiterals = ((CEnumAttribute*)att)->EnumLiterals; @@ -560,7 +560,7 @@ void CAttributes::setAttribute(const c8* attributeName, video::ITexture* value, //! \param attributeName: Name of the attribute to get. video::ITexture* CAttributes::getAttributeAsTexture(const c8* attributeName, video::ITexture* defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getTexture(); else @@ -599,7 +599,7 @@ E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8* attributeName) const { E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN; - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) ret = att->getType(); @@ -619,7 +619,7 @@ E_ATTRIBUTE_TYPE CAttributes::getAttributeType(s32 index) const //! Returns the type of an attribute const wchar_t* CAttributes::getAttributeTypeString(const c8* attributeName, const wchar_t* defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getTypeString(); else @@ -766,7 +766,7 @@ s32 CAttributes::getAttributeAsEnumeration(s32 index, const char* const* enumera { if ((u32)index < Attributes.size()) { - IAttribute* att = Attributes[index]; + const IAttribute* att = Attributes[index]; if (enumerationLiteralsToUse && att) { @@ -1027,7 +1027,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::matrix4& v) //! Gets an attribute as a matrix4 core::matrix4 CAttributes::getAttributeAsMatrix(const c8* attributeName, const core::matrix4& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getMatrix(); else @@ -1074,7 +1074,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::quaternion& //! Gets an attribute as a quaternion core::quaternion CAttributes::getAttributeAsQuaternion(const c8* attributeName, const core::quaternion& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getQuaternion(); else @@ -1120,7 +1120,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::aabbox3df& v //! Gets an attribute as a axis aligned bounding box core::aabbox3df CAttributes::getAttributeAsBox3d(const c8* attributeName, const core::aabbox3df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getBBox(); else @@ -1166,7 +1166,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::plane3df& v) //! Gets an attribute as a 3d plane core::plane3df CAttributes::getAttributeAsPlane3d(const c8* attributeName, const core::plane3df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getPlane(); else @@ -1212,7 +1212,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::triangle3df& //! Gets an attribute as a 3d triangle core::triangle3df CAttributes::getAttributeAsTriangle3d(const c8* attributeName, const core::triangle3df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getTriangle(); else @@ -1259,7 +1259,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::line2df& v) //! Gets an attribute as a 2d line core::line2df CAttributes::getAttributeAsLine2d(const c8* attributeName, const core::line2df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getLine2d(); else @@ -1305,7 +1305,7 @@ void CAttributes::setAttribute(const c8* attributeName, const core::line3df& v) //! Gets an attribute as a 3d line core::line3df CAttributes::getAttributeAsLine3d(const c8* attributeName, const core::line3df& defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getLine3d(); else @@ -1354,7 +1354,7 @@ void CAttributes::setAttribute(const c8* attributeName, void* userPointer) //! \param attributeName: Name of the attribute to get. void* CAttributes::getAttributeAsUserPointer(const c8* attributeName, void* defaultNotFound) const { - IAttribute* att = getAttributeP(attributeName); + const IAttribute* att = getAttributeP(attributeName); if (att) return att->getUserPointer(); else @@ -1427,7 +1427,7 @@ bool CAttributes::read(io::IXMLReader* reader, bool readCurrentElementOnly, } -void CAttributes::readAttributeFromXML(io::IXMLReader* reader) +void CAttributes::readAttributeFromXML(const io::IXMLReader* reader) { #ifdef _IRR_COMPILE_WITH_XML_ core::stringw element = reader->getNodeName(); @@ -1557,7 +1557,7 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader) { core::array tmpArray; - s32 count = reader->getAttributeValueAsInt(L"count"); + const s32 count = reader->getAttributeValueAsInt(L"count"); s32 n=0; const core::stringw tmpName(L"value"); for (; n Attributes;