home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 7.1 KB | 248 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCFMRes.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWFILES_H
- #include "FWFiles.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #ifdef FW_BUILD_MAC
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
- #ifndef __FRAGRSRC__
- #include <FragRsrc.h>
- #endif
-
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwresour
- #endif
-
- //========================================================================================
- // Global Variable
- //========================================================================================
- // FW_gInstance is initialized in InitLibraryResources on the Mac
- // FW_gInstance is defined in FWLbInit.cpp for Windows
-
- #ifdef FW_BUILD_MAC
- FW_SCodeFragRefFile gNullCodeFrag = {NULL, -1, 0};
- FW_Instance FW_gInstance = &gNullCodeFrag;
- #endif
-
- //========================================================================================
- // Global functions
- //========================================================================================
-
- //========================================================================================
- // class FW_CAcquireCFMResourceAccess
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- FW_DEFINE_AUTO(FW_CAcquireCFMResourceAccess)
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- fInstance = FW_gInstance;
- CommonInit(ev);
- FW_END_CONSTRUCTOR
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess(Environment* ev, FW_Instance instance)
- {
- #ifdef FW_BUILD_MAC
- fInstance = instance;
- CommonInit(ev);
- FW_END_CONSTRUCTOR
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::CommonInit
- //----------------------------------------------------------------------------------------
-
- void FW_CAcquireCFMResourceAccess::CommonInit(Environment* ev)
- {
- FW_UNUSED(ev);
- FW_ASSERT(fInstance != NULL);
-
- short ref = CurResFile();
-
- if(fInstance->fNesting > 0 )
- ::UseResFile(fInstance->fRefNum);
- else
- {
- FW_FailOnError(::BeginCFragResources(fInstance->fFragRef));
- fInstance->fRefNum = ::CurResFile();
- }
- fInstance->fNesting++;
- fSavedLibraryRefNum = ref;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess()
- {
- #ifdef FW_BUILD_MAC
- FW_START_DESTRUCTOR
-
- if(fInstance->fNesting > 0 )
- if( --fInstance->fNesting == 0 )
- FW_FailOnError(::EndCFragResources(fInstance->fFragRef));
- ::UseResFile(fSavedLibraryRefNum);
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::PrivInitLibraryResources
- //----------------------------------------------------------------------------------------
-
- OSErr FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(CFragInitBlockPtr init)
- {
- return InitCFragResources(init,&FW_gInstance->fFragRef);
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources
- //----------------------------------------------------------------------------------------
-
- void FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources()
- {
- #ifdef FW_DEBUG
- FW_ASSERT(FW_gInstance->fNesting == 0);
- #endif
-
- OSErr err= ::TermCFragResources(FW_gInstance->fFragRef);
- FW_ASSERT(err == noErr);
-
- FW_gInstance->fFragRef = NULL;
- FW_gInstance->fRefNum = -1;
- FW_gInstance->fNesting = 0;
- }
- #endif
-
- //========================================================================================
- // class FW_CSharedLibraryResourceFile
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CSharedLibraryResourceFile)
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile(Environment* ev):
- FW_PResourceFile()
- #ifdef FW_BUILD_MAC
- ,fAcquireCFMResourceAccess(ev, FW_gInstance)
- #endif
- {
- CommonInit(ev, FW_gInstance);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile(Environment* ev, FW_Instance instance):
- FW_PResourceFile()
- #ifdef FW_BUILD_MAC
- ,fAcquireCFMResourceAccess(ev, instance)
- #endif
- {
- CommonInit(ev, instance);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::CommonInit
- //----------------------------------------------------------------------------------------
-
- void FW_CSharedLibraryResourceFile::CommonInit(Environment* ev, FW_Instance instance)
- {
- #if 0
- #ifdef FW_BUILD_MAC
- FW_PResourceFile resourceFile(new FW_CResourceFileRep(ev, fAcquireCFMResourceAccess.GetLibraryRefNum()));
- #endif
- #ifdef FW_BUILD_WIN
- FW_PResourceFile resourceFile(new FW_CResourceFileRep(ev, instance));
- #endif
- SetRep(resourceFile);
- #else
- #ifdef FW_BUILD_MAC
- FW_UNUSED(instance);
- FW_PResourceFile rep(ev, fAcquireCFMResourceAccess.GetLibraryRefNum());
- #endif
- #ifdef FW_BUILD_WIN
- FW_PResourceFile rep(ev, instance);
- #endif
- SetRep(ev, rep);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile()
- {
- FW_START_DESTRUCTOR
- }
-