/* * 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. */ /* * Interface to Ref (persistent object reference) base class. */ #ifndef ref_h #define ref_h #include #include #include #include static const UID CLUSTERBITMASK = 0x80000000; static const UID INMEMORYBITMASK = 0x1; class Ref { friend class Cache; friend class ObjectMan; public: Ref(); Ref(UID); Ref(Persistent*); UID uid(); Persistent* operator()(); bool Valid(); /* true if ref is non-nil/non-INVALIDUID */ bool operator==(Ref r); bool operator!=(Ref r); bool Write(PFile*); /* write uid + cluster bit */ bool Read(PFile*); /* read uid + cluster bit */ bool WriteObjects(PFile*); /* write object if not head of a cluster */ bool ReadObjects(PFile*); /* read object if not head of a cluster */ protected: void uid (UID); /* set uid */ void Warning(const char*); void Panic(const char*, int); bool inMemory(); bool isCluster(); /* checks cluster bit (msb UID); it's */ /* set if object is a head of a cluster */ /* (doesn't check if ref is inMemory!) */ void setClusterBit(); void resetClusterBit(); UID getUID(); /* removes cluster bit */ Persistent* ref(); /* returns obj (possibly faulting it in) */ Persistent* refObjects(); /* seekless ref() for faulting in */ /* consecutive objects */ void unref(); /* converts ref to uid w/cluster bit */ protected: union { /* distinguished in that a UID has lsb == 1 */ Persistent* refto; UID _uid; }; }; #endif