home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.8 KB | 291 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLObjReg.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef SLMEMMGR_H
- #include "SLMemMgr.h"
- #endif
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #define SOM_Module_slobjreg_Source
- #include <SLObjReg.xih>
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWArchiv
- #endif
-
- static void growList(FW_OBasicObjectRegistryData *somThis);
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistry__RegisterObject
- //----------------------------------------------------------------------------------------
- /*
- * Register an object and returns the (unique) ID
- */
- SOM_Scope FW_ObjectRegistry_ID SOMLINK FW_OObjectRegistry__RegisterObject(FW_OObjectRegistry *somSelf, Environment *ev,
- void* object)
- {
- FW_UNUSED(somSelf);
- FW_UNUSED(ev);
- FW_UNUSED(object);
- return FW_kNotInRegistry;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistry__RegisterObjectAndID
- //----------------------------------------------------------------------------------------
- /*
- * Register an object to particular id.
- * The id must not already be in the registry.
- */
- SOM_Scope void SOMLINK FW_OObjectRegistry__RegisterObjectAndID(FW_OObjectRegistry *somSelf, Environment *ev,
- void* object,
- FW_ObjectRegistry_ID id)
- {
- FW_UNUSED(somSelf);
- FW_UNUSED(ev);
- FW_UNUSED(object);
- FW_UNUSED(id);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistry__LookupByObject
- //----------------------------------------------------------------------------------------
- /*
- * Look up an object in the registry, return kNonInRegistry if object not found.
- */
- SOM_Scope FW_ObjectRegistry_ID SOMLINK FW_OObjectRegistry__LookupByObject(FW_OObjectRegistry *somSelf, Environment *ev,
- void* object)
- {
- FW_UNUSED(somSelf);
- FW_UNUSED(ev);
- FW_UNUSED(object);
- return FW_kNotInRegistry;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistry__LookupByID
- //----------------------------------------------------------------------------------------
- /*
- * Find an object by ID, return its pointer.
- * Return 0 if id not in registry.
- */
- SOM_Scope void* SOMLINK FW_OObjectRegistry__LookupByID(FW_OObjectRegistry *somSelf, Environment *ev,
- FW_ObjectRegistry_ID id)
- {
- FW_UNUSED(somSelf);
- FW_UNUSED(ev);
- FW_UNUSED(id);
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistry__somInit
- //----------------------------------------------------------------------------------------
- SOM_Scope void SOMLINK FW_OObjectRegistry__somInit(FW_OObjectRegistry *somSelf)
- {
- FW_UNUSED(somSelf);
-
- // FW_OObjectRegistry_parent_SOMObject_somInit(somSelf);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OObjectRegistrysomUninit
- //----------------------------------------------------------------------------------------
- SOM_Scope void SOMLINK FW_OObjectRegistry__somUninit(FW_OObjectRegistry *somSelf)
- {
- FW_UNUSED(somSelf);
-
- // FW_OObjectRegistry_parent_SOMObject_somUninit(somSelf);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__somInit
- //----------------------------------------------------------------------------------------
- SOM_Scope void SOMLINK FW_OBasicObjectRegistry__somInit(FW_OBasicObjectRegistry *somSelf)
- {
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- // FW_OBasicObjectRegistry_parent_FW_OObjectRegistry_somInit(somSelf);
-
- somThis->fList = 0;
- somThis->fListLength = 0;
- somThis->fPhysicalListLength = 0;
- somThis->fNextUnusedID = 1;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__somUninit
- //----------------------------------------------------------------------------------------
- SOM_Scope void SOMLINK FW_OBasicObjectRegistry__somUninit(FW_OBasicObjectRegistry *somSelf)
- {
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- FW_PrimitiveFreeBlock(somThis->fList);
-
- // FW_OBasicObjectRegistry_parent_FW_OObjectRegistry_somUninit(somSelf);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__RegisterObject
- //----------------------------------------------------------------------------------------
- SOM_Scope FW_ObjectRegistry_ID SOMLINK FW_OBasicObjectRegistry__RegisterObject(FW_OBasicObjectRegistry *somSelf, Environment *ev,
- void* object)
- {
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_ASSERT(FW_OBasicObjectRegistry__LookupByObject(somSelf, ev, object) == FW_kNotInRegistry);
- if (somThis->fListLength == somThis->fPhysicalListLength)
- {
- growList(somThis);
- // if (ev->_major != 0)
- // return FW_kNotInRegistry;
- }
-
- long entry = somThis->fListLength++;
- somThis->fList[entry].fObject = object;
- while (FW_OBasicObjectRegistry__LookupByID(somSelf, ev, somThis->fNextUnusedID) != 0)
- somThis->fNextUnusedID++;
- somThis->fList[entry].fID = somThis->fNextUnusedID++;
-
- return somThis->fList[entry].fID;
- }
- FW_SOM_CATCH
-
- return FW_kNotInRegistry;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__RegisterObjectAndID
- //----------------------------------------------------------------------------------------
- SOM_Scope void SOMLINK FW_OBasicObjectRegistry__RegisterObjectAndID(FW_OBasicObjectRegistry *somSelf, Environment *ev,
- void* object,
- FW_ObjectRegistry_ID id)
- {
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- FW_SOM_TRY
- {
- // FW_ASSERT(FW_OBasicObjectRegistry__LookupByObject(somSelf, ev, object) == FW_kNotInRegistry);
- FW_ASSERT(FW_OBasicObjectRegistry__LookupByID(somSelf, ev, id) == 0);
-
- if (somThis->fListLength == somThis->fPhysicalListLength)
- growList(somThis);
-
- long entry = somThis->fListLength++;
- somThis->fList[entry].fObject = object;
- somThis->fList[entry].fID = id;
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__LookupByObject
- //----------------------------------------------------------------------------------------
- SOM_Scope FW_ObjectRegistry_ID SOMLINK FW_OBasicObjectRegistry__LookupByObject(FW_OBasicObjectRegistry *somSelf, Environment *ev,
- void* object)
- {
- FW_UNUSED(ev);
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- FW_ObjectRegistry_ID result = FW_kNotInRegistry;
- for (long i = 0; i < somThis->fListLength; i++)
- {
- if (somThis->fList[i].fObject == object)
- {
- result = somThis->fList[i].fID;
- break;
- }
- }
-
- return result;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OBasicObjectRegistry__LookupByID
- //----------------------------------------------------------------------------------------
- SOM_Scope void* SOMLINK FW_OBasicObjectRegistry__LookupByID(FW_OBasicObjectRegistry *somSelf, Environment *ev,
- FW_ObjectRegistry_ID id)
- {
- FW_UNUSED(ev);
- FW_OBasicObjectRegistryData *somThis = FW_OBasicObjectRegistryGetData(somSelf);
-
- void* result = 0;
- for (long i = 0; i < somThis->fListLength; i++)
- {
- if (somThis->fList[i].fID == id)
- {
- result = somThis->fList[i].fObject;
- break;
- }
- }
-
- return result;
- }
-
-
- //----------------------------------------------------------------------------------------
- // growList
- //----------------------------------------------------------------------------------------
- /*
- * Grow the list by kExpansion slots
- */
- static void growList(FW_OBasicObjectRegistryData *somThis)
- {
- const int kExpansion = 8;
- long bytesNeeded = (somThis->fPhysicalListLength+kExpansion) * sizeof(FW_OBasicObjectRegistry_SAssociation);
-
- if (somThis->fList == 0)
- somThis->fList = (FW_OBasicObjectRegistry_SAssociation*) FW_PrimitiveAllocateBlock(bytesNeeded);
- else
- somThis->fList = (FW_OBasicObjectRegistry_SAssociation*) FW_PrimitiveResizeBlock(somThis->fList, bytesNeeded);
-
- if (somThis->fList == 0)
- {
- somThis->fPhysicalListLength = 0;
- FW_Failure(FW_xMemoryExhausted);
- }
-
- for (long i = somThis->fPhysicalListLength; i < somThis->fPhysicalListLength+kExpansion; i++)
- {
- somThis->fList[i].fID = FW_kNotInRegistry;
- somThis->fList[i].fObject = 0;
- }
-
- somThis->fPhysicalListLength += kExpansion;
- }
-
-
-