native/FunctionsNative.cpp (40 lines of code) (raw):

#include <stdint.h> #define STR(x) #x #define XSTR(x) STR(x) #define PPCAT_NX(A, B) A ## B #define PPCAT(A, B) PPCAT_NX(A, B) #if defined(_WIN32) #define NATIVE_API(x) extern "C" __declspec(dllexport) x __stdcall #else #define NATIVE_API(x) extern "C" x __attribute__ ((externally_visible,visibility("default"))) #endif static inline double test_function(double a, double b) { #if !defined(CODEVERSION) #error The CODEVERSION variable is undefined. #endif #pragma message ("The value of CODEVERSION: " XSTR(CODEVERSION)) #if CODEVERSION == 1 return a + b; #elif CODEVERSION == 2 return a * b; #else #error Unsupported CODEVERSION value. #endif } #define JAVA_NAMESPACE PPCAT(com_epam_deltix_utilities_FunctionsImport, CODEVERSION) /** * We are creating 3 entry points for our exported functions. * For C#, for Java and for the slightly faster JavaCritical API. */ #define FN0(return_type, java_ns, name) FN1(return_type, java_ns, name) #define FN(return_type, name) FN0(return_type, JAVA_NAMESPACE, name) /* Create .NET implementation */ #define ARGS(...) (__VA_ARGS__) #define FN1(return_type, java_ns, name) NATIVE_API(return_type) name #define DOTNET #include "FunctionsNative.h" #undef DOTNET #undef FN1 /* Create JavaCritical JNI implementation */ #define FN1(return_type, java_ns, name) NATIVE_API(return_type) JavaCritical_ ## java_ns ## _ ## name #include "FunctionsNative.h" #undef FN1 /* Create Java Native Interface implementation */ #define FN1(return_type, java_ns, name) NATIVE_API(return_type) Java_ ## java_ns ## _ ## name #undef ARGS #define ARGS(...) (void *env, void *obj, __VA_ARGS__) #include "FunctionsNative.h"