18 #ifndef ZENI_DATABASE_HXX
19 #define ZENI_DATABASE_HXX
74 handles.push_front(handle_);
79 : m_xml_identifier(xml_identifier),
82 m_filenames.push_front(filename);
95 Lookup *&lr = m_lookups[
name];
102 typename Lookup::Handles::iterator it = std::find(lr->handles.begin(), lr->handles.end(),
typename Lookup::Handle(filename));
104 if(it != lr->handles.end()) {
107 lr->handles.erase(it);
110 lr->handles.push_front(
typename Lookup::Handle(type, filename,
false, keep));
112 m_entries[lr->id] =
type;
117 template <
class TYPE>
122 Lookup *&lr = m_lookups[
name];
129 typename Lookup::Handles::iterator it = std::find(lr->handles.begin(), lr->handles.end(),
typename Lookup::Handle(
""));
131 if(it != lr->handles.end()) {
134 lr->handles.erase(it);
137 lr->handles.push_front(
typename Lookup::Handle(type,
"",
true, keep));
139 m_entries[lr->id] =
type;
144 template <
class TYPE>
146 typename Lookups::iterator it = m_lookups.find(name);
148 if(it == m_lookups.end())
151 Lookup &lr = *it->second;
152 typename Lookup::Handles::iterator jt = std::find(lr.handles.begin(), lr.handles.end(),
typename Lookup::Handle(filename));
154 if(jt == lr.handles.end())
160 lr.handles.erase(jt);
162 if(lr.handles.empty()) {
163 m_entries.erase(lr.id);
168 m_entries[lr.id] = lr.handles.begin()->ptr;
171 template <
class TYPE>
173 typename Lookups::const_iterator it = m_lookups.find(name);
175 if(it == m_lookups.end() || !it->second->id)
178 return it->second->id;
181 template <
class TYPE>
183 typename Lookups::const_iterator it = m_lookups.find(name);
185 if(it != m_lookups.end() && it->second->id && find(it->second->id))
186 return it->second->id;
191 template <
class TYPE>
193 return m_entries.find(
id) != m_entries.end();
196 template <
class TYPE>
198 typename Entries::const_iterator it = m_entries.find(
id);
200 if(it == m_entries.end() || !it->second) {
207 (
buf,
"ID = %u",
static_cast<unsigned int>(
id));
214 template <
class TYPE>
216 return (*
this)[get_id(name)];
219 template <
class TYPE>
224 template <
class TYPE>
226 Filenames::iterator it = std::find(m_filenames.begin(), m_filenames.end(),
filename);
227 if(it != m_filenames.end())
228 m_filenames.erase(it);
229 m_filenames.push_front(filename);
248 if(!give_priority(name,
false,
false, filename)) {
249 TYPE *
const type = load(it, name, filename);
253 give(name, type,
false, filename);
259 const String error =
"Error loading '" + m_xml_identifier +
"' entry '" + name +
"'";
260 std::cerr << error << std::endl;
268 template <
class TYPE>
270 Filenames::iterator it = std::find(m_filenames.begin(), m_filenames.end(),
filename);
271 if(it == m_filenames.end())
274 for(
typename Lookups::iterator it = m_lookups.begin();
275 it != m_lookups.end();
278 for(
typename Lookup::Handles::iterator jt = it->second->handles.begin();
279 jt != it->second->handles.end();)
281 if(jt->filename != filename)
286 jt = it->second->handles.erase(jt);
290 if(!it->second->handles.empty()) {
291 m_entries[it->second->id] = it->second->handles.begin()->ptr;
295 m_entries.erase(it->second->id);
301 m_filenames.erase(it);
303 if(m_filenames.empty())
307 template <
class TYPE>
313 template <
class TYPE>
315 const Filenames old = m_filenames;
317 for(Filenames::const_reverse_iterator it = old.rbegin();
329 template <
class TYPE>
335 for(
typename Lookups::iterator it = m_lookups.begin();
336 it != m_lookups.end();
339 for(
typename Lookup::Handles::iterator jt = it->second->handles.begin();
340 jt != it->second->handles.end();
353 template <
class TYPE>
359 const typename Lookups::const_iterator it = m_lookups.find(name);
360 if(it == m_lookups.end())
363 typename Lookup::Handles &lhr = it->second->handles;
364 typename Lookup::Handles::iterator jt = std::find(lhr.begin(), lhr.end(),
typename Lookup::Handle(filename));
368 if(jt->lent != lent || jt->keep != keep)
373 lhr.push_front(handle);
375 m_entries[it->second->id] = handle.
ptr;
380 template <
class TYPE>
385 template <
class TYPE>
389 for(
typename Lookups::iterator it = m_lookups.begin();
390 it != m_lookups.end();
393 for(
typename Lookup::Handles::iterator jt = it->second->handles.begin();
394 jt != it->second->handles.end();)
401 jt = it->second->handles.erase(jt);
405 if(!it->second->handles.empty())
406 m_entries[it->second->id] = it->second->handles.begin()->ptr;
408 m_entries.erase(it->second->id);
414 template <
class TYPE>
void lose_resources()
Wipe losable resources and prepare to reload them when they are next needed.
static String & load_asset(String &memory, const String &filename)
Load a file into memory.
GLsizei GLenum GLenum * types
unsigned long give(const String &name, TYPE *const &type, const bool &keep, const String &filename="")
Add an entry (which it will later delete)
unsigned long lend(const String &name, TYPE *const &type, const bool &keep)
Add an entry (which it will NEVER delete)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
static void init(struct bs2b *bs2b)
unsigned long get_id(const String &name) const
Get an id by name, possibly throwing an Error.
const char * c_str() const
EGLImageKHR EGLint * name
void load_mem(const String &data)
unsigned long assign()
Get a value, unique within this run of the program.
void reload()
lose_resources + init
void load_file(const String &filename)
Load all resources from a given file, giving them highest priority.
A Texture Database Singleton.
void clear()
Permanently clear all resources.
void ZENI_LOGD(const Zeni::String &str)
A class to open an XML file and manage the root node.
TYPE & operator[](const String &name) const
Get a TYPE by name.
Resource & get_Resource()
Get access to the singleton.
void message_box(const char *const &msg)
bool operator==(const Handle &rhs) const
unsigned long find(const String &name) const
Get an id by name, without throwing an Error.
void unlose_resources()
If resources have been lost, then reload them.
GLenum GLuint GLsizei const GLchar * buf
const bool & lost_resources()
Check to see if resources have been lost.
bool give_priority(const String &name, const bool &lent, const bool &keep, const String &filename="")
If 'lent', 'keep', and 'filename' match, give priority over other 'name' entries. ...
EGLImageKHR EGLint EGLint * handle
XML_Element_c first() const
Get the first subelement.
void unload_file(const String &filename)
Unload all resources from a given file, reloading lower priority resources.
bool good() const
Test to see if the Element is valid.