1 // ------------------------------------------------------------------
3 // ------------------------------------------------------------------
4 // This is a wrapper over a datafile.
5 // Basically, it wraps a datafile in resources like bitmaps,
6 // sound and fonts in a way that can be requested
7 // and used by the program, just requesting them by name
8 // ------------------------------------------------------------------
10 // In loving memory of my father
11 // Copyright (c) 2003, Kronoman
12 // ------------------------------------------------------------------
13 // Upgraded in January 2004, based on skin.cpp of my simple GUI manager
14 // ------------------------------------------------------------------
22 #include <map> // sweet key-data container
28 // This is the type of data that I use for the Map that cache the datafile resources
29 typedef map
<string
,DATAFILE
*> DatafileCacheMap
;
35 CWDatafile(const char *filename
);
39 void nuke_datafile(); // this frees the memory used by the datafile (and the cache, so, it resets the datafile)
41 bool load_datafile(const char *filename
); // this loads a datafile from a datafile in hard disk, returns TRUE if fails
43 void do_cache(); // this do the map cache of resources, is automatically called when needed
45 void *get_resource_dat(const string resource_name
); // This is BETTER, returns directly the data or NULL on error
46 void *get_resource_dat(const char *resource_name
); // This is BETTER, returns directly the data or NULL on error
48 DATAFILE
*get_resource(const string resource_name
); // The hot stuff: get resources, or NULL on error (or exception, if set)
49 DATAFILE
*get_resource(const char *resource_name
);
51 DATAFILE
*get_whole_datafile(); // This returns a pointer to the whole loaded DATAFILE (in case that you need it for something)
53 void dump_debug_datafile_data(); // debug function, shows all loaded on console output
56 static void set_die_on_failure(bool b
) { CWDatafile::die_on_failure
= b
; } // die on failure?
59 DATAFILE
*datafile
; // datafile in RAM
60 DatafileCacheMap datafile_cache_map
; // STL map that does the cache of the datafile resources
63 static bool die_on_failure
; // if a error ocurs, kill the app? (die with error message)