template.cpp 1.96 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 5 6

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

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);
}

19
BoolArrFunc LoadSelector(std::string lib, std::string func){
Savva Golubitsky's avatar
Savva Golubitsky committed
20
    DllHandle handler;
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 34 35 36 37
    com::ini::INIParser parser(argv[1]);
    if(!parser.isLoaded()){
        std::cerr<<"Cannot find file:"<<argv[1]<<std::endl;
        return -1;
    }
38
    auto data = com::Anymap();
39
    parser.loadINIDataToAnyMap(data, {"sld", "tsl", "bc"}, enu_LoadMode::lmRecursive);
Savva Golubitsky's avatar
Savva Golubitsky committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    //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
61

Savva Golubitsky's avatar
Savva Golubitsky committed
62 63 64 65
TERM:
    std::cout<<"Termination!\n"; 
    return 0;
}