From: stephan b. <sg...@us...> - 2004-12-28 15:11:29
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25183 Added Files: SharedLib.common.cpp Log Message: egg --- NEW FILE: SharedLib.common.cpp --- #include "pclasses/Phoenix.h" #include "pclasses/System/SharedLib.h" #include <list> #ifndef CERR #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " #endif namespace P { namespace System { void* SharedLib::operator[](const std::string& symbol) throw(RuntimeError) { return operator[](symbol.empty() ? 0 : symbol.c_str()); // ^^^ the 0 is to force operator[const char*] to throw a // runtime error. We don't throw it here because we want to // inherit the platform-specific op[char*]'s throw behaviour. } /** An internal helper type to clean up a list of SharedLib objects. ContainterT must be compatible with list<SharedLib *>. */ template <typename ContainterT> struct SharedLibCleaner { typedef ContainterT list_t; SharedLibCleaner() { } /** Calls delete() on each entry in container(). */ ~SharedLibCleaner() { typename list_t::iterator it = m_list.begin(); while( m_list.end() != it ) { delete( (*it) ); ++it; } m_list.clear(); } /** Returns this object's container. */ list_t & container() { return this->m_list; } private: list_t m_list; }; /** Internal marker type. */ struct opened_libs_context {}; /** Internal SharedLib container type. */ typedef std::list<SharedLib *> OpenedLibsList; // internal list of libs opened via openSharedLib() OpenedLibsList & opened_shared_libs() { return ::P::Phoenix< SharedLibCleaner<OpenedLibsList>, opened_libs_context> ::instance().container(); } SharedLib * openSharedLib( const std::string & path ) throw(RuntimeError) { //CERR << "openSharedLib("<<path<<")\n"; SharedLib * sh = new SharedLib( path ); //CERR << "OPENED openSharedLib("<<path<<")\n"; // ^^^^ if this throws, the mem is deallocated, right? opened_shared_libs().push_back( sh ); return sh; } } // !namespace System } // !namespace P |