ScummVM API documentation
dictionary.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ILLUSIONS_DICTIONARY_H
23 #define ILLUSIONS_DICTIONARY_H
24 
25 #include "common/hashmap.h"
26 
27 namespace Illusions {
28 
29 struct ActorType;
30 class Control;
31 class FontResource;
32 struct Sequence;
33 struct TalkEntry;
34 
35 template<class T>
37 protected:
38  typedef Common::List<T*> List;
39  typedef typename List::iterator ListIterator;
41  typedef typename Map::iterator MapIterator;
42  Map _map;
43 public:
44 
46  for (MapIterator it = _map.begin(); it != _map.end(); ++it) {
47  delete it->_value;
48  }
49  }
50 
51  void add(uint32 id, T *value) {
52  MapIterator it = _map.find(id);
53  List *list;
54  if (it != _map.end())
55  list = it->_value;
56  else {
57  list = new List();
58  _map[id] = list;
59  }
60  list->push_back(value);
61  }
62 
63  void remove(uint32 id) {
64  MapIterator it = _map.find(id);
65  List *list;
66  if (it != _map.end()) {
67  list = it->_value;
68  list->pop_back();
69  if (list->empty()) {
70  _map.erase(id);
71  delete list;
72  }
73  }
74  }
75 
76  T *find(uint32 id) {
77  MapIterator it = _map.find(id);
78  if (it != _map.end())
79  return it->_value->back();
80  return 0;
81  }
82 
83 };
84 
85 class Dictionary {
86 public:
87 
88  void addActorType(uint32 id, ActorType *actorType);
89  void removeActorType(uint32 id);
90  ActorType *findActorType(uint32 id);
91 
92  void addFont(uint32 id, FontResource *fontResource);
93  void removeFont(uint32 id);
94  FontResource *findFont(uint32 id);
95 
96  void addSequence(uint32 id, Sequence *sequence);
97  void removeSequence(uint32 id);
98  Sequence *findSequence(uint32 id);
99 
100  void addTalkEntry(uint32 id, TalkEntry *talkEntry);
101  void removeTalkEntry(uint32 id);
102  TalkEntry *findTalkEntry(uint32 id);
103 
104  void setObjectControl(uint32 objectId, Control *control);
105  Control *getObjectControl(uint32 objectId);
106 
107 protected:
108  DictionaryHashMap<ActorType> _actorTypes;
109  DictionaryHashMap<Control> _controls;
110  DictionaryHashMap<FontResource> _fontResources;
111  DictionaryHashMap<Sequence> _sequences;
112  DictionaryHashMap<TalkEntry> _talkEntries;
113 };
114 
115 } // End of namespace Illusions
116 
117 #endif // ILLUSIONS_DICTIONARY_H
Definition: fontresource.h:58
Definition: dictionary.h:85
Definition: dictionary.h:36
Definition: list.h:44
Definition: actor.h:34
Definition: talkresource.h:42
Definition: actorresource.h:58
Definition: actorresource.h:51
void erase(iterator entry)
Definition: hashmap.h:708
Definition: list_intern.h:51
Definition: actor.h:180
void push_back(const t_T &element)
Definition: list.h:139
void pop_back()
Definition: list.h:150
bool empty() const
Definition: list.h:218