[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Usata-commits] Changes to usata2/src/xml/scene_parser_elements.cpp
From: |
David Lau |
Subject: |
[Usata-commits] Changes to usata2/src/xml/scene_parser_elements.cpp |
Date: |
Tue, 22 Feb 2005 13:18:04 -0500 |
Index: usata2/src/xml/scene_parser_elements.cpp
diff -u usata2/src/xml/scene_parser_elements.cpp:1.1
usata2/src/xml/scene_parser_elements.cpp:1.2
--- usata2/src/xml/scene_parser_elements.cpp:1.1 Fri Feb 18 02:24:33 2005
+++ usata2/src/xml/scene_parser_elements.cpp Tue Feb 22 18:17:57 2005
@@ -10,13 +10,14 @@
// included in the software distribution, or visit
// http://www.fsf.org/licenses/gpl.html.
//
-// $Id: scene_parser_elements.cpp,v 1.1 2005/02/18 02:24:33 skunix Exp $
+// $Id: scene_parser_elements.cpp,v 1.2 2005/02/22 18:17:57 skunix Exp $
#include "../log.hpp"
#include "scene_parser_elements.hpp"
#include <boost/lexical_cast.hpp>
+
namespace usata
{
@@ -83,6 +84,7 @@
SceneElementType ObjectElements[] =
{
{"int", IntE::create },
+ {"str", StringE::create},
{0,0}
};
@@ -111,29 +113,69 @@
bool
ObjectE::take_data_any(const std::string& name, const boost::any&data)
{
- mOd->props.add(name,data);
- return true;
+ if (mOk)
+ {
+ mOd->props.add(name,data);
+ return true;
+ }
+ return false;
}
+const char *missing_required = "'object' element missing required attribute";
+
void
ObjectE::start_element(const char*, const char **attrib)
{
+ const char * Type;
+
+ Type = attr_check("type", attrib);
+ if (!Type)
+ Type=attr_check("cls", attrib);
+
+ if (!Type)
+ {
+ int line = mParser->get_line();
+ const std::string& stream_name = mParser->get_stream_name();
+ log::BufferedStream ls(log::Level::WARNING);
+ if (!Type)
+ {
+ ls << stream_name << ':' << line << ": "
+ << missing_required <<" 'type'" << log::commit;
+ }
+ return;
+ }
+ mOk=true;
+ mOd.reset(new ObjectDescription);
+ mOd->type=Type;
+
+ return;
}
void
ObjectE::end_element()
{
+ if (mOk)
+ {
+ mParser->add_object(mOd.release());
+ }
}
SceneElement*
ObjectE::make_child(const char* eName)
{
+ SceneElementType* set = check_element_type(eName, ObjectElements);
+ if (set)
+ {
+ return set->create(this, mParser);
+ }
+
return 0;
}
ObjectE::ObjectE(SceneElement* parent, SceneParser*parser)
: SceneElement(parent,parser),
- mOd(new ObjectDescription)
+ mOd(new ObjectDescription),
+ mOk(false)
{
}
@@ -156,15 +198,23 @@
mHaveName=true;
}
- process(aValue);
+ SceneElementHub * seh_p = dynamic_cast<SceneElementHub*>(mParent);
+
+ if (!seh_p)
+ {
+ // FIXME: warn
+ return;
+ }
+
+
+ process(aValue, *seh_p);
+ return;
}
IntE::IntE(SceneElement* parent, SceneParser* parser)
: SimpleElementBase(parent,parser)
-{
-
-}
+{ }
SceneElement *
IntE::create(SceneElement*p, SceneParser*pp)
@@ -173,7 +223,7 @@
}
void
-IntE::process(const char* v)
+IntE::process(const char* v, SceneElementHub& pSEH)
{
try
{
@@ -185,30 +235,27 @@
mValue=0;
}
+ pSEH.take_data_any(mName, boost::any(mValue) );
+
return;
}
+StringE::StringE(SceneElement* parent, SceneParser* parser)
+: SimpleElementBase(parent, parser)
+{ }
+
void
-IntE::end_element()
+StringE::process(const char * v, SceneElementHub & pSEH)
{
- SceneElementHub * seh = dynamic_cast<SceneElementHub*>(mParent);
- if (!seh)
- {
- //FIXME: warn!
- return;
- }
- boost::any ccc(mValue);
- seh->take_data_any(mName, ccc);
-
+ std::string value(v);
+ pSEH.take_data_any(mName, boost::any(value));
return;
}
-
-void
-IntE::content(const char*b, int l)
+SceneElement *
+StringE::create(SceneElement*p, SceneParser*pp)
{
+ return new StringE(p,pp);
}
-
-
}
}