using irr::core::IAttributes::read()

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

using irr::core::IAttributes::read()

Post by cat.exe »

I have a question regarding the read() function of IAttributes. It seems to be only minimally documented in the api, so I'm not really sure if I'm even using it right. I'm assuming it dumps each element in the specified xml/irr file into the implicit IAttributes object, but how is it serialized exactly? By tag? By surrounding elements?

I set up a test using the following parameters, and it seems to do nothing.

XML(IRR) File:

Code: Select all

<?xml version="1.0">
<attributes name="Method One">
<method attributes="Method Two">
<attributes>
    <attributes name="Method One">
    <method attributes="Method Two">
    <test name="Method Three">
    Method Four
</attributes>
<userData>
         <attributes>
            <bool name="Collider" value="false" />
            <bool name="Collidee" value="true" />
         </attributes>
</userData>
Function readXML()

Code: Select all

io::IAttributes* readXML(IrrlichtDevice* device, io::path& filename)
{
    if (!device)
        return 0;
    io::IXMLReader* reader = device->getFileSystem()->createXMLReader(filename);
    if (!reader)
        return 0;
    io::IAttributes* attributes = device->getFileSystem()->createEmptyAttributes();
    attributes->read(reader, false, L"attributes");
    return attributes;
}
In main():

Code: Select all

/**< Read the global configuration file */
    IrrlichtDevice *device = createDevice(video::EDT_NULL);
        if (!device) return 1;
    io::IAttributes* globalAttributes = readXML(device, *(new core::stringc("Global.irr")));
    if (globalAttributes)
    {
        device->getLogger()->log(core::stringc(globalAttributes->getAttributeCount()).c_str());
        device->getLogger()->log(core::stringc(globalAttributes->existsAttribute("userData")).c_str());
    }
Notice that as I said, I wasn't sure how elements were read. Thus, as you can see, I used several different formats in the xml file to see which one registered. Everything compiles fine, but here is the terminal output:

Irrlicht Engine version 1.8.0
Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601)
0
0
...


Can someone point me to more documentation for this function or tell me what I have done wrong? Is there an easier way to read xml without having to write my own whole reader? I understand I could use IXMLReader but IAttributes::read() seems easier, if it would work.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: using irr::core::IAttributes::read()

Post by CuteAlien »

Attributes look like this:

Code: Select all

 
<attributes>
        <int name="ValInt" value="152722522" />
        <float name="ValFloat" value="1.000000" />
        <string name="ValString" value="one" />
        <string name="ValStringW" value="ONE" />
        <binary name="ValBinary" value="ffffffffffffffffffff" />
        <stringwarray name="ValStringWArray" count="3" value0="ONE" value1="TWO" value2="THREE" />
        <bool name="ValBool" value="true" />
        <enum name="ValEnum" value="one" />
        <color name="ValColor" value="01020304" />
        <colorf name="ValColorf" value="2.000000, 3.000000, 4.000000, 1.000000" />
        <vector3d name="ValVector3df" value="1.000000, 2.000000, 3.000000" />
        <vector2d name="ValVector2df" value="1.000000, 2.000000" />
        <dimension2d name="ValDimension2du" value="1, 2" />
        <position name="ValPosition2di" value="1, 2" />
        <rect name="ValRect" value="1, 2, 3, 4" />
        <matrix name="ValMatrix" value="99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002, 99.900002" />
        <quaternion name="ValQuaternion" value="1.000000, 2.000000, 3.000000, 4.000000" />
        <box3d name="ValAabbox3df" value="1.000000, 2.000000, 3.000000, 1.000000, 2.000000, 3.000000" />
        <plane name="ValPlane3df" value="1.000000, 2.000000, 3.000000, 4.000000" />
        <triangle name="ValTriangle3df" value="1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 6.000000, 7.000000, 8.000000, 9.000000" />
        <line2d name="ValLine2df" value="1.000000, 2.000000, 3.000000, 4.000000" />
        <line3d name="ValLine3df" value="1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 6.000000" />
        <texture name="ValTexture" value="" />
        <userPointer name="ValPointer" value="0xffffff" />
</attributes>
 
(this is the result of tests/serializeAttribues.cpp)

Those are the only attributes supported by Irrlicht. Attributes are only about certain defined types and used for serialization. If you want to read a general xml you don't need them - you only need the xml interfaces then.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

Re: using irr::core::IAttributes::read()

Post by cat.exe »

Thanks mate :P

At least the problem is in my xml and not in my code.

EDIT:
I tried it and it worked just fine!
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

Re: using irr::core::IAttributes::read()

Post by cat.exe »

Hey, where did you get that list of valid data types, by the way? In the htmldoc, or elsewhere?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: using irr::core::IAttributes::read()

Post by CuteAlien »

I figured them out when I wrote that test ;-) But you can also see them IAttributes.h I think.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply