/**
 @file ini.h
 @brief Management for configuration file.
 @author CLS
 */
#ifndef _INI_H
#define _INI_H

#include "fes_int.h"

/**
 @struct __ini
 @brief Stores the data necessary to read a configuration file.
 */
struct __ini
{
    /** Number of items read. */
    unsigned int nItems;
    /** Keys known. */
    char** key;
    /** Known values of the keys. */
    char** val;
    /** Maximum number of elements that can be stored. */
    unsigned int maxItems;
};

/**
 @typedef _ini
 @brief A utility data type for ::__ini structure.
 */
typedef struct __ini _ini;

/**
 @fn ini_open(fes_handler* fes, const char* const path, void** handle)

 @brief Open a configuration file.

 @param fes       FES handler.
 @param path      Absolute or relative file name for ini file to be opened.
 @param handle    Handle for the open file

 @return 0 on success otherwise an error status.
 */
int ini_open(fes_handler* fes, const char* const path, void** handle);

/**
 @fn ini_close(void* handle)

 @brief Close an open file.

 @param handle    Handle for the open file
 */
void ini_close(void* handle);

/**
 @fn ini_get_integer(void* const handle, const char* const key,
 const int defValue)

 @brief Read the integer value for a given key.
 If the key doesn't exists the function returns the default value.

 @param handle    Handle for the open file
 @param key       Key to read
 @param defValue  Default value

 @return 0 on success otherwise an error status.
 */
int ini_get_integer(
        void* const handle,
        const char* const key,
        const int defValue);

/**
 @fn ini_get_float(void* const handle, const char* const key,
 const double defValue)

 @brief Read the float value for a given key.
 If the key doesn't exists the function returns the default value.

 @param handle    Handle for the open file
 @param key       Key to read
 @param defValue  Default value

 @return 0 on success otherwise an error status.
 */
double ini_get_float(
        void* const handle,
        const char* const key,
        const double defValue);

/**
 @fn ini_get_string(void* const handle, const char* const key,
 const char* const defValue)

 @brief Read the string for a given key.
 If the key doesn't exists the function returns the default value.

 @param handle    Handle for the open file
 @param key       Key to read
 @param defValue  Default value

 @return 0 on success otherwise an error status.
 */
const char* ini_get_string(
        void* const handle,
        const char* const key,
        const char* const defValue);
#endif
