[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src plt_xml.cxx,1.8,1.9 worldobj_data_fac
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src plt_xml.cxx,1.8,1.9 worldobj_data_factory.cxx,1.26,1.27 xml_helper.cxx,1.18,1.19 xml_helper.hxx,1.12,1.13 xml_plf.cxx,1.26,1.27 |
Date: |
28 Sep 2002 19:31:08 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv23571
Modified Files:
plt_xml.cxx worldobj_data_factory.cxx xml_helper.cxx
xml_helper.hxx xml_plf.cxx
Log Message:
made XMLhelper::get_prop more versatile (may have introduced bugs)
Index: plt_xml.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/plt_xml.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- plt_xml.cxx 28 Sep 2002 11:52:22 -0000 1.8
+++ plt_xml.cxx 28 Sep 2002 19:31:06 -0000 1.9
@@ -98,35 +98,33 @@
PLTXML::parse_description(xmlNodePtr cur)
{
char* desc = (char*)xmlNodeListGetString(doc, cur->children, 1);
- char* lang = XMLhelper::get_prop(cur, "lang");
-
+ std::string lang;
+
if (desc) {
- if (lang)
+ if (XMLhelper::get_prop(cur, "lang", lang))
description[lang] = desc;
else
description[default_language] = desc;
}
if (desc) xmlFree(desc);
- if (lang) xmlFree(lang);
}
void
PLTXML::parse_world_name (xmlNodePtr cur)
{
char* name = (char*)xmlNodeListGetString(doc, cur->children, 1);
- char* lang = XMLhelper::get_prop(cur, "lang");
+ std::string lang;
if (name)
{
- if (lang)
+ if (XMLhelper::get_prop(cur, "lang", lang))
world_name[lang] = name;
else
world_name[default_language] = name;
}
if (name) xmlFree(name);
- if (lang) xmlFree(lang);
}
void
Index: worldobj_data_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobj_data_factory.cxx,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- worldobj_data_factory.cxx 28 Sep 2002 11:52:22 -0000 1.26
+++ worldobj_data_factory.cxx 28 Sep 2002 19:31:06 -0000 1.27
@@ -129,10 +129,10 @@
}
else
{
- char* type = XMLhelper::get_prop(cur, "type");
- if (type)
- {
- return create (type, doc, cur);
+ std::string type;
+ if (XMLhelper::get_prop(cur, "type", type))
+ {
+ return create (type, doc, cur);
}
else
{
Index: xml_helper.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_helper.cxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- xml_helper.cxx 28 Sep 2002 11:52:22 -0000 1.18
+++ xml_helper.cxx 28 Sep 2002 19:31:06 -0000 1.19
@@ -45,10 +45,55 @@
return ! strcmp(reinterpret_cast<const char*>(comp), orig);
}
-char*
-XMLhelper::get_prop (xmlNodePtr cur, const char* name)
+bool
+XMLhelper::get_prop (xmlNodePtr cur, const char* name, std::string& value)
{
- return reinterpret_cast<char*>(xmlGetProp(cur, reinterpret_cast<const
xmlChar*>(name)));
+ char* retval = reinterpret_cast<char*>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>(name)));
+
+ if (!retval)
+ return false;
+
+ value = retval;
+ xmlFree(retval);
+ return true;
+}
+
+bool
+XMLhelper::get_prop (xmlNodePtr cur, const char* name, float& value)
+{
+ char* retval = reinterpret_cast<char*>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>(name)));
+
+ if (!retval)
+ return false;
+
+ value = strtod(retval, reinterpret_cast<char**>(NULL));
+ xmlFree(retval);
+ return true;
+}
+
+bool
+XMLhelper::get_prop (xmlNodePtr cur, const char* name, int& value)
+{
+ char* retval = reinterpret_cast<char*>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>(name)));
+ if (!retval)
+ return false;
+
+ value = strtol(retval, reinterpret_cast<char**>(NULL), 10);
+ xmlFree(retval);
+ return true;
+}
+
+bool
+XMLhelper::get_prop (xmlNodePtr cur, const char* name, bool& value)
+{
+ char* retval = reinterpret_cast<char*>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>(name)));
+
+ if (!retval)
+ return false;
+
+ value = strtol(retval, reinterpret_cast<char**>(NULL), 10);
+ xmlFree(retval);
+ return true;
}
std::string
@@ -190,16 +235,15 @@
continue;
}
- char* type = get_prop(cur, "type");
-
- if (type)
+ std::string type;
+ if (get_prop(cur, "type", type))
{
- if (strcmp(type, "file") == 0)
+ if (type == "file")
{
desc.type = ResDescriptor::RD_FILE;
xmlNodePtr ccur = cur->children;
desc.type = ResDescriptor::RD_RESOURCE;
- while (ccur != NULL)
+ while (ccur)
{
if (xmlIsBlankNode(cur))
{
@@ -236,11 +280,11 @@
ccur = ccur->next;
}
}
- else if (strcmp(type, "datafile") == 0)
+ else if (type == "datafile")
{
xmlNodePtr ccur = cur->children;
desc.type = ResDescriptor::RD_RESOURCE;
- while (ccur != NULL)
+ while (ccur)
{
if (xmlIsBlankNode(ccur))
{
@@ -293,7 +337,6 @@
{
std::cout << "XMLhelper: Unhandled resource type: " << type <<
std::endl;
}
- xmlFree(type);
}
cur = cur->next;
}
Index: xml_helper.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_helper.hxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- xml_helper.hxx 28 Sep 2002 11:52:22 -0000 1.12
+++ xml_helper.hxx 28 Sep 2002 19:31:06 -0000 1.13
@@ -71,9 +71,30 @@
@return true if both strings are equal */
static bool equal_str (const xmlChar* comp, const char* orig);
- /** @return the value of the attribute with the name \a name, caller
- must free the returned value via xmlFree() */
- static char* get_prop (xmlNodePtr cur, const char* name);
+ /** get the propertie of the given name
+ @param name the name of the property
+ @param value gets the value if the property exists or remains unchanged
+ @return indicates whether the property existed */
+ static bool get_prop (xmlNodePtr cur, const char* name, std::string& value);
+
+ /** get the propertie of the given name
+ @param name the name of the property
+ @param value gets the value if the property exists or remains unchanged
+ @return indicates whether the property existed */
+ static bool get_prop (xmlNodePtr cur, const char* name, float& value);
+
+ /** get the propertie of the given name
+ @param name the name of the property
+ @param value gets the value if the property exists or remains unchanged
+ @return indicates whether the property existed */
+ static bool get_prop (xmlNodePtr cur, const char* name, int& value);
+
+ /** get the propertie of the given name
+ @param name the name of the property
+ @param value gets the value if the property exists or remains unchanged
+ @return indicates whether the property existed */
+ static bool get_prop (xmlNodePtr cur, const char* name, bool& value);
+
/// A set of function to parse an xml file
//@{
Index: xml_plf.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_plf.cxx,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- xml_plf.cxx 28 Sep 2002 11:52:22 -0000 1.26
+++ xml_plf.cxx 28 Sep 2002 19:31:06 -0000 1.27
@@ -262,22 +262,18 @@
{
// The allocated objects are delete'd in the destructor
//FIXME: Repair me backgrounds.push_back(BackgroundData::create (doc, cur));
- char* type_cstr = XMLhelper::get_prop(cur, "type");
- if (type_cstr)
+ std::string type;
+ if (XMLhelper::get_prop(cur, "type", type))
{
- std::string type (type_cstr);
-
- worldobjs_data.push_back(WorldObjDataFactory::instance ()
+ worldobjs_data.push_back(WorldObjDataFactory::instance()
->create (type + "-background", doc, cur));
}
else
{
- worldobjs_data.push_back(WorldObjDataFactory::instance ()
+ worldobjs_data.push_back(WorldObjDataFactory::instance()
->create ("surface-background", doc, cur));
}
-
- xmlFree(type_cstr);
}
void
@@ -296,13 +292,7 @@
ActionData button;
button.name = action_from_string(reinterpret_cast<const
char*>(cur->name));
- char* count = XMLhelper::get_prop(cur, "count");
- if (count)
- {
- from_string(count, button.number_of);
- xmlFree(count);
- }
- else
+ if (!XMLhelper::get_prop(cur, "count", button.number_of))
{
//std::cout << "XMLPLF::parse_actions (): No 'count' given, fallback
to the old format" << std::endl;
char* number = reinterpret_cast<char*>(xmlNodeListGetString(doc,
cur->children, 1));
@@ -336,10 +326,10 @@
if (XMLhelper::equal_str(cur->name, "levelname"))
{
char* name = reinterpret_cast<char*>(xmlNodeListGetString(doc,
cur->children, 1));
- char* lang = XMLhelper::get_prop(cur, "lang");
+ std::string lang;
if (name) {
- if (lang)
+ if (XMLhelper::get_prop(cur, "lang", lang))
levelname[lang] = name;
else
levelname[default_language] = name;
@@ -347,16 +337,14 @@
if (name)
xmlFree(name);
- if (lang)
- xmlFree(lang);
}
else if (XMLhelper::equal_str(cur->name, "description"))
{
char* desc = reinterpret_cast<char*>(xmlNodeListGetString(doc,
cur->children, 1));
- char* lang = XMLhelper::get_prop(cur, "lang");
+ std::string lang;
if (desc) {
- if (lang)
+ if (XMLhelper::get_prop(cur, "lang", lang))
description[lang] = desc;
else
description[default_language] = desc;
@@ -364,8 +352,6 @@
if (desc)
xmlFree(desc);
- if (lang)
- xmlFree(lang);
}
else if (XMLhelper::equal_str(cur->name, "author"))
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src plt_xml.cxx,1.8,1.9 worldobj_data_factory.cxx,1.26,1.27 xml_helper.cxx,1.18,1.19 xml_helper.hxx,1.12,1.13 xml_plf.cxx,1.26,1.27,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/input axis_factory.cxx,1.11,1.12 button_factory.cxx,1.10,1.11 pointer_factory.cxx,1.8,1.9 scroller_factory.cxx,1.9,1.10
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_surface_button.cxx,NONE,1.1
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/input axis_factory.cxx,1.11,1.12 button_factory.cxx,1.10,1.11 pointer_factory.cxx,1.8,1.9 scroller_factory.cxx,1.9,1.10
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_surface_button.cxx,NONE,1.1
- Index(es):