I'm currently trying to define a macro able to take input arguments to be passed to the asynchronous block. For now I have the following, with 'input' as a list of pairs, and 'blockCode' that is the code in the block (hehe
).
For now I would like to be able to write the following:
AwlAsyncBlock
({Awl(var1), Awl(var2)}, // define input parameters here
{
// some code
})
Or ideally:
AwlAsyncBlock
({var1, var2}, // define input parameters here
{
// some code
})
#define Awl(var) std::pair<std::string, void *>(#var, (void *)&var)
#define AwlInputEnd std::pair<std::string, void *>("__awl_null", NULL)
{
std::pair<std::string, void *> items[] = input;
std::map <std::string, void *> input_values;
for (int i = 0; items[i] != AwlInputEnd; i++)
input_values[items[i].first] = items[i].second;
struct local_struct
{
static void async_block(awl::Task *self)
{
blockCode
}
};
awl::Callback f(boost::bind(local_struct::async_block, _1));
awl::TaskRef t(new awl::Task(f));
t->SetInput(input_values);
awl::ThreadPool::Default().ScheduleTaskForExecution(t);
}
Which is not possible because of the comma issue. And if I put parenthesis around it, it is no more considered an array and
std::pair<std::string, void *> items[] = input; does no more work.
Because of this issue, I'm rather looking for a way to write something like:
AwlAsyncBlock
(AwlInput({var1, var2}), // define input parameters here
{
// some code
})
Which I don't know how to do yet.
Now as for the variadic macro, I've been taking a look at it. I know it's part of C99 standard which is ok to me. But I still can't get it to work. I would like to build a map of the input parameters where the key is the variable name and the associated value a pointer to that variable. That's why I'm defining
Awl(var) as
std::pair<std::string, void *>(#var, (void *)&var), and I would like to store these pairs in the input map. But the point with variable argument lists is you lose the name of the original variable name. You just get a list of items.