39 funcmap[name] = FuncMapItem(std::string(docString), f);
41 funcmap[name] = FuncMapItem(name, f);
45 FuncMap::iterator iter;
46 if ((iter = funcmap.find(name)) != funcmap.end())
return &iter->second.second;
51 void getFunctionNames(std::vector<std::string>& names) {
52 for (FuncMap::iterator i = funcmap.begin(); i != funcmap.end(); ++i) names.push_back(i->first);
55 std::string getDocString(
const char* functionName) {
56 FuncMap::iterator i = funcmap.find(functionName);
57 if (i == funcmap.end())
60 return i->second.first;
63 size_t sizeInBytes()
const {
65 for (FuncMap::const_iterator
it = funcmap.begin();
it != funcmap.end(); ++
it) {
66 totalSize +=
it->first.size() +
sizeof(FuncMapItem);
69 totalSize += funcx->sizeInBytes();
78 for (FuncMap::const_iterator
it = funcmap.begin();
it != funcmap.end(); ++
it) {
79 totalSize +=
it->first.size() +
sizeof(FuncMapItem);
82 funcx->statistics(statisticsDump);
85 return statisticsDump;
89 typedef std::pair<std::string, SeExpr2::ExprFunc> FuncMapItem;
90 typedef std::map<std::string, FuncMapItem> FuncMap;
94 FuncTable* Functions = 0;
132 Functions->define(name, f);
138 Functions->define(name, f, docString);
146 if (Functions)
return;
147 Functions =
new FuncTable;
149 const char* path = getenv(
"SE_EXPR_PLUGINS");
170 Functions->getFunctionNames(names);
177 std::string ret = Functions->getDocString(functionName);
185 return Functions->sizeInBytes();
191 return Functions->statistics();
196 #if defined(__APPLE__) && !defined(__MAC_10_9)
202 const char* name = dir->d_name;
204 return !strncmp(name,
"SeExpr", 6) && !strcmp(name + strlen(name) - 3,
".so");
213 char* pathdup = strdup(path);
215 char* entry = strtok_r(pathdup,
":", &state);
218 if ((!strcmp(entry + strlen(entry) - 3,
".so")))
222 struct dirent** matches = 0;
224 for (
int i = 0; i < numMatches; i++) {
225 std::string fullpath = entry;
227 fullpath += matches[i]->d_name;
233 std::cerr <<
"No plugins found matching " << path <<
"/SeExpr*.so" << std::endl;
237 entry = strtok_r(0,
":", &state);
245 std::cerr <<
"SeExpr: warning Plugins are not supported on windows currently" << std::endl;
247 void* handle = dlopen(path, RTLD_LAZY);
249 std::cerr <<
"Error reading expression plugin: " << path << std::endl;
250 const char* err = dlerror();
251 if (err) std::cerr << err << std::endl;
256 initfn_v3 init_v3 = (initfn_v3)dlsym(handle,
"SeExpr2PluginInit");
261 void* init_v2 = dlsym(handle,
"SeExprPluginInitV2");
262 void* init_v1 = dlsym(handle,
"SeExprPluginInit");
263 if (!init_v1 && !init_v2) {
264 std::cerr <<
"Error reading expression plugin: " << path << std::endl;
265 std::cerr <<
"No functions named SeExprPluginInit and SeExprPluginInitV2 called" << std::endl;
static std::string getDocString(const char *functionName)
Get doc string for a specific function.
void(* Define3)(const char *name, ExprFunc f, const char *docString)
static SeExprInternal2::Mutex mutex
static void defineInternal3(const char *name, ExprFunc f, const char *docString)
static void getFunctionNames(std::vector< std::string > &names)
Get a list of registered builtin and DSO generated functions.
static size_t sizeInBytes()
Get the total size estimate of all plugins.
void defineBuiltins(ExprFunc::Define define, ExprFunc::Define3 define3)
Function Definition, used in parse tree and func table.
static Statistics statistics()
Dump statistics.
static void define(const char *name, ExprFunc f, const char *docString)
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)
static int MatchPluginName(const struct dirent *dir)
static void loadPlugins(const char *path)
load all plugins in a given path
static void loadPlugin(const char *path)
load a given plugin
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
static void initInternal()
static void defineInternal(const char *name, ExprFunc f)
Extension function spec, used for complicated argument custom functions.
static void cleanup()
cleanup all functions
std::map< std::string, double > Statistics
static void init()
call to define built-in funcs and load standard plugins
you may not use this file except in compliance with the License and the following modification to it