From: <sv...@ww...> - 2004-06-21 07:23:38
|
Author: mkrose Date: 2004-06-21 00:23:32 -0700 (Mon, 21 Jun 2004) New Revision: 1061 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/InterfaceRegistry.h trunk/CSP/SimData/Source/InterfaceRegistry.cpp Log: Slight refactoring and cleanup of InterfaceRegistry. Subclassed singleton<InterfaceRegistry>, converted some pointer fields to member variables, tweaked the init and cleanup. Hopefully this won't break the static initializers used to register interfaces. Works fine under linux but needs to be tested under windows. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1061 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-21 07:16:54 UTC (rev 1060) +++ trunk/CSP/SimData/CHANGES.current 2004-06-21 07:23:32 UTC (rev 1061) @@ -28,6 +28,12 @@ * Minor fixups to Trace.h (needs more work, and really needs a win32 implementation). + * Slight refactoring and cleanup of InterfaceRegistry. Subclassed + singleton<InterfaceRegistry>, converted some pointer fields to + member variables, tweaked the init and cleanup. Hopefully this + won't break the static initializers used to register interfaces. + Works fine under linux but needs to be tested under windows. + 2004-06-16: onsight * Doxygen cleanups. Modified: trunk/CSP/SimData/Include/SimData/InterfaceRegistry.h =================================================================== --- trunk/CSP/SimData/Include/SimData/InterfaceRegistry.h 2004-06-21 07:16:54 UTC (rev 1060) +++ trunk/CSP/SimData/Include/SimData/InterfaceRegistry.h 2004-06-21 07:23:32 UTC (rev 1061) @@ -347,8 +347,9 @@ * * @author Mark Rose <mr...@st...> */ -class InterfaceRegistry { +class InterfaceRegistry: public Singleton<InterfaceRegistry> { +friend class Singleton<InterfaceRegistry>; friend class InterfaceProxy; public: @@ -389,18 +390,12 @@ /** Get the interface registry singleton. */ static InterfaceRegistry &getInterfaceRegistry() { - return Singleton<InterfaceRegistry>::getInstance(); + return getInstance(); } -#if defined(_MSC_VER ) && (_MSC_VER <= 1200) - virtual ~InterfaceRegistry(); -#endif - private: -#if !defined(_MSC_VER ) || (_MSC_VER > 1200) virtual ~InterfaceRegistry(); -#endif /** Add an interface to the registry. * @@ -409,17 +404,15 @@ */ void addInterface(const char *name, hasht id, InterfaceProxy *proxy) throw(InterfaceError); - friend class Singleton<InterfaceRegistry>; + //friend class Singleton<InterfaceRegistry>; InterfaceRegistry(); - void __cleanup(); - typedef HASH_MAPS<const char*, InterfaceProxy*, HASH<const char*>, eqstr>::Type proxy_map; typedef HASHT_MAP<InterfaceProxy*>::Type proxy_id_map; - proxy_map *__map; - proxy_id_map *__id_map; - interface_list *__list; + proxy_map __map; + proxy_id_map __id_map; + interface_list __list; }; Modified: trunk/CSP/SimData/Source/InterfaceRegistry.cpp =================================================================== --- trunk/CSP/SimData/Source/InterfaceRegistry.cpp 2004-06-21 07:16:54 UTC (rev 1060) +++ trunk/CSP/SimData/Source/InterfaceRegistry.cpp 2004-06-21 07:23:32 UTC (rev 1061) @@ -127,75 +127,54 @@ // InterfaceRegistry -InterfaceRegistry::InterfaceRegistry(): __map(0), __id_map(0), __list(0) { +InterfaceRegistry::InterfaceRegistry() { + SIMDATA_LOG(LOG_REGISTRY, LOG_DEBUG, "Initializing interface registry."); } InterfaceRegistry::~InterfaceRegistry() { - __cleanup(); -} - -void InterfaceRegistry::__cleanup() { SIMDATA_LOG(LOG_REGISTRY, LOG_DEBUG, "Destroying the interface registry."); - if (__map) delete __map; __map = 0; - if (__id_map) delete __id_map; __id_map = 0; - if (__list) delete __list; __list = 0; } InterfaceProxy *InterfaceRegistry::getInterface(const char *name) { - if (!__map) return 0; - proxy_map::iterator i = __map->find(name); - if (i == __map->end()) return 0; + proxy_map::iterator i = __map.find(name); + if (i == __map.end()) return 0; return i->second; } InterfaceProxy *InterfaceRegistry::getInterface(hasht key) { - if (!__id_map) return 0; - proxy_id_map::iterator i = __id_map->find(key); - if (i == __id_map->end()) return 0; + proxy_id_map::iterator i = __id_map.find(key); + if (i == __id_map.end()) return 0; return i->second; } bool InterfaceRegistry::hasInterface(const char *name) { - if (!__map) return false; - return (__map->find(name) != __map->end()); + return (__map.find(name) != __map.end()); } bool InterfaceRegistry::hasInterface(hasht key) { - if (!__id_map) return false; - return (__id_map->find(key) != __id_map->end()); + return (__id_map.find(key) != __id_map.end()); } std::vector<std::string> InterfaceRegistry::getInterfaceNames() const { std::vector<std::string> names; - if (__list) { - interface_list::const_iterator i; - for (i = __list->begin(); i != __list->end(); i++) { - names.push_back((*i)->getClassName()); - } + interface_list::const_iterator i; + for (i = __list.begin(); i != __list.end(); i++) { + names.push_back((*i)->getClassName()); } return names; } std::vector<InterfaceProxy *> InterfaceRegistry::getInterfaces() const { - if (__list) return *__list; - return interface_list(); + return __list; } void InterfaceRegistry::addInterface(const char *name, hasht id, InterfaceProxy *proxy) throw(InterfaceError) { - if (__map == 0) { - //cout << "Initializing interface registry." << endl; - SIMDATA_LOG(LOG_REGISTRY, LOG_DEBUG, "Initializing interface registry."); - __map = new proxy_map; - __id_map = new proxy_id_map; - __list = new interface_list; - } if (hasInterface(name)) { throw InterfaceError("interface \"" + std::string(name) + "\" multiply defined"); } - (*__map)[name] = proxy; - (*__id_map)[id] = proxy; - __list->push_back(proxy); - //cout << "Registering interface<" << name << "> [" << id << "]" << endl; + __map[name] = proxy; + __id_map[id] = proxy; + __list.push_back(proxy); SIMDATA_LOG(LOG_REGISTRY, LOG_DEBUG, "Registering interface<" << name << "> [" << id << "]"); } |