Commit 1c1adbf6 authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge remote-tracking branch 'origin/master' into StackTrace

Conflicts:
	src/main/java/de/monticore/lang/monticar/generator/cpp/template/AllTemplates.java
        src/main/java/de/monticore/lang/monticar/generator/cpp/GeneratorCppCli.java
parents c18e0346 6f6fa2ba
......@@ -30,7 +30,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.1.8-SNAPSHOT</version>
<version>0.1.9</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
......@@ -41,6 +41,7 @@ public class CMakeFindModule extends ViewModelBase {
private List<String> libPaths = new ArrayList<>();
private Boolean findPath;
private Boolean findLibrary;
private Boolean fortranQuadMath = false;
private boolean required;
......@@ -63,6 +64,8 @@ public class CMakeFindModule extends ViewModelBase {
this.findPath = findPath;
this.findLibrary = findLibrary;
this.required = required;
if (packageName.equals("GFortran"))
this.fortranQuadMath = true;
}
// methods
......@@ -134,4 +137,13 @@ public class CMakeFindModule extends ViewModelBase {
public void setFindLibrary(Boolean findLibrary) {
this.findLibrary = findLibrary;
}
public Boolean getFortranQuadMath() {
return fortranQuadMath;
}
public void setFortranQuadMath(Boolean fortranQuadMath) {
this.fortranQuadMath = fortranQuadMath;
}
}
......@@ -23,6 +23,7 @@ package de.monticore.lang.monticar.generator.cpp;
import de.ma2cfg.helper.Names;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc.ComponentScanner;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstanceSymbol;
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.monticar.generator.*;
......@@ -36,7 +37,7 @@ import de.monticore.lang.monticar.generator.cpp.converter.OptimizationSymbolHand
import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.cpp.mathopt.MathOptSolverConfig;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterDataModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ServerWrapperViewModel;
import de.monticore.lang.monticar.generator.testing.StreamTestGenerator;
import de.monticore.lang.monticar.ts.MCTypeSymbol;
......@@ -482,15 +483,29 @@ public class GeneratorCPP implements Generator {
private static List<FileContent> getAutopilotAdapterFiles(EMAComponentInstanceSymbol componentSymbol) {
List<FileContent> result = new ArrayList<>();
result.add(FileUtil.getResourceAsFile("/template/autopilotadapter/AutopilotAdapter.h", "AutopilotAdapter.h"));
result.add(generateAutopilotAdapter(componentSymbol));
AutopilotAdapterDataModel dm = new AutopilotAdapterDataModel();
dm.setMainModelName(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName()));
dm.setInputCount(componentSymbol.getIncomingPortInstances().size());
dm.setOutputCount(componentSymbol.getOutgoingPortInstances().size());
for ( EMAPortInstanceSymbol port : componentSymbol.getIncomingPortInstances()){
dm.addInput(port.getName(), port.getTypeReference().getName());
}
for ( EMAPortInstanceSymbol port : componentSymbol.getOutgoingPortInstances()){
dm.addOutput(port.getName(), port.getTypeReference().getName());
}
result.add(generateAutopilotAdapterH(dm));
result.add(generateAutopilotAdapterCpp(dm));
return result;
}
private static FileContent generateAutopilotAdapter(EMAComponentInstanceSymbol componentSymbol) {
AutopilotAdapterViewModel vm = new AutopilotAdapterViewModel();
vm.setMainModelName(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName()));
String fileContents = AllTemplates.generateAutopilotAdapter(vm);
private static FileContent generateAutopilotAdapterH(AutopilotAdapterDataModel dm) {
String fileContents = AllTemplates.generateAutopilotAdapterH(dm);
return new FileContent(fileContents, "AutopilotAdapter.h");
}
private static FileContent generateAutopilotAdapterCpp(AutopilotAdapterDataModel dm) {
String fileContents = AllTemplates.generateAutopilotAdapterCpp(dm);
if (currentInstance.generateCMake)
addAutopilotAdapterCMakeConfig();
return new FileContent(fileContents, "AutopilotAdapter.cpp");
......
......@@ -107,13 +107,6 @@ public final class GeneratorCppCli {
.required(false)
.build();
public static final Option OPTION_FLAG_CMAKE = Option.builder("a")
.longOpt("flag-use-cmake")
.desc("optional flag indicating if execution logging should be on")
.hasArg(false)
.required(false)
.build();
public static final Option OPTION_FLAG_AUTOPILOT_ADAPTER = Option.builder()
.longOpt("flag-generate-autopilot-adapter")
.desc("optional flag indicating if autopilot adapter should be generated")
......@@ -135,10 +128,18 @@ public final class GeneratorCppCli {
.required(false)
.build();
public static final Option OPTION_FLAG_CMAKE = Option.builder()
.longOpt("flag-generate-cmake")
.desc("optional flag indicating if a CMake project should be generated to build the model")
.hasArg(false)
.required(false)
.build();
private GeneratorCppCli() {
}
public static void main(String[] args) {
Log.initDEBUG();
Options options = getOptions();
CommandLineParser parser = new DefaultParser();
CommandLine cliArgs = parseArgs(options, parser, args);
......@@ -202,6 +203,8 @@ public final class GeneratorCppCli {
g.setExecutionLoggingActive(cliArgs.hasOption(OPTION_FLAG_EXEC_LOGGING.getLongOpt()));
g.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
g.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
try {
if (componentSymbol != null) {
g.generateFiles(componentSymbol, symTab);
......
......@@ -95,6 +95,7 @@ public class LanguageUnitCPP extends LanguageUnit {
List<String> alreadyGeneratedIncludes = new ArrayList<>();
//includes
//add default include
String backendName = MathConverter.curBackend.getBackendName();
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend")) {
resultString += "#include \"octave/oct.h\"\n";
alreadyGeneratedIncludes.add("octave/oct");
......
......@@ -141,8 +141,9 @@ public class IpoptSolverGeneratorImplementation implements NLPSolverGeneratorImp
CMakeFindModule findCoinMumps = new CMakeFindModule("CoinMumps", "", "coinmumps", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findCoinLapack = new CMakeFindModule("CoinLapack", "", "coinlapack", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findCoinBlas = new CMakeFindModule("CoinBlas", "", "coinblas", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findCoinMetis = new CMakeFindModule("CoinMetis", "", "coinmetis", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findGfortran = new CMakeFindModule("GFortran", "", "gfortran", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
return Arrays.asList(findCPPAD, findIPOpt, findCoinMumps, findCoinLapack, findCoinBlas, findGfortran);
return Arrays.asList(findCPPAD, findIPOpt, findCoinMumps, findCoinLapack, findCoinBlas, findCoinMetis, findGfortran);
}
}
......@@ -36,7 +36,8 @@ public final class AllTemplates {
private static final Template TESTS_MAIN_ENTRY;
private static final Template STRUCT;
private static final Template ENUM;
private static final Template AUTOPILOT_ADAPTER;
private static final Template AUTOPILOT_ADAPTER_CPP;
private static final Template AUTOPILOT_ADAPTER_H;
private static final Template SERVER_WRAPPER;
private static final Template DYNAMICS_EVENT_PortValueCheker;
......@@ -55,7 +56,8 @@ public final class AllTemplates {
TESTS_MAIN_ENTRY = conf.getTemplate("/test/TestsMainEntry.ftl");
STRUCT = conf.getTemplate("/type/Struct.ftl");
ENUM = conf.getTemplate("/type/Enum.ftl");
AUTOPILOT_ADAPTER = conf.getTemplate("/autopilotadapter/AutopilotAdapter.ftl");
AUTOPILOT_ADAPTER_CPP = conf.getTemplate("/autopilotadapter/AutopilotAdapterCpp.ftl");
AUTOPILOT_ADAPTER_H = conf.getTemplate("/autopilotadapter/AutopilotAdapterH.ftl");
SERVER_WRAPPER = conf.getTemplate("/serverwrapper/ServerWrapper.ftl");
DYNAMICS_EVENT_PortValueCheker = conf.getTemplate("/dynamics/events_port_value_check_h.ftl");
DYNAMICS_EVENT_DynamicHelper = conf.getTemplate("/dynamics/dynamic_port_request_connect_helper_h.ftl");
......@@ -86,8 +88,11 @@ public final class AllTemplates {
return generate(ENUM, viewModel);
}
public static String generateAutopilotAdapter(AutopilotAdapterViewModel viewModel) {
return generate(AUTOPILOT_ADAPTER, viewModel);
public static String generateAutopilotAdapterCpp(AutopilotAdapterDataModel viewModel) {
return generate(AUTOPILOT_ADAPTER_CPP, viewModel);
}
public static String generateAutopilotAdapterH(AutopilotAdapterDataModel viewModel) {
return generate(AUTOPILOT_ADAPTER_H, viewModel);
}
public static String generateServerWrapper(ServerWrapperViewModel viewModel) {
......
......@@ -20,15 +20,87 @@
*/
package de.monticore.lang.monticar.generator.cpp.viewmodel;
public final class AutopilotAdapterViewModel extends ViewModelBase {
public final class AutopilotAdapterDataModel extends ViewModelBase {
private String mainModelName;
private String inputCount;
private String outputCount;
private String inputNames = "";
private String outputNames = "";
private String inputTypes = "";
private String outputTypes = "";
private String functionDeclarations = "";
private String functionImplementations = "";
public String getMainModelName() {
return mainModelName;
}
public String getInputCount() {
return inputCount;
}
public String getOutputCount() {
return outputCount;
}
public String getInputNames() {
return inputNames;
}
public String getOutputNames() {
return outputNames;
}
public String getInputTypes() {
return inputTypes;
}
public String getOutputTypes() {
return outputTypes;
}
public String getFunctionDeclarations() {
return functionDeclarations;
}
public String getFunctionImplementations() {
return functionImplementations;
}
public void setMainModelName(String mainModelName) {
this.mainModelName = mainModelName;
}
public void setInputCount(int count) {
this.inputCount = Integer.toString(count);
}
public void setOutputCount(int count) {
this.outputCount = Integer.toString(count);
}
public void addInput(String name, String type){
//Add lines to name and type array
this.inputNames += "\n \"" + name + "\",";
this.inputTypes += "\n \"" + type + "\",";
//Add line to function declarations and implementations
String functionHeader = "EXPORT void set_input_" + name;
if (type.equals("Q")){
functionHeader += "(double v)";
this.functionImplementations += functionHeader + " { AUTOPILOT_INSTANCE." + name + " = v; }\n";
} else if (type.equals("Z")) {
functionHeader += "(int v)";
this.functionImplementations += functionHeader + " { AUTOPILOT_INSTANCE." + name + " = v; }\n";
} else if (type.equals("CommonMatrixType")) {
functionHeader += "(double *data, int size)";
this.functionImplementations += functionHeader + " { copy_double_array_to_mat( data, size, AUTOPILOT_INSTANCE." + name + "); }\n";
}
this.functionDeclarations += functionHeader + ";\n";
}
public void addOutput(String name, String type){
this.outputNames += "\n \"" + name + "\",";
this.outputTypes += "\n \"" + type + "\",";
String functionHeader = "";
if (type.equals("Q")){
functionHeader = "EXPORT double get_output_" + name + "()";
this.functionImplementations += functionHeader + " { return AUTOPILOT_INSTANCE." + name + "; }\n";
}
this.functionDeclarations += functionHeader + ";\n";
}
}
<#include "/Common.ftl">
#ifndef AUTOPILOT_ADAPTER
#define AUTOPILOT_ADAPTER
#include "AutopilotAdapter.h"
#include "./${viewModel.mainModelName}.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "armadillo.h"
${viewModel.mainModelName} AUTOPILOT_INSTANCE;
void copyJLongArrayToMatrix(JNIEnv *jenv, jlongArray &source, mat &dest) {
jsize len = jenv -> GetArrayLength(source);
if (len <= 0) {
return;
}
jlong *body = jenv -> GetLongArrayElements(source, 0);
for (int i=0; i<len; i++) {
dest(0,i) = body[i];
}
jenv -> ReleaseLongArrayElements(source, body, 0);
}
void copyJDoubleArrayToMatrix(JNIEnv *jenv, jdoubleArray &source, mat &dest) {
jsize len = jenv -> GetArrayLength(source);
if (len <= 0) {
return;
}
jdouble *body = jenv -> GetDoubleArrayElements(source, 0);
for (int i=0; i<len; i++) {
dest(0,i) = body[i];
}
jenv -> ReleaseDoubleArrayElements(source, body, 0);
}
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_timeIncrement
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1timeIncrement
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.timeIncrement = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentVelocity
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentVelocity
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.currentVelocity = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentGpsLat
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1x
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.x = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentGpsLon
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1y
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.y = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_compass
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1compass
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.compass = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentEngine
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentEngine
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.currentEngine = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentSteering
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentSteering
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.currentSteering = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentBrakes
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentBrakes
(JNIEnv *jenv, jobject jobj, jdouble v) { AUTOPILOT_INSTANCE.currentBrakes = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_addNodes_length
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1length
(JNIEnv *jenv, jobject jobj, jint v) { AUTOPILOT_INSTANCE.trajectory_length = v; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_addNodes_gpsLat
* Signature: ([D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1x
(JNIEnv *jenv, jobject jobj, jdoubleArray v) { copyJDoubleArrayToMatrix(jenv, v, AUTOPILOT_INSTANCE.trajectory_x); }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_addNodes_gpsLon
* Signature: ([D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1y
(JNIEnv *jenv, jobject jobj, jdoubleArray v) { copyJDoubleArrayToMatrix(jenv, v, AUTOPILOT_INSTANCE.trajectory_y); }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_engine
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1engine
(JNIEnv *jenv, jobject jobj) { return AUTOPILOT_INSTANCE.engine; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_steering
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1steering
(JNIEnv *jenv, jobject jobj) { return AUTOPILOT_INSTANCE.steering; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_brakes
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1brakes
(JNIEnv *jenv, jobject jobj) { return AUTOPILOT_INSTANCE.brakes; }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: exec
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_exec
(JNIEnv *jenv, jobject jobj) { AUTOPILOT_INSTANCE.execute(); }
/*
* Class: simulator_integration_AutopilotAdapter
* Method: init
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_init
(JNIEnv *jenv, jobject jobj) {
srand(time(NULL));
AUTOPILOT_INSTANCE.init();
}
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class simulator_integration_AutopilotAdapter */
#ifndef _Included_simulator_integration_AutopilotAdapter
#define _Included_simulator_integration_AutopilotAdapter
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_timeIncrement
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1timeIncrement
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentVelocity
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentVelocity
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_x
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1x
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_y
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1y
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_compass
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1compass
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentEngine
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentEngine
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentSteering
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentSteering
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_currentBrakes
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1currentBrakes
(JNIEnv *, jobject, jdouble);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_trajectory_length
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1length
(JNIEnv *, jobject, jint);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_trajectory_x
* Signature: ([D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1x
(JNIEnv *, jobject, jdoubleArray);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: set_trajectory_y
* Signature: ([D)V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_set_1trajectory_1y
(JNIEnv *, jobject, jdoubleArray);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_engine
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1engine
(JNIEnv *, jobject);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_steering
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1steering
(JNIEnv *, jobject);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: get_brakes
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_simulator_integration_AutopilotAdapter_get_1brakes
(JNIEnv *, jobject);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: exec
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_exec
(JNIEnv *, jobject);
/*
* Class: simulator_integration_AutopilotAdapter
* Method: init
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_simulator_integration_AutopilotAdapter_init
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
<#include "/Common.ftl">
#include "AutopilotAdapter.h"
#include "./${viewModel.mainModelName}.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "armadillo"
void copy_double_array_to_mat(double *data, int size, mat &dest){
for (int i=0; i<size; ++i) {
dest(0,i) = data[i];
}
}
${viewModel.mainModelName} AUTOPILOT_INSTANCE;
int input_count = ${viewModel.inputCount};
int output_count = ${viewModel.outputCount};
const char *input_names[] = { ${viewModel.inputNames}
};
const char *output_names[] = { ${viewModel.outputNames}
};
const char *input_types[] = { ${viewModel.inputTypes}
};
const char *output_types[] = { ${viewModel.outputTypes}
};
extern "C" {
EXPORT int get_input_count(){
return input_count;
}
EXPORT const char *get_input_name(int id){
return input_names[id];
}
EXPORT const char *get_input_type(int id){
return input_types[id];
}
EXPORT int get_output_count(){
return output_count;
}
EXPORT const char *get_output_name(int id){
return output_names[id];
}
EXPORT const char *get_output_type(int id){
return output_types[id];
}
EXPORT void init(){
srand(time(NULL));
AUTOPILOT_INSTANCE.init();
}
EXPORT void execute(){
AUTOPILOT_INSTANCE.execute();
}
${viewModel.functionImplementations}
}
\ No newline at end of file
<#include "/Common.ftl">
#pragma once
#if defined(_MSC_VER)
// Microsoft
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
// GCC
#define EXPORT __attribute__((visibility("default")))
#define IMPORT
#else
// do nothing and hope for the best?
#define EXPORT
#define IMPORT
#pragma warning Unknown dynamic link import/export semantics.
#endif
extern "C" {
EXPORT int get_input_count();
EXPORT const char *get_input_name(int id);
EXPORT const char *get_input_type(int id);
EXPORT int get_output_count();
EXPORT const char *get_output_name(int id);
EXPORT const char *get_output_type(int id);
EXPORT void init();
EXPORT void execute();