Store user data in $HOME
[kball.git] / include / cwdata.h
blob77acc72ce1313bc9cbcd959030339a18e69074b1
1 // ------------------------------------------------------------------
2 // cwdata.h
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 // ------------------------------------------------------------------
9 // By Kronoman
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 // ------------------------------------------------------------------
15 #ifndef CWDATAFILE_H
16 #define CWDATAFILE_H
18 // Allegro
19 #include <allegro.h>
21 // STL stuff
22 #include <map> // sweet key-data container
23 #include <iostream>
24 #include <string>
25 using namespace std;
28 // This is the type of data that I use for the Map that cache the datafile resources
29 typedef map<string,DATAFILE *> DatafileCacheMap;
31 class CWDatafile
33 public:
34 CWDatafile();
35 CWDatafile(const char *filename);
37 ~CWDatafile();
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
55 // for all the class
56 static void set_die_on_failure(bool b) { CWDatafile::die_on_failure = b; } // die on failure?
58 private:
59 DATAFILE *datafile; // datafile in RAM
60 DatafileCacheMap datafile_cache_map; // STL map that does the cache of the datafile resources
62 // for all the class
63 static bool die_on_failure; // if a error ocurs, kill the app? (die with error message)
66 #endif