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
89 ExprFunc(ExprFuncStandard::Func0* f)
90 : _standardFunc(ExprFuncStandard::FUNC0, (void*)f), _func(0), _minargs(0), _maxargs(0) {}
91 ExprFunc(ExprFuncStandard::Func1* f)
92 : _standardFunc(ExprFuncStandard::FUNC1, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
93 ExprFunc(ExprFuncStandard::Func2* f)
94 : _standardFunc(ExprFuncStandard::FUNC2, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
95 ExprFunc(ExprFuncStandard::Func3* f)
96 : _standardFunc(ExprFuncStandard::FUNC3, (void*)f), _func(0), _minargs(3), _maxargs(3) {}
97 ExprFunc(ExprFuncStandard::Func4* f)
98 : _standardFunc(ExprFuncStandard::FUNC4, (void*)f), _func(0), _minargs(4), _maxargs(4) {}
99 ExprFunc(ExprFuncStandard::Func5* f)
100 : _standardFunc(ExprFuncStandard::FUNC5, (void*)f), _func(0), _minargs(5), _maxargs(5) {}
101 ExprFunc(ExprFuncStandard::Func6* f)
102 : _standardFunc(ExprFuncStandard::FUNC6, (void*)f), _func(0), _minargs(6), _maxargs(6) {}
103 ExprFunc(ExprFuncStandard::Funcn* f, int minArgs, int maxArgs)
104 : _standardFunc(ExprFuncStandard::FUNCN, (void*)f), _func(0), _minargs(minArgs), _maxargs(maxArgs) {}
105 ExprFunc(ExprFuncStandard::Func1v* f)
106 : _standardFunc(ExprFuncStandard::FUNC1V, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
107 ExprFunc(ExprFuncStandard::Func2v* f)
108 : _standardFunc(ExprFuncStandard::FUNC2V, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
109 ExprFunc(ExprFuncStandard::Funcnv* f, int minArgs, int maxArgs)
110 : _standardFunc(ExprFuncStandard::FUNCNV, (void*)f), _func(0), _minargs(minArgs), _maxargs(maxArgs) {}
111 ExprFunc(ExprFuncStandard::Func1vv* f)
112 : _standardFunc(ExprFuncStandard::FUNC1VV, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
113 ExprFunc(ExprFuncStandard::Func2vv* f)
114 : _standardFunc(ExprFuncStandard::FUNC2VV, (void*)f), _func(0), _minargs(2), _maxargs(2) {}
115 ExprFunc(ExprFuncStandard::Funcnvv* f)
116 : _standardFunc(ExprFuncStandard::FUNC1VV, (void*)f), _func(0), _minargs(1), _maxargs(1) {}
117 ExprFunc(ExprFuncStandard::Funcnvv* f, int minArgs, int maxArgs)
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:
128 ExprFuncStandard _standardFunc;
129 ExprFuncX* _func;
130 int _minargs;
131 int _maxargs;
132 static std::vector<void*> dynlib;
133 };
134 }
135
136 #endif
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncX &f, int min=1, int max=1)
User defined function with custom argument parsing.
Definition: ExprFunc.h:87
f
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
SeExpr2::ExprFuncStandard::Func2
double Func2(double, double)
Definition: ExprFuncStandard.h:52
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func2 *f)
Definition: ExprFunc.h:93
SeExpr2::ExprFuncStandard::Func0
double Func0()
Definition: ExprFuncStandard.h:50
SeExpr2::ExprFunc::_func
ExprFuncX * _func
Definition: ExprFunc.h:129
SeExpr2::ExprFunc::cleanup
static void cleanup()
cleanup all functions
Definition: ExprFunc.cpp:117
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func4 *f)
Definition: ExprFunc.h:97
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func1 *f)
Definition: ExprFunc.h:91
SeExpr2::ExprFunc::init
static void init()
call to define built-in funcs and load standard plugins
Definition: ExprFunc.cpp:112
ExprFuncStandard.h
SeExpr2::ExprFunc::Define3
void(* Define3)(const char *name, ExprFunc f, const char *docString)
Definition: ExprFunc.h:65
SeExpr2::ExprFunc::getFunctionNames
static void getFunctionNames(std::vector< std::string > &names)
Get a list of registered builtin and DSO generated functions.
Definition: ExprFunc.cpp:176
SeExpr2::ExprFunc::sizeInBytes
static size_t sizeInBytes()
Get the total size estimate of all plugins.
Definition: ExprFunc.cpp:191
SeExpr2::ExprFuncX
Extension function spec, used for complicated argument custom functions.
Definition: ExprFuncX.h:35
SeExpr2::ExprFunc::_minargs
int _minargs
Definition: ExprFunc.h:130
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func0 *f)
Definition: ExprFunc.h:89
SeExpr2::ExprFunc
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func1v *f)
Definition: ExprFunc.h:105
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Funcnv *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:109
SeExpr2::ExprFuncStandard::Func2v
double Func2v(const Vec3d &, const Vec3d &)
Definition: ExprFuncStandard.h:58
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func2v *f)
Definition: ExprFunc.h:107
SeExpr2::ExprFunc::funcx
const ExprFuncX * funcx() const
return pointer to the funcx
Definition: ExprFunc.h:125
SeExpr2::ExprFuncStandard::Func3
double Func3(double, double, double)
Definition: ExprFuncStandard.h:53
SeExpr2::ExprFuncStandard::Funcnvv
Vec3d Funcnvv(int n, const Vec3d *params)
Definition: ExprFuncStandard.h:63
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func2vv *f)
Definition: ExprFunc.h:113
SeExpr2::ExprFunc::maxArgs
int maxArgs() const
return the maximum number of acceptable arguments
Definition: ExprFunc.h:123
SeExpr2
Definition: Context.h:22
SeExpr2::ExprFunc::statistics
static Statistics statistics()
Dump statistics.
Definition: ExprFunc.cpp:197
SeExpr2::ExprFuncStandard::Funcn
double Funcn(int n, double *params)
Definition: ExprFuncStandard.h:61
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Funcnvv *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:117
SeExpr2::ExprFuncStandard::Func1v
double Func1v(const Vec3d &)
Definition: ExprFuncStandard.h:57
ExprType.h
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func5 *f)
Definition: ExprFunc.h:99
SeExpr2::ExprFuncStandard::Func4
double Func4(double, double, double, double)
Definition: ExprFuncStandard.h:54
SeExpr2::ExprFuncStandard::Func1vv
Vec3d Func1vv(const Vec3d &)
Definition: ExprFuncStandard.h:59
SeExpr2::ExprFunc::_maxargs
int _maxargs
Definition: ExprFunc.h:131
Vec.h
SeExpr2::ExprFunc::ExprFunc
ExprFunc()
Definition: ExprFunc.h:84
SeExpr2::ExprFunc::dynlib
static std::vector< void * > dynlib
Definition: ExprFunc.h:132
SeExpr2::min
double min(double x, double y)
Definition: ExprBuiltins.h:43
SeExpr2::ExprFunc::_standardFunc
ExprFuncStandard _standardFunc
Definition: ExprFunc.h:128
SeExpr2::ExprFuncStandard::Func6
double Func6(double, double, double, double, double, double)
Definition: ExprFuncStandard.h:56
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func6 *f)
Definition: ExprFunc.h:101
ExprFuncX.h
SeExpr2::ExprFuncStandard::Funcnv
double Funcnv(int n, const Vec3d *params)
Definition: ExprFuncStandard.h:62
SeExpr2::max
double max(double x, double y)
Definition: ExprBuiltins.h:42
ExprEnv.h
SeExpr2::ExprFunc::minArgs
int minArgs() const
return the minimum number of acceptable arguments
Definition: ExprFunc.h:121
SeExpr2::ExprFuncStandard::Func2vv
Vec3d Func2vv(const Vec3d &, const Vec3d &)
Definition: ExprFuncStandard.h:60
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Funcn *f, int minArgs, int maxArgs)
Definition: ExprFunc.h:103
SeExpr2::ExprFunc::loadPlugins
static void loadPlugins(const char *path)
load all plugins in a given path
Definition: ExprFunc.cpp:217
SeExpr2::ExprFuncStandard
Definition: ExprFuncStandard.h:25
SeExpr2::ExprFunc::lookup
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
Definition: ExprFunc.cpp:130
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Funcnvv *f)
Definition: ExprFunc.h:115
SeExpr2::ExprFunc::Define
void(* Define)(const char *name, ExprFunc f)
Definition: ExprFunc.h:64
SeExpr2::ExprFunc::define
static void define(const char *name, ExprFunc f, const char *docString)
Definition: ExprFunc.cpp:169
SeExpr2::ExprFunc::initInternal
static void initInternal()
Definition: ExprFunc.cpp:150
SeExpr2::ExprFunc::getDocString
static std::string getDocString(const char *functionName)
Get doc string for a specific function.
Definition: ExprFunc.cpp:183
SeExpr2::ExprFuncStandard::Func5
double Func5(double, double, double, double, double)
Definition: ExprFuncStandard.h:55
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func1vv *f)
Definition: ExprFunc.h:111
SeExpr2::ExprFunc::ExprFunc
ExprFunc(ExprFuncStandard::Func3 *f)
Definition: ExprFunc.h:95
SeExpr2::ExprFuncStandard::Func1
double Func1(double)
Definition: ExprFuncStandard.h:51
SeExpr2::Statistics
std::map< std::string, double > Statistics
Definition: ExprFuncX.h:27
SeExpr2::ExprFunc::loadPlugin
static void loadPlugin(const char *path)
load a given plugin
Definition: ExprFunc.cpp:252