1 #ifndef SimTK_SimTKCOMMON_PLUGIN_H_     2 #define SimTK_SimTKCOMMON_PLUGIN_H_    98     explicit Plugin(
const std::string& defaultPathname=
"");
   114     bool load(
const std::string& name=
"");
   127         return m_loadedPathname; 
   140         m_searchPath.clear();
   141         for (
unsigned i=0; i < pathIn.size(); ++i) 
   142             addSearchDirectory(pathIn[i]);
   153             m_searchPath.push_back(absDir);
   163             m_searchPath.insert(m_searchPath.begin(), absDir);
   169     static void* loadPluginByFileName(
const std::string& name, std::string& errMsg);
   174     static void* loadDebugOrReleasePlugin(
const std::string& base, 
const std::string& extension,
   175                                           std::string& loadedFileName, std::string& errMsg);
   178     static void* getSymbolAddress(
void* handle, 
const std::string& name, std::string& errMsg);
   181     static void unloadPlugin(
void* handle);
   224     static bool deconstructLibraryName( 
const std::string& name,
   225                                         bool&        isAbsolutePath,
   226                                         std::string& directory,
   227                                         std::string& libPrefix,
   228                                         std::string& baseName,
   229                                         std::string& debugSuffix,
   230                                         std::string& extension);
   235     static std::string getDynamicLibPrefix();
   240     static std::string getDynamicLibExtension();
   246     static std::string getDynamicLibDebugSuffix();
   259 #define SimTK_PLUGIN_XXX_MAKE_HOLDER(FuncName)          \   260     struct FuncName##__Holder__ {                       \   261         FuncName##__Holder__() : fp(0) {}               \   262         bool loadSym(void* h, std::string& msg) const { \   263             if(!fp) fp =(FuncName##__Type__)            \   264                 Plugin::getSymbolAddress(h, #FuncName, msg);   \   267         mutable FuncName##__Type__ fp;                  \   269 #define SimTK_PLUGIN_XXX_MAKE_BODY(FuncName)            \   270     if (!FuncName##__Ref__.loadSym(m_handle,m_lastMessage)) \   271     throw std::runtime_error                            \   272       ("Plugin function " #FuncName " not found: " + m_lastMessage); \   273     return FuncName##__Ref__.fp   274 #define SimTK_PLUGIN_XXX_MAKE_SYMTEST(Symbol)           \   275     bool has_##Symbol() const {                          \   276         return Symbol##__Ref__.loadSym(m_handle,m_lastMessage);   \   279 #define SimTK_PLUGIN_DEFINE_SYMBOL(Type, SymName)   \   280     typedef Type SymName##__Type__;                 \   281     SimTK_PLUGIN_XXX_MAKE_HOLDER(SymName);          \   282     const Type& SymName() const {                   \   283         if (!SymName##__Ref__.loadSym(m_handle,m_lastMessage))  \   284         throw std::runtime_error                                \   285           ("Plugin symbol " #SymName " not found: " + m_lastMessage); \   286         return *(SymName##__Ref__.fp);              \   289 #define SimTK_PLUGIN_DEFINE_FUNCTION(RetType, FuncName) \   290     typedef RetType (*FuncName##__Type__)();            \   291     SimTK_PLUGIN_XXX_MAKE_HOLDER(FuncName);             \   292     RetType FuncName() const {                          \   293         SimTK_PLUGIN_XXX_MAKE_BODY(FuncName)();         \   295     SimTK_PLUGIN_XXX_MAKE_SYMTEST(FuncName)   297 #define SimTK_PLUGIN_DEFINE_FUNCTION1(RetType, FuncName, Arg1) \   298     typedef RetType (*FuncName##__Type__)(Arg1);        \   299     SimTK_PLUGIN_XXX_MAKE_HOLDER(FuncName);             \   300     RetType FuncName(Arg1 a1) const {                   \   301         SimTK_PLUGIN_XXX_MAKE_BODY(FuncName)(a1);       \   303     SimTK_PLUGIN_XXX_MAKE_SYMTEST(FuncName)   305 #define SimTK_PLUGIN_DEFINE_FUNCTION2(RetType, FuncName, Arg1, Arg2) \   306     typedef RetType (*FuncName##__Type__)(Arg1,Arg2);   \   307     SimTK_PLUGIN_XXX_MAKE_HOLDER(FuncName);             \   308     RetType FuncName(Arg1 a1, Arg2 a2) const {          \   309         SimTK_PLUGIN_XXX_MAKE_BODY(FuncName)(a1,a2);    \   311     SimTK_PLUGIN_XXX_MAKE_SYMTEST(FuncName)   316 #endif // SimTK_SimTKCOMMON_PLUGIN_H_ #define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:218
 
Declaration of the SimTK::Pathname class providing platform-independent manipulation of file pathname...
 
void addSearchDirectory(const std::string &directory)
Add a directory to the end of the search path for this kind of plugin. 
Definition: Plugin.h:150
 
static std::string getAbsoluteDirectoryPathname(const std::string &dirPathname)
This is the same as getAbsolutePathname() except that the final segment is interpreted as a directory...
Definition: Pathname.h:163
 
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
 
const Array_< std::string > & getSearchPath() const 
Definition: Plugin.h:145
 
This file defines the Array_<T,X> class and related support classes including base classes ArrayViewC...
 
std::string getLastErrorMessage() const 
If anything goes wrong the last error message is stored so you can retrieve it with this method...
Definition: Plugin.h:132
 
void * m_handle
Definition: Plugin.h:253
 
const std::string & getLoadedPathname() const 
Definition: Plugin.h:126
 
std::string m_loadedPathname
Definition: Plugin.h:252
 
This is the base class for representing a runtime-linked dynamic library, also known as a "plugin"...
Definition: Plugin.h:96
 
std::string m_defaultName
Definition: Plugin.h:249
 
Mandatory first inclusion for any Simbody source or header file. 
 
std::string m_lastMessage
Definition: Plugin.h:254
 
bool isLoaded() const 
Is there currently a DLL associated with this Plugin object? If so you can call getLoadedPathname() t...
Definition: Plugin.h:124
 
void setSearchPath(const Array_< std::string > &pathIn)
Provide a list of directories in the order you want them searched to find a plugin that was provided ...
Definition: Plugin.h:139
 
void prependSearchDirectory(const std::string &directory)
Put a directory on the front of the search path for this kind of plugin. 
Definition: Plugin.h:160
 
Array_< std::string > m_searchPath
Definition: Plugin.h:250