project_files/frontlib/model/cfg.h
author Medo <smaxein@googlemail.com>
Wed, 27 Jun 2012 18:02:45 +0200
changeset 7275 15f722e0b96f
parent 7271 5608ac657362
child 7314 6171f0bad318
permissions -rw-r--r--
frontlib: Getting there :) Added commandline client for testing

/**
 * Data structures for game scheme information.
 */

#ifndef CFG_H_
#define CFG_H_

#include <stdbool.h>

// TODO: cfg/config -> scheme

typedef struct {
    char *name;
    char *engineCommand;
    bool maxMeansInfinity;
    bool times1000;
    int min;
    int max;
    int def;
} flib_cfg_setting_meta;

typedef struct {
    char *name;
    int bitmaskIndex;
} flib_cfg_mod_meta;

/**
 * The order of the meta information in the arrays is the same as the order
 * of the mod/setting information in the net protocol messages.
 */
typedef struct {
	int _referenceCount;
	int settingCount;
	int modCount;
    flib_cfg_setting_meta *settings;
    flib_cfg_mod_meta *mods;
} flib_cfg_meta;

typedef struct {
	int _referenceCount;
    flib_cfg_meta *meta;

    char *name;
    int *settings;
    bool *mods;
} flib_cfg;

/**
 * Read the meta-configuration from a .ini file (e.g. which settings exist,
 * what are their defaults etc.)
 *
 * Returns the meta-configuration or NULL.
 */
flib_cfg_meta *flib_cfg_meta_from_ini(const char *filename);

/**
 * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
 * Returns the parameter.
 */
flib_cfg_meta *flib_cfg_meta_retain(flib_cfg_meta *metainfo);

/**
 * Decrease the reference count of the object and free it if this was the last reference.
 */
void flib_cfg_meta_release(flib_cfg_meta *metainfo);

/**
 * Create a new configuration with everything set to default or false
 * Returns NULL on error.
 */
flib_cfg *flib_cfg_create(flib_cfg_meta *meta, const char *schemeName);

/**
 * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
 */
flib_cfg *flib_cfg_copy(const flib_cfg *cfg);

/**
 * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
 * Returns the parameter.
 */
flib_cfg *flib_cfg_retain(flib_cfg *cfg);

/**
 * Decrease the reference count of the object and free it if this was the last reference.
 */
void flib_cfg_release(flib_cfg* cfg);

#endif /* CFG_H_ */