OSDN Git Service

support the variable(mounting and has many bugs)
[liveml/LiveML.git] / src / livemlparser.h
1 /**
2  * LiveML - LiveML is screen(graphic) controling library using XML.
3  *
4  * LGPL License
5  * Copyright (C) 2010 Nothan
6  * http://github.com/nothan/directorml/
7  * All rights reserved.
8  *
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.
13  *
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.
18  *
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
22  *
23  * Nothan
24  * private@nothan.xrea.jp
25  *
26  * Tsuioku Denrai
27  * http://tsuioku-denrai.xrea.jp/
28  */
29
30 #ifndef __LIVEMLPARSER_H__
31 #define __LIVEMLPARSER_H__
32
33 #include "xmlparser.h"
34 #include "calcu.h"
35 #include "text.h"
36
37 enum event_type
38 {
39   EVENT_INIT = 0,
40   EVENT_RELEASE,
41   EVENT_FOCUS_ON,
42   EVENT_FOCUS_OFF,
43   EVENT_BTN_PUSH,
44   EVENT_BTN_HOLD,
45   EVENT_PTN_FREE,
46   EVENT_NUMBER
47 };
48
49 // variable scope
50 enum
51 {
52   VAR_SCOPE_ACTOR = 0,
53   VAR_SCOPE_ACTION,
54   VAR_SCOPE_PARENT,
55   VAR_SCOPE_MAX
56 };
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)
60
61 #define UNDEFINED_ACTION 0xFFFFFFFF
62
63 class ActionParser
64 {
65 public:
66   Tag *tag;
67
68   const char* getName(void)
69   {
70     return tag->param.getString(0);
71   }
72 };
73
74 class ActionContainer
75 {
76   vector<ActionParser> _actions;
77
78 public:
79
80   action_type getActionType(const char* name)
81   {
82     for (size_t i = 0; i < _actions.size(); i++)
83     {
84       if (!strcmp(_actions[i].getName(), name)) return i;
85     }
86
87     return UNDEFINED_ACTION;
88   }
89
90   ActionParser* getAction(action_type type)
91   {
92     if (type == UNDEFINED_ACTION || type + 1 > _actions.size()) return NULL;
93     return &_actions[type];
94   }
95
96   action_type addAction(void)
97   {
98     _actions.resize(_actions.size() + 1);
99
100     return _actions.size() - 1;
101   }
102 };
103
104 class TagAct
105 {
106   vector<Tag*> _events;
107 public:
108   Tag *tag;
109   ActionContainer actionContainer;
110   TagAct *parent;
111
112   TagAct(void)
113   {
114     parent = NULL;
115   }
116   const char* getName(void)
117   {
118     return tag->param.getString(0);
119   }
120   void addEventTag(Tag *t)
121   {
122     _events.push_back(t);
123   }
124   Tag* getEventTag(size_t index)
125   {
126     return _events[index];
127   }
128   size_t countEvent(void)
129   {
130     return _events.size();
131   }
132 };
133
134 class SceneParser : public TagAct
135 {
136 };
137
138 class ActorParser : public TagAct
139 {
140 };
141
142 class SceneContainer
143 {
144   vector<SceneParser> _scenes;
145 public:
146
147   action_type getSceneType(const char* name)
148   {
149     for (size_t i = 0; i < _scenes.size(); i++)
150     {
151       if (!strcmp(_scenes[i].getName(), name)) return i;
152     }
153
154     return -1;
155   }
156
157   SceneParser* getScene(action_type type)
158   {
159     return &_scenes[type];
160   }
161
162   action_type addScene(void)
163   {
164     _scenes.resize(_scenes.size() + 1);
165
166     return _scenes.size() - 1;
167   }
168 };
169
170 class ActorContainer
171 {
172   vector<ActorParser> _actors;
173 public:
174
175   action_type getActorType(const char* name)
176   {
177     for (size_t i = 0; i < _actors.size(); i++)
178     {
179       if (!strcmp(_actors[i].getName(), name)) return i;
180     }
181
182     return -1;
183   }
184
185   ActorParser* getActor(action_type type)
186   {
187     return &_actors[type];
188   }
189
190   action_type addActor(void)
191   {
192     _actors.resize(_actors.size() + 1);
193
194     return _actors.size() - 1;
195   }
196 };
197
198 class LiveMLParser : public XMLParser
199 {
200   SceneParser *_currentScene;
201   ActorParser *_currentActor;
202 public:
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];
209
210   LiveMLParser(void);
211
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*);
217 protected:
218   static void* paramString(const char*, XMLParser&);
219   static void* paramNumeric(const char*, XMLParser&);
220   static variable_size variableEncoder(const char*, void*);
221 };
222
223 #endif // __LIVEMLPARSER_H__