/*****************************************************************************
 * $LastChangedDate: 2011-04-19 18:21:42 -0400 (Tue, 19 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Macros for common functions in module-specific Conf classes.
 * LEGAL:   COPYRIGHT (C) 2011 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

/*******************************************************************************
 * Put this inside every Conf::Init().
 * This initializes a Conf struct and parses cmd-line args.
 *******************************************************************************/
#define CONF_TEMPLATE_Init_ParseCmdline                                                                         \
{{                                                                                                              \
BEGIN_ONCE {                                                                                                    \
    mValid = true;  /* assign this first as MODULE_CONF may expand to GetConf() which asserts it */             \
    ParseCmdlineArgs( initArgs.mArgc, initArgs.mArgv );   /* cmdline args parsed prior to reading .conf file */ \
    ParseCmdlineArgs2( initArgs.mArgc, initArgs.mArgv );  /* cmdline args that override .conf file */           \
} END_ONCE                                                                                                      \
}}

/*******************************************************************************
 * Put this inside every Conf::Init().
 * This parses cmd-line twice and in between reads a text conf file.
 * The reason is that some cmd-line args override a conf file on the second pass.
 *******************************************************************************/
#define CONF_TEMPLATE_Init_ParseCmdline_ReadConfTxt                                                             \
{{                                                                                                              \
BEGIN_ONCE {                                                                                                    \
    mValid = true;  /* assign this first as MODULE_CONF may expand to GetConf() which asserts it */             \
    ParseCmdlineArgs( initArgs.mArgc, initArgs.mArgv );   /* cmdline args parsed prior to reading .conf file */ \
    ReadConfTxt( confTxtFilename );                       /* read from text .conf file */                       \
    ParseCmdlineArgs2( initArgs.mArgc, initArgs.mArgv );  /* cmdline args that override .conf file */           \
} END_ONCE                                                                                                      \
}}

/*******************************************************************************
 * Put this inside every Conf::ReadConfTxt().
 *******************************************************************************/
#define CONF_TEMPLATE_ReadConfTxt                                                               \
{{                                                                                              \
    try                                                                                         \
    {                                                                                           \
        ModuleConfTxt confTxt;                                                                  \
        confTxt.Read( string(base::GetDataDir()) + string(confTxtFilename) );                   \
    }                                                                                           \
    catch ( const Exception& e )                                                                \
    {                                                                                           \
        CERROR << "[conf] ERROR: cannot read " << confTxtFilename << endl << e.what() << endl;  \
        EXIT( 1 );                                                                              \
    }                                                                                           \
}}
