Empirical
Macros | Functions
utils.h File Reference
#include <map>
#include <string>
#include "../../base/macros.h"
#include "../init.h"
#include "../js_utils.h"
#include "../JSWrap.h"

Go to the source code of this file.

Macros

#define IS_JS_FUNCTION(FN)   (typeof FN === "function")
 A more descriptive wrapper for the check to see if something is a function in Javascript. More...
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_WINDOW()
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_1(A1)
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_2(A1, A2)
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_3(A1, A2, A3)
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE(...)   do {EMP_ASSEMBLE_MACRO(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_, __VA_ARGS__);} while (0);
 
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW(...)
 
#define D3_CALLBACK_FUNCTION_1_ARG(FUNC, CALLBACK)
 
#define D3_CALLBACK_FUNCTION_2_ARGS(FUNC, CALLBACK, ARG1)
 
#define D3_CALLBACK_METHOD_2_ARGS_IMPL(MACRO, FUNC, ARG1, ARG2)
 
#define D3_CALLBACK_METHOD_2_ARGS(FUNC, ARG1, ARG2)   D3_CALLBACK_METHOD_2_ARGS_IMPL(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW("d3", "emp"), FUNC, ARG1, ARG2);
 
#define D3_CALLBACK_METHOD_1_ARG_IMPL(MACRO, FUNC, ARG1)
 
#define D3_CALLBACK_METHOD_1_ARG(FUNC, ARG1)   D3_CALLBACK_METHOD_1_ARG_IMPL(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW("d3", "emp"), FUNC, ARG1);
 
#define D3_CALLBACK_METHOD_CPP_FUNCTION_2_ARGS(FUNC, ARG1, CPP_FUN)
 
#define D3_CALLBACK_METHOD_CPP_FUNCTION_1_ARG(FUNC, CPP_FUN)
 

Functions

void StoreNewObject (int id)
 

Macro Definition Documentation

#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE (   ...)    do {EMP_ASSEMBLE_MACRO(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_, __VA_ARGS__);} while (0);

Expects func_string to be a pre-defined variable that holds a string that may or may not be a function and checks to see if it is a function defined within and of the given namespaces. If it is, it stores that function in the variable func_string. Namespaces are checked in the order given and the first function found is used.

#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_1 (   A1)
Value:
if IS_JS_FUNCTION(window[A1][func_string]){ \
func_string = window[A1][func_string]; \
}
#define IS_JS_FUNCTION(FN)
A more descriptive wrapper for the check to see if something is a function in Javascript.
Definition: utils.h:21
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_2 (   A1,
  A2 
)
Value:
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_1(A1)
Definition: utils.h:34
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_3 (   A1,
  A2,
  A3 
)
Value:
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_2(A1, A2)
Definition: utils.h:40
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_1(A1)
Definition: utils.h:34
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW (   ...)
Value:
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_WINDOW()
Definition: utils.h:26
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE(...)
Definition: utils.h:53

Expects func_string to be a pre-defined variable that holds a string that may or may not be a function and checks to see if it is a function defined within and of the given namespaces or the current window. If it is, it stores that function in the variable func_string. Namespaces are checked in the order given and the first function found is used.

#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_WINDOW ( )
Value:
do { \
if IS_JS_FUNCTION(window[func_string]) { \
func_string = window[func_string]; \
} \
} while (0);
#define IS_JS_FUNCTION(FN)
A more descriptive wrapper for the check to see if something is a function in Javascript.
Definition: utils.h:21

Expects func_string to be a pre-defined variable that holds a string that may or may not be a function and checks to see if it is a function defined within the current window. If it is, it stores that function in the variable func_string.

#define D3_CALLBACK_FUNCTION_1_ARG (   FUNC,
  CALLBACK 
)
Value:
EM_ASM_ARGS({ \
var func_string = Pointer_stringify($0); \
emp.__new_object = FUNC(func_string); \
}, CALLBACK);
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW(...)
Definition: utils.h:61

Call a Javascript function that accepts either a string indicating the name of a callback function or a normal string

#define D3_CALLBACK_FUNCTION_2_ARGS (   FUNC,
  CALLBACK,
  ARG1 
)
Value:
EM_ASM_ARGS({ \
var arg1 = Pointer_stringify($0); \
var func_string = Pointer_stringify($1); \
emp.__new_object = FUNC(arg1, func_string); \
}, ARG1, CALLBACK);
#define CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW(...)
Definition: utils.h:61

Same as D3_CALLBACK_FUNCTION_1_ARG, but accepts an additional argument, ARG1, that goes before the callback function in the call to FUNC

#define D3_CALLBACK_METHOD_1_ARG (   FUNC,
  ARG1 
)    D3_CALLBACK_METHOD_1_ARG_IMPL(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW("d3", "emp"), FUNC, ARG1);

The same as D3_CALLBACK_METHOD_2_ARGS except for FUNCs that only accept a single argument (the string that might or might not be a function).

#define D3_CALLBACK_METHOD_1_ARG_IMPL (   MACRO,
  FUNC,
  ARG1 
)
Value:
EM_ASM_ARGS({ \
var func_string = Pointer_stringify($1); \
MACRO; \
emp.__new_object = js.objects[$0].FUNC(func_string); \
}, this->id, ARG1);
#define D3_CALLBACK_METHOD_2_ARGS (   FUNC,
  ARG1,
  ARG2 
)    D3_CALLBACK_METHOD_2_ARGS_IMPL(CONVERT_FUNCSTRING_TO_FUNCTION_IF_IN_NAMESPACE_OR_WINDOW("d3", "emp"), FUNC, ARG1, ARG2);
#define D3_CALLBACK_METHOD_2_ARGS_IMPL (   MACRO,
  FUNC,
  ARG1,
  ARG2 
)
Value:
EM_ASM_ARGS({ \
var arg1 = Pointer_stringify($1); \
var func_string = Pointer_stringify($2); \
MACRO; \
emp.__new_object = js.objects[$0].FUNC(arg1, func_string); \
}, this->id, ARG1, ARG2);
#define D3_CALLBACK_METHOD_CPP_FUNCTION_1_ARG (   FUNC,
  CPP_FUN 
)
Value:
uint32_t fun_id = emp::JSWrap(CPP_FUN, "", false); \
EM_ASM_ARGS({ \
emp.__new_object = js.objects[$0].FUNC(function(d, i, j) { \
return emp.Callback($1, d, i, j);\
}); \
}, this->id, fun_id); \
emp::JSDelete(fun_id);
If we are in emscripten, make sure to include the header.
Definition: array.h:37
#define D3_CALLBACK_METHOD_CPP_FUNCTION_2_ARGS (   FUNC,
  ARG1,
  CPP_FUN 
)
Value:
uint32_t fun_id = emp::JSWrap(CPP_FUN, "", false); \
EM_ASM_ARGS({ \
emp.__new_object = js.objects[$0].FUNC(Pointer_stringify($1), \
function(d, i, j) { \
return emp.Callback($2, d, i, j); \
}); \
}, this->id, ARG1, fun_id); \
emp::JSDelete(fun_id);
If we are in emscripten, make sure to include the header.
Definition: array.h:37
#define IS_JS_FUNCTION (   FN)    (typeof FN === "function")

A more descriptive wrapper for the check to see if something is a function in Javascript.

Function Documentation

void StoreNewObject ( int  id)