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;
123 for(
size_t i=0; i<
dynlib.size(); i++){
141 Functions->define(name,
f);
147 Functions->define(name,
f, docString);
155 if (Functions)
return;
156 Functions =
new FuncTable;
158 const char* path = getenv(
"SE_EXPR_PLUGINS");
179 Functions->getFunctionNames(names);
186 std::string ret = Functions->getDocString(functionName);
194 return Functions->sizeInBytes();
200 return Functions->statistics();
205 #if defined(__APPLE__) && !defined(__MAC_10_9)
211 const char* name = dir->d_name;
213 return !strncmp(name,
"SeExpr", 6) && !strcmp(name + strlen(name) - 3,
".so");
222 char* pathdup = strdup(path);
224 char* entry = strtok_r(pathdup,
":", &state);
227 if ((!strcmp(entry + strlen(entry) - 3,
".so")))
231 struct dirent** matches = 0;
233 for (
int i = 0; i < numMatches; i++) {
234 std::string fullpath = entry;
236 fullpath += matches[i]->d_name;
242 std::cerr <<
"No plugins found matching " << path <<
"/SeExpr*.so" << std::endl;
246 entry = strtok_r(0,
":", &state);
254 std::cerr <<
"SeExpr: warning Plugins are not supported on windows currently" << std::endl;
256 void* handle = dlopen(path, RTLD_LAZY);
258 std::cerr <<
"Error reading expression plugin: " << path << std::endl;
259 const char* err = dlerror();
260 if (err) std::cerr << err << std::endl;
265 initfn_v3 init_v3 = (initfn_v3)dlsym(handle,
"SeExpr2PluginInit");
271 std::cerr <<
"Error reading expression plugin: " << path << std::endl;
272 std::cerr <<
"No function named SeExpr2PluginInit defined" << std::endl;