Version: 1.0
Macros | Functions
graph_code_generator.h File Reference
#include <ostream>
#include "conact_tree.h"
#include "forest.h"
#include "rule_set.h"

Go to the source code of this file.

Macros

#define BEFORE_AFTER_FUNC(func_name)
 Macro used to define the base signature of before and after functions. More...
 

Functions

std::string DefaultEmptyFunc (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
std::string BeforeMainShiftOne (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
std::string BeforeMainShiftTwo (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
std::string BeforeEnd (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
std::string AfterEnd (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
std::string AfterEndNoLoop (size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
 
size_t GenerateDragCode (std::ostream &os, const BinaryDrag< conact > &bd, bool with_gotos=false, std::string before(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=DefaultEmptyFunc, std::string after(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=DefaultEmptyFunc, const std::string prefix="", size_t start_id=0, const std::vector< std::vector< size_t >> mapping={}, size_t end_group_id=0)
 This function generates the code for the given drag reversing the output into the specified stream. More...
 
bool GenerateDragCode (const BinaryDrag< conact > &bd, bool with_gotos=false, std::string before(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=DefaultEmptyFunc, std::string after(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=DefaultEmptyFunc, const std::string prefix="", size_t start_id=0, const std::vector< std::vector< size_t >> mapping={}, size_t end_group_id=0)
 Overload. No output stream required in this case. More...
 
size_t GenerateLineForestCode (std::ostream &os, const LineForestHandler &lfh, std::string prefix, size_t start_id, std::string before_main(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=BeforeMainShiftOne, std::string after_main(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=DefaultEmptyFunc, std::string before_end(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=BeforeEnd, std::string after_end(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)=AfterEnd)
 Generate the C++ code for the given Forest. More...
 

Macro Definition Documentation

◆ BEFORE_AFTER_FUNC

#define BEFORE_AFTER_FUNC (   func_name)
Value:
std::string func_name(size_t index, \
const std::string& prefix, \
const std::vector<std::vector<size_t>>& mapping, \
size_t end_group_id)

Macro used to define the base signature of before and after functions.

Definition at line 17 of file graph_code_generator.h.

Function Documentation

◆ AfterEnd()

std::string AfterEnd ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 53 of file graph_code_generator.cpp.

◆ AfterEndNoLoop()

std::string AfterEndNoLoop ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 58 of file graph_code_generator.cpp.

◆ BeforeEnd()

std::string BeforeEnd ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 48 of file graph_code_generator.cpp.

◆ BeforeMainShiftOne()

std::string BeforeMainShiftOne ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 28 of file graph_code_generator.cpp.

◆ BeforeMainShiftTwo()

std::string BeforeMainShiftTwo ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 41 of file graph_code_generator.cpp.

◆ DefaultEmptyFunc()

std::string DefaultEmptyFunc ( size_t  index,
const std::string &  prefix,
const std::vector< std::vector< size_t >> &  mapping,
size_t  end_group_id 
)

Definition at line 15 of file graph_code_generator.cpp.

◆ GenerateDragCode() [1/2]

bool GenerateDragCode ( const BinaryDrag< conact > &  bd,
bool  with_gotos = false,
std::string   beforesize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = DefaultEmptyFunc,
std::string   aftersize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = DefaultEmptyFunc,
const std::string  prefix = "",
size_t  start_id = 0,
const std::vector< std::vector< size_t >>  mapping = {},
size_t  end_group_id = 0 
)

Overload. No output stream required in this case.

Definition at line 246 of file graph_code_generator.cpp.

◆ GenerateDragCode() [2/2]

size_t GenerateDragCode ( std::ostream &  os,
const BinaryDrag< conact > &  bd,
bool  with_gotos = false,
std::string   beforesize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = DefaultEmptyFunc,
std::string   aftersize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = DefaultEmptyFunc,
const std::string  prefix = "",
size_t  start_id = 0,
const std::vector< std::vector< size_t >>  mapping = {},
size_t  end_group_id = 0 
)

This function generates the code for the given drag reversing the output into the specified stream.

Function pointer parameters are not well treated by doxygen. TODO fix it.

Parameters
[in]osWhere to write the code (output stream).
[in]bdBinaryDrag<conact> for which generating the code.
[in]with_gotosWhether to add gotos or not during code generation.
[in]beforePointer to the function which defines the string that should be put in the code before a tree. When dealing with forests for example you will need pass to GenerateDragCode a "before" function like the following one (i identifies the tree):
[mapping](int i, const std::string& prefix) -> std::string {
return prefix + "tree_" + string(i) + ": if ((c+=1) >= w - 1) goto " + prefix + "break_0_" + string(mapping[0][i]) + ";\n";
}
this function is valid for example for thinning algorithms, PRED, SAUF, CTB and all the algorithms that have a unitary horizontal shift. When dealing with algorithm which have an horizontal shift of 2 and for this reason will need multiple end line forests a function like the following one is required:
[mapping](int i, const std::string& prefix) -> std::string {
return prefix + "tree_" + string(i) + ": if ((c+=2) >= w - 2) { if (c > w - 2) { goto " + prefix + \
"break_0_" + string(mapping_[0][i]) + "; } else { goto " + prefix + \
"break_1_" + string(mapping_[1][i]) + "; } } \n";
}
DefaultBefore function returns an empty string and is the default function passed to the GenerateDragCode function.
[in]afterPointer to the function which defines the string that should be put into the code after a tree. When dealing with forest for example you will need pass to GenerateDragCode a "before" function like the following one:
[mapping](int i, const std::string& prefix) -> std::string {
return string(2, '\t') + "continue;\n";
}
[in]prefixString to add before tree names. This variable will be passed to the before and after functions
[in]start_idIs the id from which start node enumeration when dealing with drags. It is especially useful to avoid multiple defined labels when dealing with multiple forests in the same code, like for example when having a special forest for the first line e for the last one.
[in]mappingMapping between main and end-of-the line trees. Default value is an empty mapping.
[in]end_group_idIt is the id of the end-line forest group. It is needed when an algorithm requires multiple end-line forest group, such as when dealing with block-based approaches. Default value is zero.
Returns
The last id used during code generation. This is useful when multiple must be written in the same file.

Definition at line 265 of file graph_code_generator.cpp.

◆ GenerateLineForestCode()

size_t GenerateLineForestCode ( std::ostream &  os,
const LineForestHandler lfh,
std::string  prefix,
size_t  start_id,
std::string   before_mainsize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = BeforeMainShiftOne,
std::string   after_mainsize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = DefaultEmptyFunc,
std::string   before_endsize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = BeforeEnd,
std::string   after_endsize_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id = AfterEnd 
)

Generate the C++ code for the given Forest.

Parameters description missing. (TODO)

Definition at line 298 of file graph_code_generator.cpp.