Browse Source

Add C++ name mangling

Support for C++.
master
TheoryOfNekomata 1 year ago
parent
commit
b5007a86c4
1 changed files with 38 additions and 30 deletions
  1. +38
    -30
      ini-config.h

+ 38
- 30
ini-config.h View File

@@ -7,6 +7,10 @@
#include <stdbool.h> #include <stdbool.h>
#include <minIni.h> #include <minIni.h>


#ifdef __cplusplus
extern "C" {
#endif

/** /**
* Struct for transformer functions used for properly loading and saving the config item's value. * Struct for transformer functions used for properly loading and saving the config item's value.
*/ */
@@ -14,11 +18,11 @@ typedef struct {
/** /**
* Function that formats the value from memory to a value that is write-friendly to the config file. * Function that formats the value from memory to a value that is write-friendly to the config file.
*/ */
void* serialize;
void *serialize;
/** /**
* Function that formats the value from file to a value that is read-friendly to memory. * Function that formats the value from file to a value that is read-friendly to memory.
*/ */
void* deserialize;
void *deserialize;
} INI_ConfigTransformer; // TODO: should we unify this with INI_ConfigType? } INI_ConfigTransformer; // TODO: should we unify this with INI_ConfigType?


struct INI_ConfigItem; struct INI_ConfigItem;
@@ -26,7 +30,7 @@ struct INI_ConfigItem;
/** /**
* Function for loading a config item value from file to memory. * Function for loading a config item value from file to memory.
*/ */
typedef void INI_ConfigTypeLoad(struct INI_ConfigItem*, const char*);
typedef void INI_ConfigTypeLoad(struct INI_ConfigItem *, const char *);


/** /**
* Result enum for saving config items. * Result enum for saving config items.
@@ -46,12 +50,12 @@ typedef enum {
/** /**
* Function for saving a config item value from memory to file. * Function for saving a config item value from memory to file.
*/ */
typedef INI_ConfigSaveItemResult INI_ConfigTypeSave(struct INI_ConfigItem*, const char*);
typedef INI_ConfigSaveItemResult INI_ConfigTypeSave(struct INI_ConfigItem *, const char *);


/** /**
* Function for retrieving a config item value from the command-line to memory. * Function for retrieving a config item value from the command-line to memory.
*/ */
typedef void INI_ConfigTypeOverride(struct INI_ConfigItem*, uint8_t, const char*[]);
typedef void INI_ConfigTypeOverride(struct INI_ConfigItem *, uint8_t, const char *[]);


/** /**
* Struct for the config item type. * Struct for the config item type.
@@ -65,17 +69,17 @@ typedef struct {
* Load function. * Load function.
* @see INI_ConfigTypeLoad * @see INI_ConfigTypeLoad
*/ */
INI_ConfigTypeLoad* load;
INI_ConfigTypeLoad *load;
/** /**
* Save function. * Save function.
* @see INI_ConfigTypeSave * @see INI_ConfigTypeSave
*/ */
INI_ConfigTypeSave* save;
INI_ConfigTypeSave *save;
/** /**
* Override function. * Override function.
* @see INI_ConfigTypeOverride * @see INI_ConfigTypeOverride
*/ */
INI_ConfigTypeOverride* override;
INI_ConfigTypeOverride *override;
} INI_ConfigType; } INI_ConfigType;


/** /**
@@ -89,23 +93,23 @@ typedef struct INI_ConfigItem {
/** /**
* Section where this config item can be found. * Section where this config item can be found.
*/ */
const char* section;
const char *section;
/** /**
* Key where this config item value is serialized and stored. * Key where this config item value is serialized and stored.
*/ */
const char* key;
const char *key;
/** /**
* Command-line option for overriding this config item's value. * Command-line option for overriding this config item's value.
*/ */
const char* cmdline_option; // TODO: should we extract commandline parsing logic?
const char *cmdline_option; // TODO: should we extract commandline parsing logic?
/** /**
* Default value of the config item, when the value could not be read from the config file. * Default value of the config item, when the value could not be read from the config file.
*/ */
const void* default_value;
const void *default_value;
/** /**
* Validator function for the config item's value. * Validator function for the config item's value.
*/ */
void* validator;
void *validator;
/** /**
* Transformer functions. * Transformer functions.
* @see INI_ConfigTransformer * @see INI_ConfigTransformer
@@ -115,14 +119,14 @@ typedef struct INI_ConfigItem {
* The memory address where the config item value will reside. This property should allow storing the amount of butes * The memory address where the config item value will reside. This property should allow storing the amount of butes
* specified under `type.size`. * specified under `type.size`.
*/ */
void* dest;
void *dest;
} INI_ConfigItem; } INI_ConfigItem;


/** /**
* Retrieves the value from a command-line option. * Retrieves the value from a command-line option.
* @return The string value from the command-line option. * @return The string value from the command-line option.
*/ */
const char* INI_ConfigGetCommandlineOption(uint8_t, const char*[], const char*);
const char *INI_ConfigGetCommandlineOption(uint8_t, const char *[], const char *);


/** /**
* Result enum for initializing config items. * Result enum for initializing config items.
@@ -142,11 +146,15 @@ typedef enum {
INI_CONFIG_INITIALIZE_RESULT_WARNING INI_CONFIG_INITIALIZE_RESULT_WARNING
} INI_ConfigInitializeResult; } INI_ConfigInitializeResult;


INI_ConfigInitializeResult INI_ConfigInitialize(INI_ConfigItem[], const char*, uint8_t, const char*[]);
INI_ConfigInitializeResult INI_ConfigInitialize(INI_ConfigItem[], const char *, uint8_t, const char *[]);


typedef int32_t INI_ConfigSaveResult; typedef int32_t INI_ConfigSaveResult;


INI_ConfigSaveResult INI_ConfigSave(INI_ConfigItem[], const char*);
INI_ConfigSaveResult INI_ConfigSave(INI_ConfigItem[], const char *);

#ifdef __cplusplus
};
#endif


#define INI_CONFIG_DECLARE_TYPE(ID) \ #define INI_CONFIG_DECLARE_TYPE(ID) \
INI_ConfigTypeLoad INI_ConfigLoad##ID; \ INI_ConfigTypeLoad INI_ConfigLoad##ID; \
@@ -154,24 +162,24 @@ INI_ConfigTypeSave INI_ConfigSave##ID; \
INI_ConfigTypeOverride INI_ConfigOverride##ID INI_ConfigTypeOverride INI_ConfigOverride##ID


#define INI_CONFIG_TRANSFORMER_NONE (INI_ConfigTransformer) { \ #define INI_CONFIG_TRANSFORMER_NONE (INI_ConfigTransformer) { \
.serialize = NULL, \
.deserialize = NULL, \
.serialize = NULL, \
.deserialize = NULL, \
} }


#define INI_CONFIG_ITEM_NULL (INI_ConfigItem) { \ #define INI_CONFIG_ITEM_NULL (INI_ConfigItem) { \
(INI_ConfigType) { \ (INI_ConfigType) { \
.size = 0, \
.load = NULL, \
.save = NULL, \
.override = NULL, \
.size = 0, \
.load = NULL, \
.save = NULL, \
.override = NULL, \
}, \ }, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
INI_CONFIG_TRANSFORMER_NONE, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
INI_CONFIG_TRANSFORMER_NONE, \
NULL, \
} }


#endif #endif

Loading…
Cancel
Save