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

typedef std::function<int(com::Anymap)> IntFunc;
typedef std::function<bool(com::Anymap)> BoolFunc;
6
typedef std::function<bool*(com::Anymap)> BoolArrFunc;  
Savva Golubitsky's avatar
Savva Golubitsky committed
7 8 9 10 11 12 13 14 15 16 17

IntFunc LoadEntry(std::string lib, std::string func) {
    DllHandle handler;
    return com::lib::loadFunction<int (com::Anymap), DllHandle>(lib.c_str(), func.c_str(), handler);
}

BoolFunc LoadPred(std::string lib, std::string func) {
    DllHandle handler;
    return com::lib::loadFunction<int (com::Anymap), DllHandle>(lib.c_str(), func.c_str(), handler);
}

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

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

Savva Golubitsky's avatar
Savva Golubitsky committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
int main(int argc, char const *argv[])
{   
    auto data = com::Anymap();
    //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
54

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