/* * Copyright (c) 1987, 1988, 1989 Stanford University * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Stanford not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Stanford makes no representations about * the suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * RefList class implementation. A RefList is a list of Refs, which are * references to Persistent objects. */ #include RefList* RefList::Find (Ref p) { register RefList* e; for (e = next; e != this; e = e->next) { if (*e == p) { return e; } } return nil; } bool RefList::Write (PFile* f) { RefList* i; int count = 0; for (i = next; i != this; i = i->next) { ++count; } bool ok = f->Write(count); for (i = next; i != this && ok; i = i->next) { ok = ((Ref*) i)->Write(f); } return ok; } bool RefList::Read (PFile* f) { int count; RefList* i; bool ok = f->Read(count); for (--count; count >= 0 && ok; --count) { i = new RefList; ok = ((Ref*) i)->Read(f); Append(i); } return ok; } bool RefList::WriteObjects (PFile* f) { RefList* i; bool ok = true; for (i = next; i != this && ok; i = i->next) { ok = ((Ref*) i)->WriteObjects(f); } return ok; } bool RefList::ReadObjects (PFile* f) { RefList* i; bool ok = true; for (i = next; i != this && ok; i = i->next) { ok = ((Ref*) i)->ReadObjects(f); } return ok; } RefList* RefList::operator[] (int count) { RefList* pos = First(); int i; for (i = 1; i < count && pos != End(); ++i) { pos = pos->Next(); } if (i == count) { return pos; } return nil; } RefList::RefList () : Ref() { next = this; prev = this; } RefList::RefList (UID u) : Ref(u) { next = this; prev = this; } RefList::RefList (Persistent* p) : Ref(p) { next = this; prev = this; } RefList::~RefList () { uid(INVALIDUID); next = (RefList*) -2; prev = (RefList*) -3; } bool RefList::IsEmpty () { return next == this; } void RefList::SetRef (Ref r) { uid(r.uid()); } void RefList::Append (RefList* e) { prev->next = e; e->prev = prev; e->next = this; prev = e; } void RefList::Prepend (RefList* e) { next->prev = e; e->prev = this; e->next = next; next = e; } void RefList::Remove (RefList* e) { e->prev->next = e->next; e->next->prev = e->prev; e->prev = (RefList*) -1; e->next = (RefList*) -1; } void RefList::Delete (Ref p) { register RefList* e; e = Find(p); if (e != nil) { Remove(e); delete e; } } RefList* RefList::First () { return next; } RefList* RefList::Last () { return prev; } RefList* RefList::End () { return this; } RefList* RefList::Next () { return next; } RefList* RefList::Prev () { return prev; }