home *** CD-ROM | disk | FTP | other *** search
- //***************************************************************************
- // OATH :: Object-oriented Abstract Type Hierarchy
- //***************************************************************************
- //
- // Copyright (C) 1991, 1990 Texas Instruments Incorporated
- // Permission is granted to any individual or institution
- // to use, copy, modify, and distribute this software,
- // provided that this complete copyright and permission notice
- // is maintained, intact, in all copies and supporting documentation.
- //
- // Texas Instruments Incorporated provides this software "as is"
- // without express or implied warranty.
- //
- //***************************************************************************
- // oathCore (oathCoreA, oathCoreG)
- //
- // History:
- // 06/92 Brian M Kennedy fixed oathCoreG::Nil to be a const pointer
- // 07/91 Brian M Kennedy import, export, typeRegister
- // 06/91 Brian M Kennedy New macros & format; remove printDiagnostic
- // 10/90 Brian M Kennedy Original
- //
- //***************************************************************************
-
- #include "copyright.h"
-
- #include <oath/oathCore.h>
-
- #include <oath/obj.h>
-
- #include <iostream.h>
-
- /////////////////////////////////////////////////////////////////////////////
- // oathCoreG Outline Definitions
-
- void oathCoreG::
- vtablePosition () const
- {}
-
- const char* oathCoreG::TypeName = registerType("", oathCoreG::import);
-
- void (*oathCoreG::NextNewHandler) () = oathCoreG::setOathNewHandler();
-
- oathCoreG* oathCoreG::AllObjs;
-
- oathCoreG* oathCoreG::NilPtr;
-
- oathCoreG* const oathCoreG::Nil = oathCoreG::nil();
-
-
- void (* oathCoreG::
- setOathNewHandler ()) ()
- {return set_new_handler(oathCoreG::oathNewHandler);}
-
- oathCoreG* oathCoreG::
- nil ()
- {if(!NilPtr)
- NilPtr = new oathCoreG(OATH_NIL, OATH_NIL);
- return NilPtr;
- }
-
-
- // Garbage Collection //////////
-
- #if (OATH_GC == OATH_GC_COM)
-
- void oathCoreG::
- collectGarbage (int Quick) // Quick = FALSE)
- {oathCoreG* Obj;
- if(!Quick)
- {// Pass 1: Dereference
- Obj = AllObjs;
- while(Obj)
- {Obj->clearReferences();
- Obj = Obj->Next;
- }
-
- // Pass 2: Re-reference
- Obj = AllObjs;
- while(Obj)
- {if(Obj->isRefd())
- Obj->setReferences();
- Obj = Obj->Next;
- }
- }
-
- // Pass 3: Collect garbage
- Obj = AllObjs;
- while(Obj)
- {oathCoreG* Next = Obj->Next;
- if(!Obj->isRefd())
- delete Obj;
- Obj = Next;
- }
- }
-
- #elif (OATH_GC == OATH_GC_SAC)
-
- void oathCoreG::
- collectGarbage (int Quick) // Quick = FALSE)
- {oathCoreG* Prev;
- oathCoreG* Obj;
- if(!Quick)
- {// Pass 1: Dereference
- Obj = AllObjs;
- while(Obj)
- {Obj->clearReferences();
- Obj = Obj->Next;
- }
-
- // Pass 2: Re-reference
- Obj = AllObjs;
- while(Obj)
- {if(Obj->isRefd())
- Obj->setReferences();
- Obj = Obj->Next;
- }
- }
-
- // Pass 3: Collect garbage
- Obj = AllObjs;
- while(Obj && !Obj->isRefd())
- {AllObjs = Obj->Next;
- delete Obj;
- Obj = AllObjs;
- }
- while(Obj)
- {Prev = Obj;
- Obj = Obj->Next;
- while(Obj && !Obj->isRefd())
- {Prev->Next = Obj->Next;
- delete Obj;
- Obj = Prev->Next;
- }
- }
- }
-
- #else
-
- void oathCoreG::
- collectGarbage (int) // Quick = FALSE)
- {}
-
- #endif
-
-
- void oathCoreG::
- oathNewHandler ()
- {collectGarbage();
- if(NextNewHandler)
- NextNewHandler();
- }
-
-
- // Operations //////////
-
- void oathCoreG::
- export (exportP& X) const
- {X.writeType(TypeName);}
-
- objA oathCoreG::
- import (importP&)
- {return objA::Nil;}
-
- void oathCoreG:: // clearMark();
- clearReferences() // for(each Obj this ref's)
- {clearMark();} // Obj->deref();
-
- void oathCoreG:: // if(!isMarked())
- setReferences() // {setMark();
- {setMark();} // for(each Obj this ref's)
- // {Obj->ref();
- // Obj->setReferences();
- // }
- // }
-
-
- // Static Internal Operations //////////
-
- const char* oathCoreG::
- registerType (const char* Name, importF Import)
- {return typeRegisterP::registerType(Name, Import);}
-
-
- /////////////////////////////////////////////////////////////////////////////
- // oathCoreA Outline Definitions
-
- // Export Operations //////////
-
- void oathCoreA::
- export (ostream& S) const
- {exportP X (S);
- export(X);
- }
-
- void oathCoreA::
- export (exportP& X) const
- {oidP OID;
- if(X.registerObj(guts(), OID))
- X.stream() << 'R' << OID << ' ';
- else
- {X.stream() << 'N' << OID << ' ';
- guts()->export(X);
- }
- }
-
- objA oathCoreA::
- import (istream& S)
- {importP M (S);
- return import(M);
- }
-
- objA oathCoreA::
- import (importP& M)
- {oathCoreA ImportObj;
- char C = M.stream().get();
- oidP OID;
- M.stream() >> OID;
- M.stream().get();
- switch(C)
- {case 'R':
- ImportObj = M.obj(OID);
- break;
- case 'N':
- {const char* TypeName = M.readType();
- typeRegisterP * TR = typeRegisterP::findRegister(TypeName);
- ensure(TR, "throw: badImportData");
- // ImportObj = TR->Import(M); // compiler broken -- bad code
- ImportObj = (*(importF)(TR->Import))(M);
- M.registerObj(ImportObj.guts(), OID);
- }
- break;
- default:
- ensure(FALSE, "throw: badImportData");
- }
- return (const objA&)ImportObj;
- }
-
-
- //***************************************************************************
-