project_files/frontlib/model/cfg.h
changeset 7230 240620f46dd7
parent 7224 5143861c83bd
child 7271 5608ac657362
equal deleted inserted replaced
7227:1c859f572d72 7230:240620f46dd7
     1 /**
     1 /**
     2  * Data structures for game scheme information.
     2  * Data structures for game scheme information.
     3  *
       
     4  * Important conventions:
       
     5  * - All data structures own what they point to.
       
     6  * - Strings are never null pointers.
       
     7  */
     3  */
     8 
     4 
     9 #ifndef CFG_H_
     5 #ifndef CFG_H_
    10 #define CFG_H_
     6 #define CFG_H_
    11 
     7 
    12 #include <stdbool.h>
     8 #include <stdbool.h>
    13 
     9 
       
    10 // TODO: cfg/config -> scheme
       
    11 
    14 typedef struct {
    12 typedef struct {
    15     char *iniName;
    13     char *name;
    16     char *title;
       
    17     char *engineCommand;
    14     char *engineCommand;
    18     char *image;
    15     bool maxMeansInfinity;
    19     int netplayIndex;
       
    20     bool checkOverMax;
       
    21     bool times1000;
    16     bool times1000;
    22     int def;
       
    23     int min;
    17     int min;
    24     int max;
    18     int max;
       
    19     int def;
    25 } flib_cfg_setting_meta;
    20 } flib_cfg_setting_meta;
    26 
    21 
    27 typedef struct {
    22 typedef struct {
    28     char *iniName;
    23     char *name;
    29     int bitmaskIndex;
    24     int bitmaskIndex;
    30 } flib_cfg_mod_meta;
    25 } flib_cfg_mod_meta;
    31 
    26 
    32 typedef struct {
    27 typedef struct {
    33     int settingCount;
    28 	int _referenceCount;
    34     int modCount;
    29 	int settingCount;
       
    30 	int modCount;
    35     flib_cfg_setting_meta *settings;
    31     flib_cfg_setting_meta *settings;
    36     flib_cfg_mod_meta *mods;
    32     flib_cfg_mod_meta *mods;
    37 } flib_cfg_meta;
    33 } flib_cfg_meta;
    38 
    34 
    39 typedef struct {
    35 typedef struct {
    40     int settingCount;
    36 	int _referenceCount;
    41     int modCount;
    37     flib_cfg_meta *meta;
       
    38 
    42     char *schemeName;
    39     char *schemeName;
    43     int *settings;
    40     int *settings;
    44     bool *mods;
    41     bool *mods;
    45 } flib_cfg;
    42 } flib_cfg;
    46 
    43 
    47 /**
    44 /**
    48  * Read the meta-configuration from the relevant .ini files (e.g. which settings exist,
    45  * Read the meta-configuration from a .ini file (e.g. which settings exist,
    49  * what are their defaults etc.)
    46  * what are their defaults etc.)
    50  *
    47  *
    51  * Returns the meta-configuration or NULL. Destroy the meta-configuration with
    48  * Returns the meta-configuration or NULL.
    52  * flib_cfg_meta_destroy.
       
    53  */
    49  */
    54 flib_cfg_meta *flib_cfg_meta_from_ini(const char *settingpath, const char *modpath);
    50 flib_cfg_meta *flib_cfg_meta_from_ini(const char *filename);
    55 void flib_cfg_meta_destroy(flib_cfg_meta *metainfo);
       
    56 
    51 
    57 /**
    52 /**
    58  * Create a new configuration with default settings.
    53  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    54  * Returns the parameter.
       
    55  */
       
    56 flib_cfg_meta *flib_cfg_meta_retain(flib_cfg_meta *metainfo);
       
    57 
       
    58 /**
       
    59  * Decrease the reference count of the object and free it if this was the last reference.
       
    60  */
       
    61 void flib_cfg_meta_release(flib_cfg_meta *metainfo);
       
    62 
       
    63 /**
       
    64  * Create a new configuration with everything set to default or false
    59  * Returns NULL on error.
    65  * Returns NULL on error.
    60  */
    66  */
    61 flib_cfg *flib_cfg_create(const flib_cfg_meta *meta, const char *schemeName);
    67 flib_cfg *flib_cfg_create(flib_cfg_meta *meta, const char *schemeName);
    62 
    68 
    63 /**
    69 /**
    64  * Load a configuration from the ini file.
    70  * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
    65  * Returns NULL on error.
       
    66  */
    71  */
    67 flib_cfg *flib_cfg_from_ini(const flib_cfg_meta *meta, const char *filename);
    72 flib_cfg *flib_cfg_copy(flib_cfg *cfg);
    68 
    73 
    69 /**
    74 /**
    70  * Store the configuration to an ini file.
    75  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
    71  * Returns NULL on error.
    76  * Returns the parameter.
    72  */
    77  */
    73 int flib_cfg_to_ini(const flib_cfg_meta *meta, const char *filename, const flib_cfg *config);
    78 flib_cfg *flib_cfg_retain(flib_cfg *cfg);
    74 void flib_cfg_destroy(flib_cfg* cfg);
    79 
       
    80 /**
       
    81  * Decrease the reference count of the object and free it if this was the last reference.
       
    82  */
       
    83 void flib_cfg_release(flib_cfg* cfg);
    75 
    84 
    76 #endif /* CFG_H_ */
    85 #endif /* CFG_H_ */