17 |
|
|
18 |
#include <boost/lexical_cast.hpp> |
#include <boost/lexical_cast.hpp> |
19 |
|
|
20 |
|
|
21 |
namespace usata |
namespace usata |
22 |
{ |
{ |
23 |
|
|
84 |
SceneElementType ObjectElements[] = |
SceneElementType ObjectElements[] = |
85 |
{ |
{ |
86 |
{"int", IntE::create }, |
{"int", IntE::create }, |
87 |
|
{"str", StringE::create}, |
88 |
{0,0} |
{0,0} |
89 |
}; |
}; |
90 |
|
|
113 |
bool |
bool |
114 |
ObjectE::take_data_any(const std::string& name, const boost::any&data) |
ObjectE::take_data_any(const std::string& name, const boost::any&data) |
115 |
{ |
{ |
116 |
mOd->props.add(name,data); |
if (mOk) |
117 |
return true; |
{ |
118 |
|
mOd->props.add(name,data); |
119 |
|
return true; |
120 |
|
} |
121 |
|
return false; |
122 |
} |
} |
123 |
|
|
124 |
|
const char *missing_required = "'object' element missing required attribute"; |
125 |
|
|
126 |
void |
void |
127 |
ObjectE::start_element(const char*, const char **attrib) |
ObjectE::start_element(const char*, const char **attrib) |
128 |
{ |
{ |
129 |
|
const char * Type; |
130 |
|
|
131 |
|
Type = attr_check("type", attrib); |
132 |
|
if (!Type) |
133 |
|
Type=attr_check("cls", attrib); |
134 |
|
|
135 |
|
if (!Type) |
136 |
|
{ |
137 |
|
int line = mParser->get_line(); |
138 |
|
const std::string& stream_name = mParser->get_stream_name(); |
139 |
|
log::BufferedStream ls(log::Level::WARNING); |
140 |
|
if (!Type) |
141 |
|
{ |
142 |
|
ls << stream_name << ':' << line << ": " |
143 |
|
<< missing_required <<" 'type'" << log::commit; |
144 |
|
} |
145 |
|
return; |
146 |
|
} |
147 |
|
mOk=true; |
148 |
|
mOd.reset(new ObjectDescription); |
149 |
|
mOd->type=Type; |
150 |
|
|
151 |
|
|
152 |
|
return; |
153 |
} |
} |
154 |
|
|
155 |
void |
void |
156 |
ObjectE::end_element() |
ObjectE::end_element() |
157 |
{ |
{ |
158 |
|
if (mOk) |
159 |
|
{ |
160 |
|
mParser->add_object(mOd.release()); |
161 |
|
} |
162 |
} |
} |
163 |
|
|
164 |
SceneElement* |
SceneElement* |
165 |
ObjectE::make_child(const char* eName) |
ObjectE::make_child(const char* eName) |
166 |
{ |
{ |
167 |
|
SceneElementType* set = check_element_type(eName, ObjectElements); |
168 |
|
if (set) |
169 |
|
{ |
170 |
|
return set->create(this, mParser); |
171 |
|
} |
172 |
|
|
173 |
return 0; |
return 0; |
174 |
} |
} |
175 |
ObjectE::ObjectE(SceneElement* parent, SceneParser*parser) |
ObjectE::ObjectE(SceneElement* parent, SceneParser*parser) |
176 |
: SceneElement(parent,parser), |
: SceneElement(parent,parser), |
177 |
mOd(new ObjectDescription) |
mOd(new ObjectDescription), |
178 |
|
mOk(false) |
179 |
{ |
{ |
180 |
} |
} |
181 |
|
|
198 |
mHaveName=true; |
mHaveName=true; |
199 |
} |
} |
200 |
|
|
201 |
process(aValue); |
SceneElementHub * seh_p = dynamic_cast<SceneElementHub*>(mParent); |
202 |
|
|
203 |
|
if (!seh_p) |
204 |
|
{ |
205 |
|
// FIXME: warn |
206 |
|
return; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
process(aValue, *seh_p); |
211 |
|
return; |
212 |
} |
} |
213 |
|
|
214 |
|
|
215 |
IntE::IntE(SceneElement* parent, SceneParser* parser) |
IntE::IntE(SceneElement* parent, SceneParser* parser) |
216 |
: SimpleElementBase(parent,parser) |
: SimpleElementBase(parent,parser) |
217 |
{ |
{ } |
|
|
|
|
} |
|
218 |
|
|
219 |
SceneElement * |
SceneElement * |
220 |
IntE::create(SceneElement*p, SceneParser*pp) |
IntE::create(SceneElement*p, SceneParser*pp) |
223 |
} |
} |
224 |
|
|
225 |
void |
void |
226 |
IntE::process(const char* v) |
IntE::process(const char* v, SceneElementHub& pSEH) |
227 |
{ |
{ |
228 |
try |
try |
229 |
{ |
{ |
235 |
mValue=0; |
mValue=0; |
236 |
} |
} |
237 |
|
|
238 |
|
pSEH.take_data_any(mName, boost::any(mValue) ); |
239 |
|
|
240 |
return; |
return; |
241 |
} |
} |
242 |
|
|
243 |
|
StringE::StringE(SceneElement* parent, SceneParser* parser) |
244 |
|
: SimpleElementBase(parent, parser) |
245 |
|
{ } |
246 |
|
|
247 |
void |
void |
248 |
IntE::end_element() |
StringE::process(const char * v, SceneElementHub & pSEH) |
249 |
{ |
{ |
250 |
SceneElementHub * seh = dynamic_cast<SceneElementHub*>(mParent); |
std::string value(v); |
251 |
if (!seh) |
pSEH.take_data_any(mName, boost::any(value)); |
|
{ |
|
|
//FIXME: warn! |
|
|
return; |
|
|
} |
|
|
boost::any ccc(mValue); |
|
|
seh->take_data_any(mName, ccc); |
|
|
|
|
252 |
return; |
return; |
253 |
} |
} |
254 |
|
SceneElement * |
255 |
void |
StringE::create(SceneElement*p, SceneParser*pp) |
|
IntE::content(const char*b, int l) |
|
256 |
{ |
{ |
257 |
|
return new StringE(p,pp); |
258 |
} |
} |
259 |
|
|
|
|
|
|
|
|
260 |
} |
} |
261 |
} |
} |