1 /** * LiveML - LiveML is screen(graphic) controling library using XML.
4 * Copyright (C) 2010 Nothan
5 * http://github.com/nothan/liveml/
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * private@nothan.xrea.jp
26 * http://tsuioku-denrai.xrea.jp/
29 #ifndef __LIVEMLRUNNER_H__
30 #define __LIVEMLRUNNER_H__
32 #include "livemlparser.h"
34 #include "bool_list.hpp"
36 #define LML_CMDFUNC(name) LML_CMDRTN name(LMLParameter ¶m)
38 typedef int LML_CMDRTN;
41 LML_CMDRTN_NULL = 0x00,
42 LML_CMDRTN_STOP = 0x01,
43 LML_CMDRTN_NEXT = 0x02,
44 LML_CMDRTN_REACTION = 0x04,
45 LML_CMDRTN_CHILD = 0x08
50 struct NumericVariable
58 fixed_float* getNumeric(variable_size id)
60 DCODE(printf("LMLVariable::getNumeric(%d)\n", id);)
61 id = VAR_LOCAL_ID(id);
62 NumericVariable *v = numericList.front();
68 numericList.chain_front(v);
76 DCODE(printf("added variable %d\n", id);)
77 v = numericList.push_front();
85 list<NumericVariable> numericList;
89 numericList.clear(true);
92 void setFixedFloat(variable_size id, fixed_float v)
94 DCODE(printf("LMLVariable::setFixedFloat(%d) = %d\n", id, v);)
98 void setString(variable_size id, const char *v)
102 fixed_float getFixedFloat(variable_size id)
104 DCODE(printf("LMLVariable::getFixedFloat(%d) = %d\n", id, *getNumeric(id));)
105 return *getNumeric(id);
108 const char* getString(variable_size id)
132 return list.push_back(false);
152 item = list_next(item);
159 return current() != NULL;
163 class ResumeTagStack : public ActiveStack<XMLElement*>
168 list.remove(current());
180 ActionParser *action;
182 ResumeTagStack resumeTagStack;
184 LMLVariable variable;
188 resumeTagStack.clear();
193 class ChildActionStack : public ActiveStack<ChildAction>
200 ChildActionStack childActionStack;
201 unsigned int waitCounter;
202 ::list<unsigned int> repeatCounter;
206 childActionStack.clear();
208 repeatCounter.clear(true);
213 childActionStack.close();
218 return childActionStack.has();
221 ChildAction* current(void)
223 return childActionStack.current();
226 ChildAction* front(void)
228 return childActionStack.front();
233 return childActionStack.add();
236 bool add(ActionParser *action)
238 if (action == NULL) return false;
240 ChildAction *ab = add();
242 ab->tag = action->tag;
248 class ActiveActionStack : public ActiveStack<ActiveAction>
253 ActiveStack<ActiveAction>::clear();
256 ActiveAction* add(ActionParser *action)
258 ActiveAction *aa = NULL;
260 if (action->unionId != UNameContainer<UNameItem>::NOTFOUND)
265 if (aa->front()->action->unionId == action->unionId)
267 if (aa->front()->action == action) return aa;
276 aa = ActiveStack<ActiveAction>::add();
280 DCODE(printf("added action[address: %x]\n", aa));
286 class ActiveEventStack : public ActiveStack<ActiveAction>
289 ActiveAction* add(ActionParser *action)
291 ActiveAction *aa = ActiveStack<ActiveAction>::add();
294 DCODE(printf("added action[address: %x]\n", aa));
303 ActiveActionStack activeActionStack;
304 ActiveEventStack activeEventStack;
307 LMLVariable variable;
322 activeActionStack.clear();
323 activeEventStack.clear();
326 void setVariableAllocator(list_allocator<NumericVariable> *alloc)
328 variable.numericList.allocator(alloc);
331 bool addAction(ActionParser *action)
333 DCODE(printf("LMLActorObject::setAction(%x)\n", action);)
334 if (action == NULL) return false;
336 activeActionStack.add(action);
340 bool addAction(action_type type)
342 DCODE(printf("LMLActorObject::setAction(%d)\n", type);)
343 ActionParser *action = parser->actionContainer[type];
344 if (action->tag == NULL) return false;
349 bool addAction(const char *name)
351 DCODE(printf("LMLActorObject::setActionByName(%s)\n", name);)
352 return addAction(parser->actionContainer[name]);
355 bool setEvent(EventParser *event)
357 DCODE(printf("LMLActorObject::setEvent(%x)\n", event);)
358 if (event == NULL) return false;
360 activeEventStack.add((ActionParser*)event);
365 bool setEvent(event_type type)
367 DCODE(printf("LMLActorObject::setEvent(%d)\n", type);)
368 EventParser *event = parser->eventContainer[type];
369 if (event->tag == NULL) return false;
371 return setEvent(event);
374 bool setEvent(const char *name)
376 DCODE(printf("LMLActorObject::setActionByName(%s)\n", name);)
377 return setEvent(parser->eventContainer[name]);
380 void endAction(const char *name)
382 ActiveAction *aa = activeActionStack.current();
385 if (!strcmp(aa->front()->action->getName(), name))
387 activeActionStack.close(aa);
397 friend class LiveMLRunner;
400 LiveMLRunner *runner;
402 ActiveAction *action;
405 LMLParameter(Parameter *param, LiveMLRunner *runner, LMLActorObject *obj, ActiveAction *action)
408 this->runner = runner;
410 this->action = action;
414 LMLVariable* getVariable(variable_size);
417 XMLParameter* get(size_t);
424 LML_CMDRTN (*func)(LMLParameter&);
427 list<LMLActorObject> _actorList;
428 vector<FuncPtr> _commandFuncs;
430 list_allocator<ChildAction> _childActionAllocator;
431 list_allocator<ActiveAction> _actionAllocator;
432 list_allocator<unsigned int> _repeatAllocator;
433 list_allocator<NumericVariable> _numericVariableAllocator;
434 list_allocator<XMLElement*> _tagPtrAllocator;
436 void setObjectAllocators(LMLActorObject&);
439 LiveMLParser *parser;
441 LMLVariable variable;
443 LiveMLRunner(LiveMLParser*);
444 virtual ~LiveMLRunner();
446 bool registerCommand(
448 LML_CMDRTN (*)(LMLParameter&)
451 void setMaxActors(size_t);
452 LMLActorObject* addActor(const char*);
453 void dropActor(LMLActorObject&);
455 LML_CMDRTN runCommand(LMLParameter&, XMLElement*);
456 LML_CMDRTN runChildAction(LMLParameter&);
457 LML_CMDRTN runAction(LMLParameter&);
458 void callEvent(LMLActorObject&, event_type);
459 void callEvent(LMLActorObject&, const char*);
460 void callEvent(event_type);
461 void callEvent(EventType*);
462 bool runActiveActions(LMLActorObject&);
463 bool runObject(LMLActorObject&);
465 LMLActorObject* getActorObject(size_t);
466 size_t getActorObjectId(LMLActorObject&);
468 virtual LMLActorObject* createActor(size_t);
470 static fixed_float calcuDecode(const char**, void*);
471 static const char* variableStringDecoder(variable_size, void*);
474 #endif // __LIVEMLRUNNER_H__