2 * LiveML - LiveML is screen(graphic) controling library using XML.
5 * Copyright (C) 2010 Nothan
6 * http://github.com/nothan/directorml/
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * private@nothan.xrea.jp
27 * http://tsuioku-denrai.xrea.jp/
30 #ifndef __LIVEMLPARSER_H__
31 #define __LIVEMLPARSER_H__
33 #include "xmlparser.h"
57 #define VAR_GLOBAL_ID(scope, id) ((0x10000000 << scope) | id)
58 #define VAR_LOCAL_ID(scope, id) (0x0FFFFFFF & id)
59 #define VAR_SCOPE_TYPE(id) ((0xF0000000 & id) >> 28)
61 #define UNDEFINED_ACTION 0xFFFFFFFF
68 const char* getName(void)
70 return tag->param.getString(0);
76 vector<ActionParser> _actions;
80 action_type getActionType(const char* name)
82 for (size_t i = 0; i < _actions.size(); i++)
84 if (!strcmp(_actions[i].getName(), name)) return i;
87 return UNDEFINED_ACTION;
90 ActionParser* getAction(action_type type)
92 if (type == UNDEFINED_ACTION || type + 1 > _actions.size()) return NULL;
93 return &_actions[type];
96 action_type addAction(void)
98 _actions.resize(_actions.size() + 1);
100 return _actions.size() - 1;
106 vector<Tag*> _events;
109 ActionContainer actionContainer;
116 const char* getName(void)
118 return tag->param.getString(0);
120 void addEventTag(Tag *t)
122 _events.push_back(t);
124 Tag* getEventTag(size_t index)
126 return _events[index];
128 size_t countEvent(void)
130 return _events.size();
134 class SceneParser : public TagAct
138 class ActorParser : public TagAct
144 vector<SceneParser> _scenes;
147 action_type getSceneType(const char* name)
149 for (size_t i = 0; i < _scenes.size(); i++)
151 if (!strcmp(_scenes[i].getName(), name)) return i;
157 SceneParser* getScene(action_type type)
159 return &_scenes[type];
162 action_type addScene(void)
164 _scenes.resize(_scenes.size() + 1);
166 return _scenes.size() - 1;
172 vector<ActorParser> _actors;
175 action_type getActorType(const char* name)
177 for (size_t i = 0; i < _actors.size(); i++)
179 if (!strcmp(_actors[i].getName(), name)) return i;
185 ActorParser* getActor(action_type type)
187 return &_actors[type];
190 action_type addActor(void)
192 _actors.resize(_actors.size() + 1);
194 return _actors.size() - 1;
198 class LiveMLParser : public XMLParser
200 SceneParser *_currentScene;
201 ActorParser *_currentActor;
203 const param_type PARAM_STRING;
204 const param_type PARAM_NUMERIC;
205 SceneContainer sceneContainer;
206 ActorContainer actorContainer;
207 ActionContainer actionContainer;
208 vector<string> variableList[VAR_SCOPE_MAX];
212 void setCurrentScene(SceneParser* t) { _currentScene = t; }
213 void setCurrentActor(ActorParser* t) { _currentActor = t; }
214 SceneParser* getCurrentScene(void) { return _currentScene; }
215 ActorParser* getCurrentActor(void) { return _currentActor; }
216 event_type registerEventType(const char*);
218 static void* paramString(const char*, XMLParser&);
219 static void* paramNumeric(const char*, XMLParser&);
220 static variable_size variableEncoder(const char*, void*);
223 #endif // __LIVEMLPARSER_H__