SeExpr
ExprFunc.h
Go to the documentation of this file.
1 /*
2  Copyright Disney Enterprises, Inc. All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License
6  and the following modification to it: Section 6 Trademarks.
7  deleted and replaced with:
8 
9  6. Trademarks. This License does not grant permission to use the
10  trade names, trademarks, service marks, or product names of the
11  Licensor and its affiliates, except as required for reproducing
12  the content of the NOTICE file.
13 
14  You may obtain a copy of the License at
15  http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #ifndef ExprFunc_h
18 #define ExprFunc_h
19 
20 #include "Vec.h"
21 #include <vector>
22 
23 #include "ExprType.h"
24 #include "ExprEnv.h"
25 #include "ExprFuncX.h"
26 #include "ExprFuncStandard.h"
27 
28 namespace SeExpr2 {
29 
31 
44 class ExprFunc {
45  static void initInternal(); // call to define built-in funcs and load standard plugins
46  public:
48 
50  static void init();
52  static void cleanup();
54  static void loadPlugins(const char* path);
56  static void loadPlugin(const char* path);
57 
58  /* A pointer to the define func is passed to the init method of
59  expression plugins. This should be called instead of calling
60  the static method directly so that the plugin will work if the
61  expression library is statically linked. */
62  static void define(const char* name, ExprFunc f, const char* docString);
63  static void define(const char* name, ExprFunc f);
64  typedef void (*Define)(const char* name, ExprFunc f);
65  typedef void (*Define3)(const char* name, ExprFunc f, const char* docString);
66 
68  static const ExprFunc* lookup(const std::string& name);
69 
71  static void getFunctionNames(std::vector<std::string>& names);
72 
74  static std::string getDocString(const char* functionName);
75 
77  static size_t sizeInBytes();
78 
80  static Statistics statistics();
81 
82  // bool isScalar() const { return _scalar; };
83 
84  ExprFunc() : _func(0), _minargs(0), _maxargs(0) {};
85 
87  ExprFunc(ExprFuncX& f, int min = 1, int max = 1) : _func(&f), _minargs(min), _maxargs(max) {};
88 
90  : _standardFunc(ExprFuncStandard::FUNC0, (void*)f), _func(0), _minargs(0), _maxargs(0) {}
92  : _standardFunc(ExprFuncStandard::FUNC1, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
94  : _standardFunc(ExprFuncStandard::FUNC2, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
96  : _standardFunc(ExprFuncStandard::FUNC3, (void*)f), _func(0), _minargs(3), _maxargs(3) {}
98  : _standardFunc(ExprFuncStandard::FUNC4, (void*)f), _func(0), _minargs(4), _maxargs(4) {}
100  : _standardFunc(ExprFuncStandard::FUNC5, (void*)f), _func(0), _minargs(5), _maxargs(5) {}
102  : _standardFunc(ExprFuncStandard::FUNC6, (void*)f), _func(0), _minargs(6), _maxargs(6) {}
104  : _standardFunc(ExprFuncStandard::FUNCN, (void*)f), _func(0), _minargs(minArgs), _maxargs(maxArgs) {}
106  : _standardFunc(ExprFuncStandard::FUNC1V, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
108  : _standardFunc(ExprFuncStandard::FUNC2V, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
110  : _standardFunc(ExprFuncStandard::FUNCNV, (void*)f), _func(0), _minargs(minArgs), _maxargs(maxArgs) {}
112  : _standardFunc(ExprFuncStandard::FUNC1VV, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
114  : _standardFunc(ExprFuncStandard::FUNC2VV, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
116  : _standardFunc(ExprFuncStandard::FUNC1VV, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
118  : _standardFunc(ExprFuncStandard::FUNCNVV, (void*)f), _func(0), _minargs(minArgs), _maxargs(maxArgs) {}
119 
121  int minArgs() const { return _minargs; }
123  int maxArgs() const { return _maxargs; }
125  const ExprFuncX* funcx() const { return _func ? _func : &_standardFunc; }
126 
127  private:
130  int _minargs;
131  int _maxargs;
132 };
133 }
134 
135 #endif
static std::string getDocString(const char *functionName)
Get doc string for a specific function.
Definition: ExprFunc.cpp:174
void(* Define3)(const char *name, ExprFunc f, const char *docString)
Definition: ExprFunc.h:65
ExprFunc(ExprFuncStandard::Funcn *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:103
ExprFuncX * _func
Definition: ExprFunc.h:129
ExprFunc(ExprFuncStandard::Func1v *f)
Definition: ExprFunc.h:105
double Func2v(const Vec3d &, const Vec3d &)
double Func3(double, double, double)
static void getFunctionNames(std::vector< std::string > &names)
Get a list of registered builtin and DSO generated functions.
Definition: ExprFunc.cpp:167
const ExprFuncX * funcx() const
return pointer to the funcx
Definition: ExprFunc.h:125
static size_t sizeInBytes()
Get the total size estimate of all plugins.
Definition: ExprFunc.cpp:182
int maxArgs() const
return the maximum number of acceptable arguments
Definition: ExprFunc.h:123
double Func1v(const Vec3d &)
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
ExprFunc(ExprFuncStandard::Func6 *f)
Definition: ExprFunc.h:101
double Funcnv(int n, const Vec3d *params)
Vec3d Funcnvv(int n, const Vec3d *params)
static Statistics statistics()
Dump statistics.
Definition: ExprFunc.cpp:188
ExprFunc(ExprFuncStandard::Funcnvv *f)
Definition: ExprFunc.h:115
Vec3d Func1vv(const Vec3d &)
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
Definition: varblocks.txt:35
static void define(const char *name, ExprFunc f, const char *docString)
Definition: ExprFunc.cpp:160
double Func6(double, double, double, double, double, double)
Vec3d Func2vv(const Vec3d &, const Vec3d &)
static void loadPlugins(const char *path)
load all plugins in a given path
Definition: ExprFunc.cpp:208
ExprFunc(ExprFuncStandard::Func3 *f)
Definition: ExprFunc.h:95
ExprFunc(ExprFuncStandard::Func2 *f)
Definition: ExprFunc.h:93
double max(double x, double y)
Definition: ExprBuiltins.h:42
ExprFunc(ExprFuncStandard::Func4 *f)
Definition: ExprFunc.h:97
static void loadPlugin(const char *path)
load a given plugin
Definition: ExprFunc.cpp:243
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
Definition: ExprFunc.cpp:121
ExprFunc(ExprFuncX &f, int min=1, int max=1)
User defined function with custom argument parsing.
Definition: ExprFunc.h:87
double min(double x, double y)
Definition: ExprBuiltins.h:43
double Funcn(int n, double *params)
static void initInternal()
Definition: ExprFunc.cpp:141
void(* Define)(const char *name, ExprFunc f)
Definition: ExprFunc.h:64
double Func5(double, double, double, double, double)
ExprFunc(ExprFuncStandard::Func1vv *f)
Definition: ExprFunc.h:111
ExprFunc(ExprFuncStandard::Func1 *f)
Definition: ExprFunc.h:91
ExprFunc(ExprFuncStandard::Func0 *f)
Definition: ExprFunc.h:89
ExprFunc(ExprFuncStandard::Func2v *f)
Definition: ExprFunc.h:107
ExprFunc(ExprFuncStandard::Func2vv *f)
Definition: ExprFunc.h:113
ExprFunc(ExprFuncStandard::Funcnvv *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:117
double Func4(double, double, double, double)
Extension function spec, used for complicated argument custom functions.
Definition: ExprFuncX.h:35
static void cleanup()
cleanup all functions
Definition: ExprFunc.cpp:115
std::map< std::string, double > Statistics
Definition: ExprFuncX.h:27
ExprFunc(ExprFuncStandard::Funcnv *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:109
static void init()
call to define built-in funcs and load standard plugins
Definition: ExprFunc.cpp:110
int minArgs() const
return the minimum number of acceptable arguments
Definition: ExprFunc.h:121
ExprFunc(ExprFuncStandard::Func5 *f)
Definition: ExprFunc.h:99
ExprFuncStandard _standardFunc
Definition: ExprFunc.h:128
double Func2(double, double)