home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611B.ISO
/
vabasic
/
ntclnt.exe
/
DISK8
/
data.8
/
datab
/
INCLUDE
/
VUUID.H
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-29
|
6KB
|
145 lines
/*****************************************************************************
*** $Source: /rcs/crcs/general/vuuid.h,v $
*** Checked int by: $Author: dan $
*** $Date: 1996/04/10 15:17:30 $
*** $Revision: 1.7 $
*****************************************************************************
*** ***
*** Copyright (c) 1995, Visual Edge Software Ltd. ***
*** ***
*** All rights reserved. This notice is intended as a precaution ***
*** against inadvertent publication, and shall not be deemed to con- ***
*** stitute an acknowledgment that publication has occurred nor to ***
*** imply any waiver of confidentiality. The year included in the ***
*** notice is the year of the creation of the work. ***
*** ***
*****************************************************************************/
#ifndef VUUID_H
#define VUUID_H
#include <iptrhash.hh> // for typedef VIHashKey.
#include <vatom.h> // for VAtomP.
/*==========================================================================
* VUUIDDECL is used to declare a persistent ID in a header file.
* The first and only argument is the identifier that you are going
* to use throughout the C code.
*--------------------------------------------------------------------------*/
#define VUUIDDECL(uuid) VDATADECL(VTUniqueID) uuid
/*==========================================================================
* VUUIDDEF is used to define a persistent ID in a source file.
* For each given ID, this should be in only one source file.
* The first argument is the identifier that you are going to
* use throughout the C code.
* The second argument is a string that represents a unique id.
* The member itsAtom is initialized at NULL. The first time
* VUUIDKEY is called on the argument 'uuid' (which can happen
* when a comparison is made between two uuids), a look up for
* an atom is done.
*--------------------------------------------------------------------------*/
#define VUUIDDEF(uuid,idStr) \
VTUniqueIDData uuid##Data = { idStr, 0 }; \
VDATADEF(VTUniqueID) uuid = { & uuid##Data }
/*==========================================================================
* VUUIDFROMATOM declares a VTUniqueID variable given an
* atom. The uniqueID should only be used as a local variable
*--------------------------------------------------------------------------*/
#define VUUIDFROMATOM(uuid,atom) \
VTUniqueIDData uuid##Data; \
VTUniqueID uuid; \
uuid##Data.itsString = 0; \
uuid##Data.itsAtom = atom; \
uuid.itsID = &uuid##Data;
/*==========================================================================
* VUUID_ATOM_LOOKUP returns a valid VAtomP given a VTUniqueID as argument.
* This method is not intended to be called by a user.
* The macro first checks if itsAtom has ever been looked up. If not, a
* look up is done and assigned to itsAtom.
* NEVER CHANGE the VAtomP returned by this macro.
*--------------------------------------------------------------------------*/
#define VUUID_ATOM_LOOKUP(uuid) \
(uuid.itsID->itsAtom ? uuid.itsID->itsAtom : \
(uuid.itsID->itsAtom = VeLookupAtom(uuid.itsID->itsString)))
/*==========================================================================
* VUUIDKEY returns a unique key that can be used in hash tables, for
* instance.
* NEVER CHANGE the VAtomP returned by this macro.
* In C++, you don't have to use this macro; we have a cast operator that
* cast a uuid to a VIHashKey.
*--------------------------------------------------------------------------*/
#define VUUIDKEY(uuid) (VIHashKey)VUUID_ATOM_LOOKUP(uuid)
/*==========================================================================
* VeEqualID compares two ID to see if they describe the same value.
*--------------------------------------------------------------------------*/
#define VeEqualID(a, b) (VUUID_ATOM_LOOKUP(a) == VUUID_ATOM_LOOKUP(b))
/*==========================================================================
* VTUniqueIDInfo contains the unique identification data of a UUID.
* Only one instance of this should exist for any given ID in one DLL.
*--------------------------------------------------------------------------*/
typedef struct VUniqueIDDataStruct
{
const char *itsString;
VTAtomP itsAtom;
} VTUniqueIDData;
/*==========================================================================
* VTUniqueID is the unique ID reference which is used in all comparisons.
* There can be many instances of this for each ID data object.
*--------------------------------------------------------------------------*/
typedef struct VTUniqueIDStruct
{
VTUniqueIDData *itsID;
#ifdef __cplusplus
operator VIHashKey () { return VUUIDKEY((*this)); }
operator VTAtomP () { return VUUID_ATOM_LOOKUP((*this)); }
operator VeAtomRef () { return VUUID_ATOM_LOOKUP((*this)); }
#endif
} VTUniqueID;
#ifdef __cplusplus
/*==========================================================================
* C++ operators == and != compare two ID's to determine equality.
*--------------------------------------------------------------------------*/
inline bool_t operator ==(const VTUniqueID &a, const VTUniqueID &b)
{
return VeEqualID(a, b);
}
inline bool_t operator !=(const VTUniqueID &a, const VTUniqueID &b)
{
return !VeEqualID(a, b);
}
inline bool_t operator ==(const VTUniqueID &a, const VeAtomRef &b)
{
return VUUID_ATOM_LOOKUP(a) == (VTAtomP)b;
}
inline bool_t operator !=(const VTUniqueID &a, const VeAtomRef &b)
{
return !(VUUID_ATOM_LOOKUP(a) == (VTAtomP)b);
}
#endif
#endif /* VUUID_H */