#include "CAttributes.h"
#include "CAttributeImpl.h"
#include "ITexture.h"
#include "IXMLWriter.h"
#include "IVideoDriver.h"
namespace irr
{
namespace io
{
CAttributes::CAttributes(video::IVideoDriver* driver)
: Driver(driver)
{
#ifdef _DEBUG
setDebugName("CAttributes");
#endif
if (Driver)
Driver->grab();
}
CAttributes::~CAttributes()
{
clear();
if (Driver)
Driver->drop();
}
void CAttributes::clear()
{
for (u32 i=0; i<Attributes.size(); ++i)
Attributes[i]->drop();
Attributes.clear();
}
void CAttributes::setAttribute(const c8* attributeName, const c8* value)
{
for (u32 i=0; i<Attributes.size(); ++i)
if (Attributes[i]->Name == attributeName)
{
if (!value)
{
Attributes[i]->drop();
Attributes.erase(i);
}
else
Attributes[i]->setString(value);
return;
}
if (value)
{
Attributes.push_back(new CStringAttribute(attributeName, value));
}
}
core::stringc CAttributes::getAttributeAsString(const c8* attributeName)
{
core::stringc str;
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getString();
else
return str;
}
void CAttributes::getAttributeAsString(const c8* attributeName, char* target)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
{
core::stringc str = att->getString();
strcpy(target,str.c_str());
}
else
target[0] = 0;
}
core::stringc CAttributes::getAttributeAsString(s32 index)
{
core::stringc str;
if ((u32)index < Attributes.size())
return Attributes[index]->getString();
return str;
}
void CAttributes::setAttribute(const c8* attributeName, const wchar_t* value)
{
for (u32 i=0; i<Attributes.size(); ++i)
{
if (Attributes[i]->Name == attributeName)
{
if (!value)
{
Attributes[i]->drop();
Attributes.erase(i);
}
else
Attributes[i]->setString(value);
return;
}
}
if (value)
{
Attributes.push_back(new CStringAttribute(attributeName, value));
}
}
core::stringw CAttributes::getAttributeAsStringW(const c8* attributeName)
{
core::stringw str;
IAttribute* att = getAttributeP(attributeName);
if (att)
str = att->getStringW();
return str;
}
void CAttributes::getAttributeAsStringW(const c8* attributeName, wchar_t* target)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
{
core::stringw str = att->getStringW();
wcscpy(target,str.c_str());
}
else
target[0] = 0;
}
core::stringw CAttributes::getAttributeAsStringW(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getStringW();
else
return core::stringw();
}
void CAttributes::addArray(const c8* attributeName, const core::array<core::stringw>& value)
{
Attributes.push_back(new CStringWArrayAttribute(attributeName, value));
}
void CAttributes::setAttribute(const c8* attributeName, const core::array<core::stringw>& value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setArray(value);
else
{
Attributes.push_back(new CStringWArrayAttribute(attributeName, value));
}
}
core::array<core::stringw> CAttributes::getAttributeAsArray(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getArray();
else
return core::array<core::stringw>();
}
core::array<core::stringw> CAttributes::getAttributeAsArray(s32 index)
{
core::array<core::stringw> ret;
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getArray();
return ret;
}
void CAttributes::setAttribute(s32 index, const core::array<core::stringw>& value)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setArray(value);
}
s32 CAttributes::findAttribute(const c8* attributeName) const
{
for (u32 i=0; i<Attributes.size(); ++i)
if (Attributes[i]->Name == attributeName)
return i;
return -1;
}
IAttribute* CAttributes::getAttributeP(const c8* attributeName) const
{
for (u32 i=0; i<Attributes.size(); ++i)
if (Attributes[i]->Name == attributeName)
return Attributes[i];
return 0;
}
void CAttributes::setAttribute(const c8* attributeName, bool value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setBool(value);
else
{
Attributes.push_back(new CBoolAttribute(attributeName, value));
}
}
bool CAttributes::getAttributeAsBool(const c8* attributeName)
{
bool ret = false;
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getBool();
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
void CAttributes::setAttribute(const c8* attributeName, s32 value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setInt(value);
else
{
Attributes.push_back(new CIntAttribute(attributeName, value));
}
}
s32 CAttributes::getAttributeAsInt(const c8* attributeName) const
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getInt();
else
return 0;
}
void CAttributes::setAttribute(const c8* attributeName, f32 value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setFloat(value);
else
Attributes.push_back(new CFloatAttribute(attributeName, value));
}
f32 CAttributes::getAttributeAsFloat(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getFloat();
return 0.f;
}
void CAttributes::setAttribute(const c8* attributeName, video::SColor value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setColor(value);
else
Attributes.push_back(new CColorAttribute(attributeName, value));
}
video::SColor CAttributes::getAttributeAsColor(const c8* attributeName)
{
video::SColor ret(0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getColor();
return ret;
}
void CAttributes::setAttribute(const c8* attributeName, video::SColorf value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setColor(value);
else
Attributes.push_back(new CColorfAttribute(attributeName, value));
}
video::SColorf CAttributes::getAttributeAsColorf(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getColorf();
else
return video::SColorf();
}
void CAttributes::setAttribute(const c8* attributeName, core::position2di value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setPosition(value);
else
Attributes.push_back(new CPosition2DAttribute(attributeName, value));
}
core::position2di CAttributes::getAttributeAsPosition2d(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getPosition();
else
return core::position2di();
}
void CAttributes::setAttribute(const c8* attributeName, core::rect<s32> value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setRect(value);
else
Attributes.push_back(new CRectAttribute(attributeName, value));
}
core::rect<s32> CAttributes::getAttributeAsRect(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getRect();
else
return core::rect<s32>();
}
void CAttributes::setAttribute(const c8* attributeName, core::vector3df value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setVector(value);
else
Attributes.push_back(new CVector3DAttribute(attributeName, value));
}
core::vector3df CAttributes::getAttributeAsVector3d(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getVector();
else
return core::vector3df();
}
void CAttributes::setAttribute(const c8* attributeName, void* data, s32 dataSizeInBytes )
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setBinary(data, dataSizeInBytes);
else
Attributes.push_back(new CBinaryAttribute(attributeName, data, dataSizeInBytes));
}
void CAttributes::getAttributeAsBinaryData(const c8* attributeName, void* outData, s32 maxSizeInBytes)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->getBinary(outData, maxSizeInBytes);
}
void CAttributes::setAttribute(const c8* attributeName, const char* enumValue, const char* const* enumerationLiterals)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setEnum(enumValue, enumerationLiterals);
else
Attributes.push_back(new CEnumAttribute(attributeName, enumValue, enumerationLiterals));
}
const char* CAttributes::getAttributeAsEnumeration(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getEnum();
else
return 0;
}
s32 CAttributes::getAttributeAsEnumeration(const c8* attributeName, const char* const* enumerationLiteralsToUse)
{
IAttribute* att = getAttributeP(attributeName);
if (enumerationLiteralsToUse && att)
{
const char* value = att->getEnum();
if (value)
{
for (s32 i=0; enumerationLiteralsToUse[i]; ++i)
if (!strcmp(value, enumerationLiteralsToUse[i]))
return i;
}
}
return -1;
}
void CAttributes::getAttributeEnumerationLiteralsOfEnumeration(const c8* attributeName, core::array<core::stringc>& outLiterals)
{
IAttribute* att = getAttributeP(attributeName);
if (att && att->getType() == EAT_ENUM)
outLiterals = ((CEnumAttribute*)att)->EnumLiterals;
}
void CAttributes::setAttribute(const c8* attributeName, video::ITexture* value )
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setTexture(value);
else
Attributes.push_back(new CTextureAttribute(attributeName, value, Driver));
}
video::ITexture* CAttributes::getAttributeAsTexture(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getTexture();
else
return 0;
}
video::ITexture* CAttributes::getAttributeAsTexture(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getTexture();
else
return 0;
}
u32 CAttributes::getAttributeCount() const
{
return Attributes.size();
}
const c8* CAttributes::getAttributeName(s32 index)
{
if ((u32)index >= Attributes.size())
return 0;
return Attributes[index]->Name.c_str();
}
E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8* attributeName)
{
E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN;
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getType();
return ret;
}
E_ATTRIBUTE_TYPE CAttributes::getAttributeType(s32 index)
{
if ((u32)index >= Attributes.size())
return EAT_UNKNOWN;
return Attributes[index]->getType();
}
const wchar_t* CAttributes::getAttributeTypeString(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getTypeString();
else
return L"unknown";
}
const wchar_t* CAttributes::getAttributeTypeString(s32 index)
{
if ((u32)index >= Attributes.size())
return L"unknown";
return Attributes[index]->getTypeString();
}
bool CAttributes::getAttributeAsBool(s32 index)
{
bool ret = false;
if ((u32)index < Attributes.size())
ret = Attributes[index]->getBool();
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
s32 CAttributes::getAttributeAsInt(s32 index) const
{
if ((u32)index < Attributes.size())
return Attributes[index]->getInt();
else
return 0;
}
f32 CAttributes::getAttributeAsFloat(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getFloat();
else
return 0.f;
}
video::SColor CAttributes::getAttributeAsColor(s32 index)
{
video::SColor ret(0);
if ((u32)index < Attributes.size())
ret = Attributes[index]->getColor();
return ret;
}
video::SColorf CAttributes::getAttributeAsColorf(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getColorf();
return video::SColorf();
}
core::vector3df CAttributes::getAttributeAsVector3d(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getVector();
else
return core::vector3df();
}
core::position2di CAttributes::getAttributeAsPosition2d(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getPosition();
else
return core::position2di();
}
core::rect<s32> CAttributes::getAttributeAsRect(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getRect();
else
return core::rect<s32>();
}
void CAttributes::getAttributeAsBinaryData(s32 index, void* outData, s32 maxSizeInBytes)
{
if ((u32)index < Attributes.size())
Attributes[index]->getBinary(outData, maxSizeInBytes);
}
const char* CAttributes::getAttributeAsEnumeration(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getEnum();
else
return 0;
}
s32 CAttributes::getAttributeAsEnumeration(s32 index, const char* const* enumerationLiteralsToUse)
{
if ((u32)index < Attributes.size())
{
IAttribute* att = Attributes[index];
if (enumerationLiteralsToUse && att)
{
const char* value = att->getEnum();
if (value)
{
for (s32 i=0; enumerationLiteralsToUse[i]; ++i)
if (!strcmp(value, enumerationLiteralsToUse[i]))
return i;
}
}
}
return -1;
}
void CAttributes::getAttributeEnumerationLiteralsOfEnumeration(s32 index, core::array<core::stringc>& outLiterals)
{
if ((u32)index < Attributes.size() &&
Attributes[index]->getType() == EAT_ENUM)
outLiterals = ((CEnumAttribute*)Attributes[index])->EnumLiterals;
}
void CAttributes::addInt(const c8* attributeName, s32 value)
{
Attributes.push_back(new CIntAttribute(attributeName, value));
}
void CAttributes::addFloat(const c8* attributeName, f32 value)
{
Attributes.push_back(new CFloatAttribute(attributeName, value));
}
void CAttributes::addString(const c8* attributeName, const char* value)
{
Attributes.push_back(new CStringAttribute(attributeName, value));
}
void CAttributes::addString(const c8* attributeName, const wchar_t* value)
{
Attributes.push_back(new CStringAttribute(attributeName, value));
}
void CAttributes::addBool(const c8* attributeName, bool value)
{
Attributes.push_back(new CBoolAttribute(attributeName, value));
}
void CAttributes::addEnum(const c8* attributeName, const char* enumValue, const char* const* enumerationLiterals)
{
Attributes.push_back(new CEnumAttribute(attributeName, enumValue, enumerationLiterals));
}
void CAttributes::addEnum(const c8* attributeName, s32 enumValue, const char* const* enumerationLiterals)
{
addEnum(attributeName, "", enumerationLiterals);
Attributes.getLast()->setInt(enumValue);
}
void CAttributes::addColor(const c8* attributeName, video::SColor value)
{
Attributes.push_back(new CColorAttribute(attributeName, value));
}
void CAttributes::addColorf(const c8* attributeName, video::SColorf value)
{
Attributes.push_back(new CColorfAttribute(attributeName, value));
}
void CAttributes::addVector3d(const c8* attributeName, core::vector3df value)
{
Attributes.push_back(new CVector3DAttribute(attributeName, value));
}
void CAttributes::addPosition2d(const c8* attributeName, core::position2di value)
{
Attributes.push_back(new CPosition2DAttribute(attributeName, value));
}
void CAttributes::addRect(const c8* attributeName, core::rect<s32> value)
{
Attributes.push_back(new CRectAttribute(attributeName, value));
}
void CAttributes::addBinary(const c8* attributeName, void* data, s32 dataSizeInBytes)
{
Attributes.push_back(new CBinaryAttribute(attributeName, data, dataSizeInBytes));
}
void CAttributes::addTexture(const c8* attributeName, video::ITexture* texture)
{
Attributes.push_back(new CTextureAttribute(attributeName, texture, Driver));
}
bool CAttributes::existsAttribute(const c8* attributeName)
{
return getAttributeP(attributeName) != 0;
}
void CAttributes::setAttribute(s32 index, const c8* value)
{
if ((u32)index < Attributes.size())
Attributes[index]->setString(value);
}
void CAttributes::setAttribute(s32 index, const wchar_t* value)
{
if ((u32)index < Attributes.size())
Attributes[index]->setString(value);
}
void CAttributes::setAttribute(s32 index, bool value)
{
if ((u32)index < Attributes.size())
Attributes[index]->setBool(value);
}
void CAttributes::setAttribute(s32 index, s32 value)
{
if ((u32)index < Attributes.size())
Attributes[index]->setInt(value);
}
void CAttributes::setAttribute(s32 index, f32 value)
{
if ((u32)index < Attributes.size())
Attributes[index]->setFloat(value);
}
void CAttributes::setAttribute(s32 index, video::SColor color)
{
if ((u32)index < Attributes.size())
Attributes[index]->setColor(color);
}
void CAttributes::setAttribute(s32 index, video::SColorf color)
{
if ((u32)index < Attributes.size())
Attributes[index]->setColor(color);
}
void CAttributes::setAttribute(s32 index, core::vector3df v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setVector(v);
}
void CAttributes::setAttribute(s32 index, core::position2di v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setPosition(v);
}
void CAttributes::setAttribute(s32 index, core::rect<s32> v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setRect(v);
}
void CAttributes::setAttribute(s32 index, void* data, s32 dataSizeInBytes )
{
if ((u32)index < Attributes.size())
Attributes[index]->setBinary(data, dataSizeInBytes);
}
void CAttributes::setAttribute(s32 index, const char* enumValue, const char* const* enumerationLiterals)
{
if ((u32)index < Attributes.size())
Attributes[index]->setEnum(enumValue, enumerationLiterals);
}
void CAttributes::setAttribute(s32 index, video::ITexture* texture)
{
if ((u32)index < Attributes.size())
Attributes[index]->setTexture(texture);
}
void CAttributes::addMatrix(const c8* attributeName, const core::matrix4& v)
{
Attributes.push_back(new CMatrixAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, const core::matrix4& v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setMatrix(v);
else
Attributes.push_back(new CMatrixAttribute(attributeName, v));
}
core::matrix4 CAttributes::getAttributeAsMatrix(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getMatrix();
else
return core::matrix4();
}
core::matrix4 CAttributes::getAttributeAsMatrix(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getMatrix();
else
return core::matrix4();
}
void CAttributes::setAttribute(s32 index, const core::matrix4& v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setMatrix(v);
}
void CAttributes::addQuaternion(const c8* attributeName, core::quaternion v)
{
Attributes.push_back(new CQuaternionAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::quaternion v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setQuaternion(v);
else
{
Attributes.push_back(new CQuaternionAttribute(attributeName, v));
}
}
core::quaternion CAttributes::getAttributeAsQuaternion(const c8* attributeName)
{
core::quaternion ret(0,1,0, 0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getQuaternion();
return ret;
}
core::quaternion CAttributes::getAttributeAsQuaternion(s32 index)
{
core::quaternion ret(0,1,0, 0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getQuaternion();
return ret;
}
void CAttributes::setAttribute(s32 index, core::quaternion v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setQuaternion(v);
}
void CAttributes::addBox3d(const c8* attributeName, core::aabbox3df v)
{
Attributes.push_back(new CBBoxAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::aabbox3df v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setBBox(v);
else
{
Attributes.push_back(new CBBoxAttribute(attributeName, v));
}
}
core::aabbox3df CAttributes::getAttributeAsBox3d(const c8* attributeName)
{
core::aabbox3df ret(0,0,0, 0,0,0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getBBox();
return ret;
}
core::aabbox3df CAttributes::getAttributeAsBox3d(s32 index)
{
core::aabbox3df ret(0,0,0, 0,0,0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getBBox();
return ret;
}
void CAttributes::setAttribute(s32 index, core::aabbox3df v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setBBox(v);
}
void CAttributes::addPlane3d(const c8* attributeName, core::plane3df v)
{
Attributes.push_back(new CPlaneAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::plane3df v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setPlane(v);
else
{
Attributes.push_back(new CPlaneAttribute(attributeName, v));
}
}
core::plane3df CAttributes::getAttributeAsPlane3d(const c8* attributeName)
{
core::plane3df ret(0,0,0, 0,1,0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getPlane();
return ret;
}
core::plane3df CAttributes::getAttributeAsPlane3d(s32 index)
{
core::plane3df ret(0,0,0, 0,1,0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getPlane();
return ret;
}
void CAttributes::setAttribute(s32 index, core::plane3df v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setPlane(v);
}
void CAttributes::addTriangle3d(const c8* attributeName, core::triangle3df v)
{
Attributes.push_back(new CTriangleAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::triangle3df v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setTriangle(v);
else
{
Attributes.push_back(new CTriangleAttribute(attributeName, v));
}
}
core::triangle3df CAttributes::getAttributeAsTriangle3d(const c8* attributeName)
{
core::triangle3df ret;
ret.pointA = ret.pointB = ret.pointC = core::vector3df(0,0,0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getTriangle();
return ret;
}
core::triangle3df CAttributes::getAttributeAsTriangle3d(s32 index)
{
core::triangle3df ret;
ret.pointA = ret.pointB = ret.pointC = core::vector3df(0,0,0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getTriangle();
return ret;
}
void CAttributes::setAttribute(s32 index, core::triangle3df v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setTriangle(v);
}
void CAttributes::addLine2d(const c8* attributeName, core::line2df v)
{
Attributes.push_back(new CLine2dAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::line2df v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setLine2d(v);
else
{
Attributes.push_back(new CLine2dAttribute(attributeName, v));
}
}
core::line2df CAttributes::getAttributeAsLine2d(const c8* attributeName)
{
core::line2df ret(0,0, 0,0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getLine2d();
return ret;
}
core::line2df CAttributes::getAttributeAsLine2d(s32 index)
{
core::line2df ret(0,0, 0,0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getLine2d();
return ret;
}
void CAttributes::setAttribute(s32 index, core::line2df v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setLine2d(v);
}
void CAttributes::addLine3d(const c8* attributeName, core::line3df v)
{
Attributes.push_back(new CLine3dAttribute(attributeName, v));
}
void CAttributes::setAttribute(const c8* attributeName, core::line3df v)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setLine3d(v);
else
{
Attributes.push_back(new CLine3dAttribute(attributeName, v));
}
}
core::line3df CAttributes::getAttributeAsLine3d(const c8* attributeName)
{
core::line3df ret(0,0,0, 0,0,0);
IAttribute* att = getAttributeP(attributeName);
if (att)
ret = att->getLine3d();
return ret;
}
core::line3df CAttributes::getAttributeAsLine3d(s32 index)
{
core::line3df ret(0,0,0, 0,0,0);
if (index >= 0 && index < (s32)Attributes.size())
ret = Attributes[index]->getLine3d();
return ret;
}
void CAttributes::setAttribute(s32 index, core::line3df v)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setLine3d(v);
}
void CAttributes::addUserPointer(const c8* attributeName, void* userPointer)
{
Attributes.push_back(new CUserPointerAttribute(attributeName, userPointer));
}
void CAttributes::setAttribute(const c8* attributeName, void* userPointer)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setUserPointer(userPointer);
else
{
Attributes.push_back(new CUserPointerAttribute(attributeName, userPointer));
}
}
void* CAttributes::getAttributeAsUserPointer(const c8* attributeName)
{
void* value = 0;
IAttribute* att = getAttributeP(attributeName);
if (att)
value = att->getUserPointer();
return value;
}
void* CAttributes::getAttributeAsUserPointer(s32 index)
{
void* value = 0;
if (index >= 0 && index < (s32)Attributes.size())
value = Attributes[index]->getUserPointer();
return value;
}
void CAttributes::setAttribute(s32 index, void* userPointer)
{
if (index >= 0 && index < (s32)Attributes.size() )
Attributes[index]->setUserPointer(userPointer);
}
bool CAttributes::read(io::IXMLReader* reader, bool readCurrentElementOnly,
const wchar_t* nonDefaultElementName)
{
if (!reader)
return false;
clear();
core::stringw elementName = L"attributes";
if (nonDefaultElementName)
elementName = nonDefaultElementName;
if (readCurrentElementOnly)
{
if (elementName != reader->getNodeName())
return false;
}
while(reader->read())
{
switch(reader->getNodeType())
{
case io::EXN_ELEMENT:
readAttributeFromXML(reader);
break;
case io::EXN_ELEMENT_END:
if (elementName == reader->getNodeName())
return true;
break;
default:
break;
}
}
return true;
}
void CAttributes::readAttributeFromXML(io::IXMLReader* reader)
{
core::stringw element = reader->getNodeName();
core::stringc name = reader->getAttributeValue(L"name");
if (element == L"enum")
{
addEnum(name.c_str(), 0, 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"binary")
{
addBinary(name.c_str(), 0, 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"color")
{
addColor(name.c_str(), video::SColor());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"colorf")
{
addColorf(name.c_str(), video::SColorf());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"float")
{
addFloat(name.c_str(), 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"int")
{
addInt(name.c_str(), 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"bool")
{
addBool(name.c_str(), 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"string")
{
addString(name.c_str(), L"");
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"texture")
{
addTexture(name.c_str(), 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"vector3d")
{
addVector3d(name.c_str(), core::vector3df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"position")
{
addPosition2d(name.c_str(), core::position2di());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"rect")
{
addRect(name.c_str(), core::rect<s32>());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"matrix")
{
addMatrix(name.c_str(), core::matrix4());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"quaternion")
{
addQuaternion(name.c_str(), core::quaternion());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"box3d")
{
addBox3d(name.c_str(), core::aabbox3df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"plane")
{
addPlane3d(name.c_str(), core::plane3df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"triangle")
{
addTriangle3d(name.c_str(), core::triangle3df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"line2d")
{
addLine2d(name.c_str(), core::line2df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"line3d")
{
addLine3d(name.c_str(), core::line3df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"stringwarray")
{
core::array<core::stringw> tmpArray;
s32 count = reader->getAttributeValueAsInt(L"count");
s32 n=0;
const core::stringw tmpName(L"value");
for (; n<count; ++n)
{
tmpArray.push_back(reader->getAttributeValue((tmpName+core::stringw(n)).c_str()));
}
addArray(name.c_str(),tmpArray);
}
else
if (element == L"userPointer")
{
}
}
bool CAttributes::write(io::IXMLWriter* writer, bool writeXMLHeader,
const wchar_t* nonDefaultElementName)
{
if (!writer)
return false;
if (writeXMLHeader)
writer->writeXMLHeader();
core::stringw elementName = L"attributes";
if (nonDefaultElementName)
elementName = nonDefaultElementName;
writer->writeElement(elementName.c_str(), false);
writer->writeLineBreak();
s32 i=0;
for (; i<(s32)Attributes.size(); ++i)
{
if ( Attributes[i]->getType() == EAT_STRINGWARRAY )
{
core::array<core::stringw> arraynames, arrayvalues;
core::array<core::stringw> arrayinput = Attributes[i]->getArray();
arraynames.push_back(core::stringw(L"name"));
arrayvalues.push_back(core::stringw(Attributes[i]->Name.c_str()) );
arraynames.push_back(core::stringw(L"count"));
arrayvalues.push_back(core::stringw((s32)arrayinput.size()));
u32 n=0;
const core::stringw tmpName(L"value");
for (; n < arrayinput.size(); ++n)
{
arraynames.push_back((tmpName+core::stringw(n)).c_str());
arrayvalues.push_back(arrayinput[n]);
}
writer->writeElement( Attributes[i]->getTypeString(), true, arraynames, arrayvalues);
}
else
{
writer->writeElement(
Attributes[i]->getTypeString(), true,
L"name", core::stringw(Attributes[i]->Name.c_str()).c_str(),
L"value", Attributes[i]->getStringW().c_str() );
}
writer->writeLineBreak();
}
writer->writeClosingTag(elementName.c_str());
writer->writeLineBreak();
return true;
}
}
}