mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-01 15:50:27 +02:00
Drop XML implementation, related code and dependent features
This commit is contained in:
@ -5,13 +5,8 @@
|
||||
#include "CAttributes.h"
|
||||
#include "CAttributeImpl.h"
|
||||
#include "ITexture.h"
|
||||
#include "IXMLWriter.h"
|
||||
#include "IVideoDriver.h"
|
||||
|
||||
#ifndef _IRR_COMPILE_WITH_XML_
|
||||
#include "CXMLReader.h" // for noXML
|
||||
#endif
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace io
|
||||
@ -1381,278 +1376,6 @@ void CAttributes::setAttribute(s32 index, void* userPointer)
|
||||
}
|
||||
|
||||
|
||||
//! Reads attributes from a xml file.
|
||||
//! \param readCurrentElementOnly: If set to true, reading only works if current element has the name 'attributes'.
|
||||
//! IF set to false, the first appearing list attributes are read.
|
||||
bool CAttributes::read(io::IXMLReader* reader, bool readCurrentElementOnly,
|
||||
const wchar_t* nonDefaultElementName)
|
||||
{
|
||||
#ifdef _IRR_COMPILE_WITH_XML_
|
||||
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;
|
||||
#else
|
||||
noXML();
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void CAttributes::readAttributeFromXML(const io::IXMLReader* reader)
|
||||
{
|
||||
#ifdef _IRR_COMPILE_WITH_XML_
|
||||
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"vector2d")
|
||||
{
|
||||
addVector2d(name.c_str(), core::vector2df());
|
||||
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;
|
||||
|
||||
const 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")
|
||||
{
|
||||
// It's debatable if a pointer should be set or not, but it's more likely that adding it now would wreck user-applications.
|
||||
// Also it probably doesn't makes sense setting this to a value when it comes from file.
|
||||
}
|
||||
else
|
||||
if (element == L"dimension2d")
|
||||
{
|
||||
addDimension2d(name.c_str(), core::dimension2d<u32>());
|
||||
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
|
||||
}
|
||||
#else
|
||||
noXML();
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Write these attributes into a xml file
|
||||
bool CAttributes::write(io::IXMLWriter* writer, bool writeXMLHeader,
|
||||
const wchar_t* nonDefaultElementName)
|
||||
{
|
||||
#ifdef _IRR_COMPILE_WITH_XML_
|
||||
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();
|
||||
|
||||
// build arrays
|
||||
|
||||
// name
|
||||
arraynames.push_back(core::stringw(L"name"));
|
||||
arrayvalues.push_back(core::stringw(Attributes[i]->Name.c_str()) );
|
||||
|
||||
// count
|
||||
arraynames.push_back(core::stringw(L"count"));
|
||||
arrayvalues.push_back(core::stringw((s32)arrayinput.size()));
|
||||
|
||||
// array...
|
||||
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]);
|
||||
}
|
||||
|
||||
// write them
|
||||
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;
|
||||
#else
|
||||
noXML();
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // end namespace io
|
||||
} // end namespace irr
|
||||
|
||||
|
Reference in New Issue
Block a user