home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.4 KB | 164 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWExtMgr.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWEXTMGR_H
- #include "FWExtMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODExtension_xh
- #include "Extensn.xh"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment extensionmanager
- #endif
-
- //========================================================================================
- // class FW_CPrivExtensionMap
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivExtensionMap::FW_CPrivExtensionMap
- //----------------------------------------------------------------------------------------
-
- FW_CPrivExtensionMap::FW_CPrivExtensionMap()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivExtensionMap::~FW_CPrivExtensionMap
- //----------------------------------------------------------------------------------------
-
- FW_CPrivExtensionMap::~FW_CPrivExtensionMap()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivExtensionMap::KeysMatch
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivExtensionMap::KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const
- {
- return !ODISOStrCompare((ODISOStr) key1, (ODISOStr) key2);
- }
-
- //========================================================================================
- // class FW_CExtensionManager
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::~FW_CExtensionManager
- //----------------------------------------------------------------------------------------
-
- FW_CExtensionManager::~FW_CExtensionManager()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::FW_CExtensionManager
- //----------------------------------------------------------------------------------------
-
- FW_CExtensionManager::FW_CExtensionManager(FW_CPart* part)
- : fPart(part),
- fNameToCreateFuncMap(),
- fActiveExtensions()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::HasExtension
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CExtensionManager::HasExtension(Environment *ev, const char* const name)
- {
- return fNameToCreateFuncMap.ContainsKey((FW_PrivKeyType)name);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::RegisterExtension
- //----------------------------------------------------------------------------------------
-
- void FW_CExtensionManager::RegisterExtension(Environment *ev, const char * const name, CreateExtensionFunc func)
- {
- FW_ASSERT(!fNameToCreateFuncMap.ContainsKey((FW_PrivKeyType)name));
- fNameToCreateFuncMap.AddPair((FW_PrivKeyType)name, (FW_PrivValueType)func);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::AcquireExtension
- //----------------------------------------------------------------------------------------
-
- ODExtension* FW_CExtensionManager::AcquireExtension(Environment *ev, const char* const name)
- {
- ODExtension *theExtension = (ODExtension *) fActiveExtensions.ValueAtKey((FW_PrivKeyType)name);
- if (!theExtension)
- {
- CreateExtensionFunc func = (CreateExtensionFunc) fNameToCreateFuncMap.ValueAtKey((FW_PrivKeyType)name);
- if (func)
- {
- theExtension = (func)(ev, fPart, name);
- if (theExtension)
- fActiveExtensions.AddPair((FW_PrivKeyType)name, (FW_PrivValueType)theExtension);
- }
- }
- if (theExtension)
- theExtension->Acquire(ev);
- return theExtension;
- }
-
- //----------------------------------------------------------------------------------------
- // FindValueInMap
- //----------------------------------------------------------------------------------------
-
- static FW_PrivKeyType FindValueInMap(FW_CPrivDictionaryList* list, FW_PrivValueType value)
- {
- FW_PrivKeyType result = 0;
- FW_CPrivLinkedListIterator *iter = list->CreateIterator();
- FW_CPrivLink *link;
- for (link=iter->First(); iter->IsNotComplete(); link=iter->Next())
- {
- FW_CPrivAssociation *assoc = (FW_CPrivAssociation*) link;
- if (assoc->GetValue() == value)
- {
- result = assoc->GetKey();
- break;
- }
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CExtensionManager::ReleaseExtension
- //----------------------------------------------------------------------------------------
-
- void FW_CExtensionManager::ReleaseExtension(Environment *ev, ODExtension *extension)
- {
- FW_ASSERT(extension!=NULL);
- FW_ASSERT(extension->GetRefCount(ev) == 0);
-
- // We only need to remove the extenson from the map when it's about to be destroyed
- FW_PrivKeyType name = FindValueInMap(&fActiveExtensions, extension);
- if (name)
- fActiveExtensions.RemoveKey(name);
-
- }
-
-