GeoModel - GeoModelCore
GeoGeometryPluginLoader.cxx
1 #include "GeoModelKernel/GeoGeometryPluginLoader.h"
2 #include "GeoModelKernel/GeoVGeometryPlugin.h"
3 #include <string>
4 #include <iostream>
5 #include <dlfcn.h>
6 #include <libgen.h>
7 
8 GeoGeometryPluginLoader::GeoGeometryPluginLoader () {
9 }
10 
11 GeoGeometryPluginLoader::~GeoGeometryPluginLoader () {
12 }
13 
14 
15 GeoVGeometryPlugin *GeoGeometryPluginLoader::load(const std::string & pString) const {
16  std::string bNameString=basename ((char *) pString.c_str()); // Strip off the directory
17  bNameString=bNameString.substr(3); // Strip off leading "lib"
18  bNameString=bNameString.substr(0,bNameString.find(".")); // Strip off extensions
19 
20  std::string createFunctionName = std::string("create")+bNameString;
21 
22  //
23  // Loads the library:
24  //
25  void *handle = dlopen(pString.c_str(),RTLD_NOW);
26  if (!handle) {
27  std::cerr << dlerror() << std::endl;
28  return nullptr;
29  }
30 
31  //
32  // Gets the function
33  //
34  void *f = dlsym(handle,createFunctionName.c_str());
35  if (!f) {
36  std::cerr << dlerror() << std::endl;
37  return nullptr;
38  }
39 
40  typedef void * (*CreationMethod) ();
41  CreationMethod F = (CreationMethod) f;
42 
43  //
44  //
45  //
46  GeoVGeometryPlugin * factory = (GeoVGeometryPlugin *) F();
47  return factory;
48 
49 }
Abstact Base Class for a geometry plugin. The geometry plugin builds the raw geometry.