I want to build a directed graph in C++11 at compile time.
Example: I have some threads and queues and want to build up:
+-------+ +---------+ +-------+
| f_gen | -> QGen -> | f_check | -> QOut -> | f_out |
+-------+ +---------+ ^ +-------+
| |
\|/ |
| |
QProc |
| |
\|/ |
| |
+-----------+ |
| f_process | /
+-----------+
Please note that this is only an example: the solution should handle directed graphs of every node / edge type.
I want to write it maybe like:
make_directed_graph<Queue, Thread>(
// Queues
{
// ID, Type of Queue, queue size
{ 0, std::string, 100 }, // QGen
{ 1, int, 250 }, // QProc
{ 2, std::string, 500 } // QOut
},
// Threads
{
// Fn, thread cnt, in queues, out queues
{ f_gen, 5, {}, { qref(0) } }, // ID 1: QGen
{ f_check, 30, { qref(0) }, { qref(1), qref(2) }}, // IDs of queues
{ f_process, 75, { qref(1) }, { qref(2) }},
{ f_out, 12, { qref(2) }, {} }
});
Please note that this is just an idea - any other possibility of writing this down is fine for me.
I managed to implement a make_tree
function.
It can be used like
make_tree< arexp, int >(
{ '+', { 1, 2, { '*', { 3, 4, 5 } } } } )
There is one big difference here: nodes and edges can be created 'on the fly' - there is no need to reference any existing one.
The biggest problem for the directed graph is how to reference an object / structure / part which was defined earlier. Like: how to reference a queue when defining the threads (or vice verse).
My questions:
- Is it possible to define a directed graph at compile time?
- If so, can you please give me a hint how to implement it?