how to generate this code?

R

Roberto Gori

Phlip said:
If a legacy code had a poor design, I would work harder to fix that than
to adapt to it.

However, you can easily get your technique here:

http://www.codeproject.com/macro/metamacros.asp

i'm already faced to this kind of approach to link an enum to a vector of
strings but ...

could you give me an example on how to apply it to my case?

Are you thinking to something like this?

META(foo, bar, _m(type1) ident1, _m(type2) ident2, ...)

in this case is up to the developer to establish what's the type e what's
the identifier of the argument. Moreover for some types as the function
pointer type it's not simple to use that syntax without a typedef.
Since a complex system could contains a lot of events i would like to
generate automatically all the interfaces.
I would like to write in a text file something like that:

event_a, arg1_of_a, arg2_of_a, arg3_of_a
event_b, arg1_of_b, arg2_of_b
event_c, arg1_of_c, arg2_of_c, arg3_of_c, arg4_of_c

and for each declaration i would like to generate a header and a source
files (event_?.h event_a.cpp) containing the implementation of the
event/observer pattern for each event. The classes differ for the argument
list only.
 
C

Christian Gollwitzer

Roberto Gori wrote
the problem is to generate a code like this:

void foo(int a, char b, void (*f)(int), double g[], float c=5)
{
bar(a, b, f, g, c);
}

And what about a function template?

template <typename A,B,C,D,E>
void foo(A a, B b, C c, D d, E e)
{
bar (a,b,c,d,e);
}

should be typesafe and if you provide the same template with
zero,1,2,3... parameters you can pass anything. You can make these
templates out of a macro, or maybe some template guru knows how to do it
with metaprogramming.

Maybe have a look at libsigc++, which does something similiar, if I
understood it correctly, tom implement a GUI callback system for GTK.

Christian
 
V

Victor Bazarov

Christian said:
Roberto Gori wrote
the problem is to generate a code like this:

void foo(int a, char b, void (*f)(int), double g[], float c=5)
{
bar(a, b, f, g, c);
}

And what about a function template?

template <typename A,B,C,D,E>

A nit picked:

template said:
void foo(A a, B b, C c, D d, E e)
{
bar (a,b,c,d,e);
}

should be typesafe and if you provide the same template with
zero,1,2,3... parameters you can pass anything. You can make these
templates out of a macro, or maybe some template guru knows how to do
it with metaprogramming.

If you wrap it in a macro (that I suppose will have to be variadic anyway)
is that it will provide the compiler with way too many functions than
maybe needed (a template is an rather large number when only one was
intended). And if I wanted to make sure that conversions are involved,
I'd have to wrap it again in something.

But, of course, let the OP decide...
Maybe have a look at libsigc++, which does something similiar, if I
understood it correctly, tom implement a GUI callback system for GTK.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top