Commit ed5710bf authored by hybrid's avatar hybrid

Made some string constructors explicit to avoid nasty misinterpretations. Just...

Made some string constructors explicit to avoid nasty misinterpretations. Just add core::stringc or core::stringw around the numbers the compiler doesn't want to convert automatically anymore.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1534 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 4750bbc3
......@@ -41,7 +41,6 @@ public:
}
//! Constructor
string(const string<T>& other)
: array(0), allocated(0), used(0)
......@@ -50,9 +49,8 @@ public:
}
//! Constructs a string from a float
string(const double number)
explicit string(const double number)
: array(0), allocated(0), used(0)
{
c8 tmpbuf[255];
......@@ -61,9 +59,8 @@ public:
}
//! Constructs a string from an int
string(int number)
explicit string(int number)
: array(0), allocated(0), used(0)
{
// store if negative and make positive
......@@ -111,9 +108,8 @@ public:
}
//! Constructs a string from an unsigned int
string(unsigned int number)
explicit string(unsigned int number)
: array(0), allocated(0), used(0)
{
// temporary buffer for 16 numbers
......@@ -144,7 +140,6 @@ public:
}
//! Constructor for copying a string from a pointer with a given length
template <class B>
string(const B* const c, u32 length)
......@@ -167,7 +162,6 @@ public:
}
//! Constructor for unicode and ascii strings
template <class B>
string(const B* const c)
......@@ -177,7 +171,6 @@ public:
}
//! destructor
~string()
{
......@@ -185,7 +178,6 @@ public:
}
//! Assignment operator
string<T>& operator=(const string<T>& other)
{
......@@ -204,7 +196,6 @@ public:
}
//! Assignment operator for strings, ascii and unicode
template <class B>
string<T>& operator=(const B* const c)
......@@ -247,7 +238,8 @@ public:
return *this;
}
//! Add operator for other strings
//! Append operator for other strings
string<T> operator+(const string<T>& other) const
{
string<T> str(*this);
......@@ -256,7 +248,8 @@ public:
return str;
}
//! Add operator for strings, ascii and unicode
//! Append operator for strings, ascii and unicode
template <class B>
string<T> operator+(const B* const c) const
{
......@@ -283,7 +276,7 @@ public:
}
//! Comparison operator
//! Equality operator
bool operator ==(const T* const str) const
{
if (!str)
......@@ -298,8 +291,7 @@ public:
}
//! Comparison operator
//! Equality operator
bool operator ==(const string<T>& other) const
{
for(u32 i=0; array[i] && other.array[i]; ++i)
......@@ -310,7 +302,7 @@ public:
}
//! Is smaller operator
//! Is smaller comparator
bool operator <(const string<T>& other) const
{
for(u32 i=0; array[i] && other.array[i]; ++i)
......@@ -328,41 +320,36 @@ public:
}
//! Equals not operator
//! Inequality operator
bool operator !=(const T* const str) const
{
return !(*this == str);
}
//! Equals not operator
//! Inequality operator
bool operator !=(const string<T>& other) const
{
return !(*this == other);
}
//! Returns length of string
/** \return Returns length of the string in characters. */
/** \return Length of the string in characters. */
u32 size() const
{
return used-1;
}
//! Returns character string
/** \return Returns pointer to C-style zero terminated string. */
/** \return pointer to C-style zero terminated string. */
const T* c_str() const
{
return array;
}
//! Makes the string lower case.
void make_lower()
{
......@@ -371,7 +358,6 @@ public:
}
//! Makes the string upper case.
void make_upper()
{
......@@ -387,10 +373,9 @@ public:
}
//! Compares the string ignoring case.
//! Compares the strings ignoring case.
/** \param other: Other string to compare.
\return Returns true if the string are equal ignoring case. */
\return True if the strings are equal ignoring case. */
bool equals_ignore_case(const string<T>& other) const
{
for(u32 i=0; array[i] && other[i]; ++i)
......@@ -400,9 +385,10 @@ public:
return used == other.used;
}
//! Compares the string ignoring case.
//! Compares the strings ignoring case.
/** \param other: Other string to compare.
\return Returns true if the string is smaller ignoring case. */
\return True if this string is smaller ignoring case. */
bool lower_ignore_case(const string<T>& other) const
{
for(u32 i=0; array[i] && other.array[i]; ++i)
......@@ -416,8 +402,10 @@ public:
}
//! compares the first n characters of the strings
/** \param other Other string to compare.
\param n Number of characters to compare
\return True if the n first characters of this string are smaller. */
bool equalsn(const string<T>& other, u32 n) const
{
u32 i;
......@@ -432,6 +420,9 @@ public:
//! compares the first n characters of the strings
/** \param str Other string to compare.
\param n Number of characters to compare
\return True if the n first characters of this string are smaller. */
bool equalsn(const T* const str, u32 n) const
{
if (!str)
......@@ -460,6 +451,7 @@ public:
array[used-1] = 0;
}
//! Appends a char string to this string
/** \param other: Char string to append. */
void append(const T* const other)
......@@ -734,6 +726,8 @@ public:
}
//! Appends a character to this string
/** \param character: Character to append. */
string<T>& operator += (T c)
{
append(c);
......@@ -741,6 +735,8 @@ public:
}
//! Appends a char string to this string
/** \param other: Char string to append. */
string<T>& operator += (const T* const c)
{
append(c);
......@@ -748,6 +744,8 @@ public:
}
//! Appends a string to this string
/** \param other: String to append. */
string<T>& operator += (const string<T>& other)
{
append(other);
......@@ -805,6 +803,7 @@ public:
array[i] = replaceWith;
}
//! trims the string.
/** Removes whitespace from begin and end of the string. */
string<T>& trim()
......@@ -823,9 +822,10 @@ public:
}
//! Erases a character from the string. May be slow, because all elements
//! following after the erased element have to be copied.
//! \param index: Index of element to be erased.
//! Erases a character from the string.
/** May be slow, because all elements
following after the erased element have to be copied.
\param index: Index of element to be erased. */
void erase(u32 index)
{
_IRR_DEBUG_BREAK_IF(index>=used) // access violation
......
......@@ -1477,7 +1477,7 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader)
const core::stringw tmpName(L"value");
for (; n<count; ++n)
{
tmpArray.push_back(reader->getAttributeValue((tmpName+n).c_str()));
tmpArray.push_back(reader->getAttributeValue((tmpName+core::stringw(n)).c_str()));
}
addArray(name.c_str(),tmpArray);
}
......@@ -1523,7 +1523,7 @@ bool CAttributes::write(io::IXMLWriter* writer, bool writeXMLHeader,
const core::stringw tmpName(L"value");
for (; n < arrayinput.size(); ++n)
{
arraynames.push_back((tmpName+n).c_str());
arraynames.push_back((tmpName+core::stringw(n)).c_str());
arrayvalues.push_back(arrayinput[n]);
}
......
......@@ -307,7 +307,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"source", false, L"id", L"mesh-Pos");
Writer->writeLineBreak();
core::stringw vertexCountStr = (totalVertexCount*3);
core::stringw vertexCountStr(totalVertexCount*3);
Writer->writeElement(L"float_array", false, L"id", L"mesh-Pos-array",
L"count", vertexCountStr.c_str());
Writer->writeLineBreak();
......@@ -387,7 +387,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"technique_common", false);
Writer->writeLineBreak();
vertexCountStr = totalVertexCount;
vertexCountStr = core::stringw(totalVertexCount);
Writer->writeElement(L"accessor", false, L"source", L"#mesh-Pos-array",
L"count", vertexCountStr.c_str(), L"stride", L"3");
......@@ -414,7 +414,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"source", false, L"id", L"mesh-TexCoord0");
Writer->writeLineBreak();
vertexCountStr = (totalVertexCount*2);
vertexCountStr = core::stringw(totalVertexCount*2);
Writer->writeElement(L"float_array", false, L"id", L"mesh-TexCoord0-array",
L"count", vertexCountStr.c_str());
Writer->writeLineBreak();
......@@ -488,7 +488,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"technique_common", false);
Writer->writeLineBreak();
vertexCountStr = totalVertexCount;
vertexCountStr = core::stringw(totalVertexCount);
Writer->writeElement(L"accessor", false, L"source", L"#mesh-TexCoord0-array",
L"count", vertexCountStr.c_str(), L"stride", L"2");
......@@ -513,7 +513,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"source", false, L"id", L"mesh-Normal");
Writer->writeLineBreak();
vertexCountStr = (totalVertexCount*3);
vertexCountStr = core::stringw(totalVertexCount*3);
Writer->writeElement(L"float_array", false, L"id", L"mesh-Normal-array",
L"count", vertexCountStr.c_str());
Writer->writeLineBreak();
......@@ -593,7 +593,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"technique_common", false);
Writer->writeLineBreak();
vertexCountStr = totalVertexCount;
vertexCountStr = core::stringw(totalVertexCount);
Writer->writeElement(L"accessor", false, L"source", L"#mesh-Normal-array",
L"count", vertexCountStr.c_str(), L"stride", L"3");
......@@ -622,7 +622,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"source", false, L"id", L"mesh-TexCoord1");
Writer->writeLineBreak();
vertexCountStr = (totalTCoords2Count*2);
vertexCountStr = core::stringw(totalTCoords2Count*2);
Writer->writeElement(L"float_array", false, L"id", L"mesh-TexCoord1-array",
L"count", vertexCountStr.c_str());
Writer->writeLineBreak();
......@@ -671,7 +671,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"technique_common", false);
Writer->writeLineBreak();
vertexCountStr = totalTCoords2Count;
vertexCountStr = core::stringw(totalTCoords2Count);
Writer->writeElement(L"accessor", false, L"source", L"#mesh-TexCoord1-array",
L"count", vertexCountStr.c_str(), L"stride", L"2");
......@@ -714,7 +714,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
const u32 polyCount = buffer->getIndexCount() / 3;
core::stringw strPolyCount = polyCount;
core::stringw strPolyCount(polyCount);
core::stringw strMat = "#mat";
strMat += i;
......
......@@ -1423,7 +1423,7 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
core::stringc prefix="Texture";
u32 i;
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addTexture((prefix+(i+1)).c_str(), material.getTexture(i));
attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i));
attr->addBool("Wireframe", material.Wireframe);
attr->addBool("GouraudShading", material.GouraudShading);
......@@ -1437,16 +1437,16 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
prefix = "BilinearFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addBool((prefix+(i+1)).c_str(), material.TextureLayer[i].BilinearFilter);
attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].BilinearFilter);
prefix = "TrilinearFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addBool((prefix+(i+1)).c_str(), material.TextureLayer[i].TrilinearFilter);
attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TrilinearFilter);
prefix = "AnisotropicFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addBool((prefix+(i+1)).c_str(), material.TextureLayer[i].AnisotropicFilter);
attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].AnisotropicFilter);
prefix="TextureWrap";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addEnum((prefix+(i+1)).c_str(), material.TextureLayer[i].TextureWrap, aTextureClampNames);
attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrap, aTextureClampNames);
return attr;
}
......@@ -1479,7 +1479,7 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater
core::stringc prefix="Texture";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.setTexture(i, attr->getAttributeAsTexture((prefix+(i+1)).c_str()));
outMaterial.setTexture(i, attr->getAttributeAsTexture((prefix+core::stringc(i+1)).c_str()));
outMaterial.Wireframe = attr->getAttributeAsBool("Wireframe");
outMaterial.GouraudShading = attr->getAttributeAsBool("GouraudShading");
......@@ -1495,25 +1495,25 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater
outMaterial.setFlag(EMF_BILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].BilinearFilter = attr->getAttributeAsBool((prefix+(i+1)).c_str());
outMaterial.TextureLayer[i].BilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str());
prefix = "TrilinearFilter";
if (attr->existsAttribute(prefix.c_str())) // legacy
outMaterial.setFlag(EMF_TRILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].TrilinearFilter = attr->getAttributeAsBool((prefix+(i+1)).c_str());
outMaterial.TextureLayer[i].TrilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str());
prefix = "AnisotropicFilter";
if (attr->existsAttribute(prefix.c_str())) // legacy
outMaterial.setFlag(EMF_ANISOTROPIC_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].AnisotropicFilter = attr->getAttributeAsBool((prefix+(i+1)).c_str());
outMaterial.TextureLayer[i].AnisotropicFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str());
prefix = "TextureWrap";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].TextureWrap = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+(i+1)).c_str(), aTextureClampNames);
outMaterial.TextureLayer[i].TextureWrap = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+core::stringc(i+1)).c_str(), aTextureClampNames);
}
......
......@@ -149,11 +149,11 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s3
void CSTLMeshWriter::getVectorAsStringLine(const core::vector3df& v, core::stringc& s) const
{
s = v.X;
s = core::stringc(v.X);
s += " ";
s += v.Y;
s += core::stringc(v.Y);
s += " ";
s += v.Z;
s += core::stringc(v.Z);
s += "\n";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment