www.pudn.com > RCApp-src.zip > RCXML.cpp
/*
RedEye Project (http://members.ozemail.com.au/~ndmcevoy/)
Copyright (C) 2003 Nick McEvoy
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-----------------------------------------------------------------
Commented for use with Doxygen (http://www.doxygen.org)
-----------------------------------------------------------------
*/
/*! \file RCXML.cpp
* \brief XML reader interface.
*
* This file contains an XML reader interface.
*/
// RedEye includes
#include "RCXML.h"
bool
GetValue(const char* Val, const bool& Default)
{
if (Val)
{
if (strcmp(Val, "true")==0)
return true;
else if (strcmp(Val, "false")==0)
return false;
}
return Default;
}
int
GetValue(const char* Val, const int& Default)
{
if (Val)
return atoi(Val);
else
return Default;
}
float
GetValue(const char* Val, const float& Default)
{
if (Val)
return (float)atof(Val);
else
return Default;
}
const char*
reGetXMLAttribute(const TiXmlNode* Node, const char* AttribName, const char* Default)
{
if (Node)
{
TiXmlElement* Element = Node->ToElement();
if (Element)
{
const char* Val = Element->Attribute(AttribName);
if (Val)
{
return Val;
}
}
}
return Default;
}
bool
reGetXMLAttribute(const TiXmlNode* Node, const char* AttribName, const bool& Default)
{
if (Node)
{
TiXmlElement* Element = Node->ToElement();
if (Element)
{
return GetValue(Element->Attribute(AttribName), Default);
}
}
return Default;
}
int
reGetXMLAttribute(const TiXmlNode* Node, const char* AttribName, const int& Default)
{
if (Node)
{
TiXmlElement* Element = Node->ToElement();
if (Element)
{
return GetValue(Element->Attribute(AttribName), Default);
}
}
return Default;
}
float
reGetXMLAttribute(const TiXmlNode* Node, const char* AttribName, const float& Default)
{
if (Node)
{
TiXmlElement* Element = Node->ToElement();
if (Element)
{
return GetValue(Element->Attribute(AttribName), Default);
}
}
return Default;
}
void
reGetXMLChildAttribVec2(const TiXmlNode* Node, const char* ChildName, sgVec2 Result)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
TiXmlElement* Element = Child->ToElement();
if (Element)
{
int i = 0;
TiXmlAttribute* Attribute = Element->FirstAttribute();
while (Attribute && i < 2)
{
Result[i] = GetValue(Attribute->Value(), Result[i]);
Attribute = Attribute->Next();
i++;
}
}
}
}
}
void
reGetXMLChildAttribVec3(const TiXmlNode* Node, const char* ChildName, sgVec3 Result)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
TiXmlElement* Element = Child->ToElement();
if (Element)
{
int i = 0;
TiXmlAttribute* Attribute = Element->FirstAttribute();
while (Attribute && i < 3)
{
Result[i] = GetValue(Attribute->Value(), Result[i]);
Attribute = Attribute->Next();
i++;
}
}
}
}
}
void
reGetXMLChildAttribVec4(const TiXmlNode* Node, const char* ChildName, sgVec4 Result)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
TiXmlElement* Element = Child->ToElement();
if (Element)
{
int i = 0;
TiXmlAttribute* Attribute = Element->FirstAttribute();
while (Attribute && i < 4)
{
Result[i] = GetValue(Attribute->Value(), Result[i]);
Attribute = Attribute->Next();
i++;
}
}
}
}
}
void
reGetXMLChildAttribCoord(const TiXmlNode* Node, const char* ChildName, sgCoord* Result)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
TiXmlElement* Element = Child->ToElement();
if (Element)
{
int i = 0;
TiXmlAttribute* Attribute = Element->FirstAttribute();
while (Attribute && i < 3)
{
Result->xyz[i] = GetValue(Attribute->Value(), Result->xyz[i]);
Attribute = Attribute->Next();
i++;
}
i = 0;
while (Attribute && i < 3)
{
Result->hpr[i] = GetValue(Attribute->Value(), Result->hpr[i]);
Attribute = Attribute->Next();
i++;
}
}
}
}
}
const char*
reGetXMLChildValue(const TiXmlNode* Node, const char* ChildName, const char* Default)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
Child = Child->FirstChild();
if (Child)
{
TiXmlText* Text = Child->ToText();
if (Text)
{
const char* Val = Text->Value();
if (Val)
{
return Val;
}
}
}
}
}
return Default;
}
bool
reGetXMLChildValue(const TiXmlNode* Node, const char* ChildName, const bool& Default)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
Child = Child->FirstChild();
if (Child)
{
TiXmlText* Text = Child->ToText();
if (Text)
{
return GetValue(Text->Value(), Default);
}
}
}
}
return Default;
}
int
reGetXMLChildValue(const TiXmlNode* Node, const char* ChildName, const int& Default)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
Child = Child->FirstChild();
if (Child)
{
TiXmlText* Text = Child->ToText();
if (Text)
{
return GetValue(Text->Value(), Default);
}
}
}
}
return Default;
}
float
reGetXMLChildValue(const TiXmlNode* Node, const char* ChildName, const float& Default)
{
if (Node)
{
TiXmlNode* Child = Node->FirstChild(ChildName);
if (Child)
{
Child = Child->FirstChild();
if (Child)
{
TiXmlText* Text = Child->ToText();
if (Text)
{
return GetValue(Text->Value(), Default);
}
}
}
}
return Default;
}