digitalmars.D.learn - Do we already have full compile time / runtime separation?
Content-Type: Text/Plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Hello,
I've been trying to manage this on my own for like 2 days but still couldn'=
t=20
do that, and because my brain just suddenly turned-off, I would ask You for=
=20
some guidance.
The thing is:
I'd like to make some kind of messaging in my application. So, there is=20
=2D interface Msg
=2D classes that are implementing it, i.e. MsgWindowClose
=2D interface Provider for message publishers, i.e. MsgProviderWindowClose
=2D interface Listener for message subscibers i.e. MsgListenerWindowClose
=2D interface Handler for message filters i.e. bool MsgHandlerWindowClose.l=
og()
=2D interface Mediator for message passing between program classes, i.e.=20
MsgMediatorDMultiThreading() - which is using D messages btw.
Nothing related to D so far. Key thing is, that most of this Msg objects wi=
ll=20
be really generic, so I'm building object generator, i.e=20
MsgProviderGen!"WindowClose":
<code>
template MsgProviderGen(string MSG, Args...) {
=09
const char[] MsgProviderGen =3D "class MsgProvider"~MSG~" : MsgProvider {"
=09
~"override Msg"~MSG~" getMsg() {"
~"return new Msg"~MSG~";"
~"}"
=09
~"}";
=09
}
</code>
Which will be bigger of course.
Then, for standard and generic messages i can easily define:
<code>
private import
msg.msg,
msg.provider.gen,
msg.handler.gen;
class MsgWindowClose : Msg {
=20
}
mixin(MsgProviderGen!"WindowClose");
</code>
So far so good, but then if I'd like to add
<code>mixin("immutable uint id=3D"~static_id~";")</code>
for each *class* (not object) I got a=20
PROBLEM:
Each compile-time variable has to be const, right? So I can't increment my=
=20
`static_id` each time I build a class (how many times template has generate=
d=20
provider/listener of this type). This wont let me statically check if each=
=20
listener has its provider.
Surely it's not the only use of this feature, For loosen coupling, I'd wish=
to=20
add function that statically returns array of Msg defined in module. It isn=
't=20
an option without compile-time variables too.
Is it something about undefined module initialization?
Or maybe there is any way to overcome this problems, since I'm still new =
D=20
language.
Ps. How to make associative array of dynamic arrays?
<code>MsgHandler[hash_t][] _handlers =3D new MsgHandler[hash_t][];</code>
wont work.
Thanks for help,
Mariusz Gliwi=C5=84ski
Dec 23 2010








Mariusz =?utf-8?q?Gliwi=C5=84ski?= <alienballance gmail.com>