/*
 * debugmsg.h --
 *      
 *      Header file for debug messages utils
 * 
 * Copyright (c) 2016-2017 by Simon Bachmann <simonbachmann@bluewin.ch>
 * All rights reserved.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 * 
 */


#ifndef IMGTOOLS_DEBUGMSG
    #define IMGTOOLS_DEBUGMSG
    
    #include "imgtoolsDecl.h"
    
    /*
     * Debug levels 
     * see also debug modes struct and array in debugmsg.c
     */
    #define DEBUG_NONE          0x0
    #define DEBUG_PROGRESS      0x1     //p
    #define DEBUG_PARAMETERS    0x2     //w
    #define DEBUG_MORE          0x4     //m
    #define DEBUG_ALL           0x8     //a
    #define DEBUG_FOLLOW        0x10    //f automatically set with -followpixel option
    #define DEBUG_CPUTIME       0x20    //c
    #define DEBUG_CPUTIME_DEBUG 0x40    //d
    #define DEBUG_OPTIONPARSING 0x80    //o
    #define DEBUG_TESTS         0x100   //t
    #define DEBUG_WARNING       0x200   //e
    
    /*
     * Prototypes
     */
    void Imgtools_SetDebugLevel(Tcl_Interp *interp, int newLevel);
    int Imgtools_GetDebugLevel(Tcl_Interp *interp);
    Tcl_Obj *Imgtools_GetDebugLevelStr(Tcl_Interp *interp);
    void Imgtools_DebugMsg(Tcl_Interp *interp, const int level, const char *formatStr, ...);
    int Imgtools_SetDebugLevelFromObj(Tcl_Interp *interp, Tcl_Obj *levelObj);
    int Imgtools_SetDebugLevelCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
    int Imgtools_GetDebugLevelCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
    
    // Print the values for all options in *options. Bound to DEBUG_PARAMETERS
    void Imgtools_PrintOptions(Tcl_Interp *interp, const Imgtools_CommonOpts *options);


    #ifdef IMGTOOLS_DEBUG    
        /*
         * debugmsg macro
         *      args: debugmsg(interp, level, formatString, ...)
         */
        #define debugmsg(...) Imgtools_DebugMsg (__VA_ARGS__)
        
        /*
         * debugmsg_printopts macro
         *      args: debugmsg_printoptions (interp, optPtr)
         */
        #define debugmsg_printopts(intrp, opts) ( Imgtools_PrintOptions ( ( intrp ) , ( opts ) ) )
        
    #else
        /* 
         * generates no code for the macros above, 
         * if IMGTOOLS_DEBUG is not set
         */
        #define debugmsg(...) ((void)0)
        #define debugmsg_printopts(intrp, opts) ((void)0)

    #endif
#endif //IMGTOOLS_DEBUGMSG
