template.cpp 1.73 KB
Newer Older
Savva Golubitsky's avatar
Savva Golubitsky committed
1 2
#include <libtools.h>
#include <anymap.h>
3
#include <iniparser.h>
Savva Golubitsky's avatar
Savva Golubitsky committed
4

Savva Golubitsky's avatar
Savva Golubitsky committed
5 6 7
typedef std::function<int(com::Anymap*)> IntFunc;
typedef std::function<bool(com::Anymap*)> BoolFunc;
typedef std::function<bool*(com::Anymap*)> BoolArrFunc;  
Savva Golubitsky's avatar
Savva Golubitsky committed
8 9 10

IntFunc LoadEntry(std::string lib, std::string func) {
    DllHandle handler;
Savva Golubitsky's avatar
Savva Golubitsky committed
11
    return com::lib::loadFunction<int (com::Anymap*), DllHandle>(lib.c_str(), func.c_str(), handler);
Savva Golubitsky's avatar
Savva Golubitsky committed
12 13 14 15
}

BoolFunc LoadPred(std::string lib, std::string func) {
    DllHandle handler;
Savva Golubitsky's avatar
Savva Golubitsky committed
16
    return com::lib::loadFunction<int (com::Anymap*), DllHandle>(lib.c_str(), func.c_str(), handler);
Savva Golubitsky's avatar
Savva Golubitsky committed
17 18
}

19
BoolArrFunc LoadSelector(std::string lib, std::string func){
Savva Golubitsky's avatar
Savva Golubitsky committed
20
    DllHandle handler;
Savva Golubitsky's avatar
Savva Golubitsky committed
21
    return com::lib::loadFunction<bool* (com::Anymap*), DllHandle>(lib.c_str(), func.c_str(), handler);
Savva Golubitsky's avatar
Savva Golubitsky committed
22 23
}

Savva Golubitsky's avatar
Savva Golubitsky committed
24
void check_pred(bool predval, std::string predname) {
25 26 27
    if (!predval) {
        std::cout<<"Predicate "<<predname<<" returned FALSE!"<<std::endl;
        exit(-1);
Savva Golubitsky's avatar
Savva Golubitsky committed
28
    }   
29 30
}

Savva Golubitsky's avatar
Savva Golubitsky committed
31 32
int main(int argc, char const *argv[])
{   
33
    auto data = com::Anymap();
Savva Golubitsky's avatar
Savva Golubitsky committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    //Predicates
% for pred in preds:
    auto ${pred} = LoadPred("${pred.module}", "${pred.name}"); 
% endfor
    //Entry functions
% for morph in morphs:
    auto ${str(morph)} = LoadEntry("${morph.module}", "${morph.name}"); 
% endfor
    //Selectors
% for sel in sels:
    auto ${str(sel)} = LoadSelector("${sel.module}", "${sel.name}"); 
% endfor
    //Branch tokens
    bool* SEL_${states[0].name} = new bool[${len(states[0].transfers)}];
    std::fill_n(SEL_${states[0].name}, ${len(states[0].transfers)}, true);
% for st in states[1:]:
    bool* SEL_${st.name} = new bool[${len(st.transfers)}];
    std::fill_n(SEL_${st.name}, ${len(st.transfers)}, false);
% endfor

${body}
Savva Golubitsky's avatar
Savva Golubitsky committed
55

Savva Golubitsky's avatar
Savva Golubitsky committed
56 57 58 59
TERM:
    std::cout<<"Termination!\n"; 
    return 0;
}