📄 ncbidll.hpp
字号:
/// /// Called from constructor. /// @param path /// Path to DLL. /// @param name /// Name of DLL. /// @param when_to_load /// Choice to load now or later using Load(). /// @param auto_load /// Choice to unload DLL in destructor. /// @param treat_as /// Choice to transform the DLL base name. /// @sa /// Eload, EAutoUnload, EBasename definition. void x_Init(const string& path, const string& name, ELoad when_to_load, EAutoUnload auto_unload, EBasename treate_as);protected: /// Private copy constructor to prohibit copy. CDll(const CDll&); /// Private assignment operator to prohibit assignment. CDll& operator= (const CDll&);private: string m_Name; ///< DLL name SDllHandle* m_Handle; ///< DLL handle bool m_AutoUnload; ///< Whether to unload DLL in the destructor};/////////////////////////////////////////////////////////////////////////////////// Class for entry point resolution when there are several DLL candidates.////// If Dll resolver finds DLL with the specified entry point it is/// stored in the internal list (provided by GetResolvedEntries method)./// All DLL libraries are unloaded upon resolver's destruction///class CDllResolver{public: /// DLL entry point name -> function pair struct SNamedEntryPoint { string name; ///< Entry point name CDll::TEntryPoint entry_point; ///< DLL entry point SNamedEntryPoint(const string& x_name, CDll::TEntryPoint x_entry_point) : name(x_name) { entry_point.data = x_entry_point.data; } }; /// DLL resolution descriptor. struct SResolvedEntry { CDll* dll; ///< Loaded DLL instance vector<SNamedEntryPoint> entry_points; ///< list of DLL entry points SResolvedEntry(CDll* dll_ptr = 0) : dll(dll_ptr) {} }; /// Container, keeps list of all resolved entry points. typedef vector<SResolvedEntry> TEntries; /// Constructor. /// /// @param entry_point_name /// Name of the DLL entry point. NCBI_XNCBI_EXPORT CDllResolver(const string& entry_point_name); /// Constructor. /// /// @param entry_point_names /// List of alternative DLL entry points. NCBI_XNCBI_EXPORT CDllResolver(const vector<string>& entry_point_names); NCBI_XNCBI_EXPORT ~CDllResolver(); /// Try to load DLL from the specified file and resolve the entry point. /// /// If DLL resolution successfull loaded entry point is registered in the /// internal list of resolved entries. /// /// @param file_name /// Name of the DLL file. Can be full name with path of the base name. /// @return /// TRUE if DLL is succesfully loaded and entry point resolved. /// @sa /// GetResolvedEntries NCBI_XNCBI_EXPORT bool TryCandidate(const string& file_name); /// Try to resolve file candidates. /// /// @param candidates /// Container with file names to try. /// @sa /// GetResolvedEntries template<class TClass> void Try(const TClass& candidates) { typename TClass::const_iterator it = candidates.begin(); typename TClass::const_iterator it_end = candidates.end(); for (; it != it_end; ++it) { TryCandidate(*it); } } /// Try to resolve all files matching the specified masks in the /// specified directories. /// /// @param paths /// Container with directory names. /// @param masks /// Container with file candidate masks. /// @sa /// GetResolvedEntries template<class TClass1, class TClass2> void FindCandidates(const TClass1& paths, const TClass2& masks) { vector<string> candidates; FindFiles(candidates, paths.begin(), paths.end(), masks.begin(), masks.end()); Try(candidates); } /// Get all resolved entry points. NCBI_XNCBI_EXPORT const TEntries& GetResolvedEntries() const { return m_ResolvedEntries; } /// Get all resolved entry points. NCBI_XNCBI_EXPORT TEntries& GetResolvedEntries() { return m_ResolvedEntries; } /// Unload all resolved DLLs. NCBI_XNCBI_EXPORT void Unload();private: CDllResolver(const CDllResolver&); CDllResolver& operator=(const CDllResolver&);protected: vector<string> m_EntryPoinNames; ///< Candidate entry points TEntries m_ResolvedEntries;};/* @} */END_NCBI_SCOPE/* * =========================================================================== * $Log: ncbidll.hpp,v $ * Revision 1000.3 2003/12/02 20:27:57 gouriano * PRODUCTION: UPGRADED [ORIGINAL] Dev-tree R1.21 * * Revision 1.21 2003/12/01 16:39:00 kuznets * CDllResolver changed to try all entry points * (prev. version stoped on first successfull). * * Revision 1.20 2003/11/19 16:49:26 ivanov * Specify NCBI_XNCBI_EXPORT for each method in the CDll and CDllResolver. * In the MSVC, templates cannot be used with functions declared with * __declspec (dllimport) or __declspec (dllexport). * * Revision 1.19 2003/11/19 15:42:01 kuznets * Using new entry point structure (union) in CDllResolver * * Revision 1.18 2003/11/19 13:50:28 ivanov * GetEntryPoint() revamp: added GetEntryPoin_[Func|Data]() * * Revision 1.17 2003/11/12 17:40:36 kuznets * + CDllResolver::Unload() * * Revision 1.16 2003/11/10 15:28:24 kuznets * Fixed misprint * * Revision 1.15 2003/11/10 15:04:35 kuznets * CDllResolver changed to inspect DLL candidate for several alternative * entry points * * Revision 1.14 2003/11/07 17:11:53 kuznets * Minor cleanup. * * Revision 1.13 2003/11/06 13:22:36 kuznets * Fixed minor compilation bug * * Revision 1.12 2003/11/06 12:59:15 kuznets * Added new class CDllResolver * (searches for DLLs with the specified entry point) * * Revision 1.11 2003/09/11 16:17:33 ivanov * Fixed lines wrapped at 79th column * * Revision 1.10 2003/07/28 19:07:04 siyan * Documentation changes. * * Revision 1.9 2003/03/31 15:44:33 siyan * Added doxygen support * * Revision 1.8 2002/12/18 22:53:21 dicuccio * Added export specifier for building DLLs in windows. Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.7 2002/10/29 15:59:06 ivanov * Prohibited copy constructor and assignment operator * * Revision 1.6 2002/07/15 18:17:51 gouriano * renamed CNcbiException and its descendents * * Revision 1.5 2002/07/11 14:17:54 gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.4 2002/04/11 20:39:17 ivanov * CVS log moved to end of the file * * Revision 1.3 2002/01/20 07:18:10 vakatov * CDll::GetEntryPoint() -- fool-proof cast of void ptr to func ptr * * Revision 1.2 2002/01/16 18:48:13 ivanov * Added new constructor and related "basename" rules for DLL names. * Polished source code. * * Revision 1.1 2002/01/15 19:06:07 ivanov * Initial revision * * =========================================================================== */#endif /* CORELIB___NCBIDLL__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -