I use mixin to control some alias define, for example, if "test" module's dbg is on, then mixin would alias "od" to "syncprint", otherwise alias it to "nullprint".
in this case, first 4 statment in a module is like the following:
module test;
private import prjcfg;
private const char [] mod="test";
mixin (dbgctrl);
20080501 version works ok, but 20081008 would think the rest codes after the mixin is not D code.
sample code:
module test;
private import prjcfg;
private const char [] mod="test";
mixin (dbgctrl);
import xlib.comm.session;
//import xlib.comm.selector.parts;
import xlib.comm.selector.simple;
import xlib.comm.evsrc.tcpsock;
import xlib.comm.evsrc.udpsock;
dbgctrl is:
const char [] dbgctrl=
"
struct dbg
{
mixin (getvalue_stmt(mod, \"dbg\", true, true));
mixin (getvalue_stmt(mod, \"od\", true, true));
mixin (getvalue_stmt(mod, \"ut\", dbg, dbg));
mixin (getvalue_stmt(mod, \"uttitle\", ut, ut));
mixin (getvalue_stmt(mod, \"trace\", dbg, false));
mixin (getvalue_stmt(mod, \"ot\", trace, false));
mixin (getvalue_stmt(mod, \"trace_dtor\", true, false));
mixin (getvalue_stmt(mod, \"trace_fail\", true, true));
};
// alias od
static if (dbg.od || dbg.trace_dtor)
alias xlib.tools.applog.syncOut od;
else
alias xlib.tools.applog.nullPrint od;
// alias unit test's title
static if (dbg.uttitle)
alias xlib.tools.applog.syncOut title;
else
alias xlib.tools.applog.nullPrint title;
// alias ot (for trace)
static if (dbg.trace)
{
alias xlib.tools.applog.syncOut ot;
}
else
{
alias xlib.tools.applog.nullPrint ot;
}
";