home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611B.ISO
/
vabasic
/
ntclnt.exe
/
DISK8
/
data.8
/
datab
/
INCLUDE
/
VATOM.H
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-29
|
8KB
|
369 lines
/*****************************************************************************
*** $Source: /rcs/crcs/general/vatom.h,v $
*** Checked int by: $Author: alaind $
*** $Date: 1996/03/19 15:32:58 $
*** $Revision: 1.12 $
*****************************************************************************
*** ***
*** Copyright (c) 1993, 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 VATOM_H
#define VATOM_H
#ifdef VSYS_WIN16
// Shorten the names of these enums and typedefs so that MSVC
// IMPLIB does not crash because of identifiers longer than
// 128 chars.
#define VTSearchCaseEnum VTSCaseE
#endif
#ifndef __cplusplus
struct VAtomStruct;
typedef VAtomStruct *VTAtomP;
#else
#include <dllclass.hh>
#include <vwcstr.hh>
class VeAtom;
typedef VeAtom *VTAtomP;
//=========================================================================
// VTSearchCase
// This enumeration is used to specify how to perform name
// searches when dealing with atoms. This enumeration allows
// hash tables, arrays, etc. to take the search type as an argument.
//-------------------------------------------------------------------------
typedef enum VTSearchCaseEnum
{
kVCaseSensitive, // Name search is case sensitive.
kVCaseInsensitive // Name search is case insensitive.
} VTSearchCase;
//-----------------------------------------------------------------------------
// Internal atom representation
// These objects should only be used as atom pointers by
// outside code.
class VeAtom : public VeDllBasedClass
{
public:
bool_t Equal(VTAtomP);
bool_t CaselessEqual(VTAtomP);
bool_t Equal(VTAtomP, VTSearchCase);
VTAtomP Caseless();
const char *String();
const wchar_t *WideString();
private:
VeAtom( const char *str,
VTAtomP caseless,
unsigned len,
unsigned hash);
VeAtom( const wchar_t *str,
VTAtomP caseless,
unsigned len,
unsigned hash);
// Put an inline destructor so that nobody can delete
// a VeAtom except those who are allowed to do so.
~VeAtom() { }
bool_t SameAs(const char *str, unsigned len);
bool_t SameAs(const wchar_t *str, unsigned len);
unsigned HashIndex();
friend class VeAtomManager;
friend class VeAtomHashTable;
unsigned itsLength;
char *itsString;
wchar_t *itsWideString;
VTAtomP itsCaselessAtom;
VTAtomP itsNext;
unsigned itsHashIndex;
};
//-----------------------------------------------------------------------------
// C++ castable atom class.
// This should be used for return values and arguments to functions
// This class is able to cast to/from VeString and const char *.
class VeAtomRef : public VeDllBasedClass
{
public:
VeAtomRef();
VeAtomRef(const char *);
VeAtomRef(const wchar_t *);
VeAtomRef(const VeString&);
VeAtomRef(const VwcString&);
VeAtomRef(VTAtomP);
VeAtomRef(const VeAtomRef &);
~VeAtomRef();
VeAtomRef &operator=(const VeAtomRef &other);
operator const char *() const;
operator const wchar_t *() const;
operator VTAtomP() const;
bool_t Equal(const VeAtomRef&) const;
bool_t CaselessEqual(const VeAtomRef&) const;
bool_t Equal(const VeAtomRef&, VTSearchCase) const;
VeAtomRef Caseless() const;
bool_t IsValid() const;
protected:
VTAtomP itsAtom;
};
//-----------------------------------------------------------------------------
// Class which manages collections of atoms.
// There should be only one instance of this class per process and it
// should never be deleted (until the process dies).
// The instance is controlled by LookupAtom.
class VeAtomManager : public VeDllBasedClass
{
public:
// only LookupAtom should use these public methods.
VeAtomManager();
VTAtomP Lookup(const char *);
VTAtomP Lookup(const wchar_t *);
protected:
VTAtomP Install(VTAtomP caseless,
const char *str,
unsigned len,
unsigned hash);
VTAtomP Install(VTAtomP caseless,
const wchar_t *str,
unsigned len,
unsigned hash);
unsigned Hash( const char *str,
unsigned &len);
unsigned Hash( const wchar_t *str,
unsigned &len);
VTAtomP Find( const char *str,
unsigned &len,
unsigned &hash);
VTAtomP Find( const wchar_t *str,
unsigned &len,
unsigned &hash);
VeAtom **itsAtoms;
};
extern "C"
{
#endif /* __cplusplus */
/* C callable entry points for using Atoms */
#define VaAtomsEqual(a, b) ((a) == (b))
#define VaAtomsCaseEqual(a, b, cs) \
( ((cs) == kVCaseSensitive) ? \
((a) == (b)) : \
(((a) ? VeCaselessAtom(a) : 0) == \
((b) ? VeCaselessAtom(b) : 0)) )
VFUNCDECL(VTAtomP) VeLookupAtom(const char *);
VFUNCDECL(VTAtomP) VeLookupWideAtom(const wchar_t *);
VFUNCDECL(VTAtomP) VeCaselessAtom(VTAtomP);
VFUNCDECL(const char*) VeGetAtomString(VTAtomP);
VFUNCDECL(const wchar_t*) VeGetAtomWideString(VTAtomP);
#ifdef __cplusplus
}
//=============================================================================
// Inline methods of VeAtom
//-----------------------------------------------------------------------------
inline bool_t VeAtom::Equal(VTAtomP cmp)
{
return this == cmp;
}
inline bool_t VeAtom::CaselessEqual(VTAtomP cmp)
{
return (this ? this->itsCaselessAtom : 0) ==
(cmp ? cmp->itsCaselessAtom : 0);
}
inline bool_t VeAtom::Equal(VTAtomP cmp, VTSearchCase scase)
{
if(scase == kVCaseSensitive)
return Equal(cmp);
else
return CaselessEqual(cmp);
}
inline VTAtomP VeAtom::Caseless()
{
return itsCaselessAtom;
}
inline unsigned VeAtom::HashIndex()
{
return itsHashIndex;
}
inline const char *VeAtom::String()
{
return itsString;
}
inline const wchar_t *VeAtom::WideString()
{
return itsWideString;
}
//=============================================================================
// Inline methods of VeAtomRef
//-----------------------------------------------------------------------------
inline VeAtomRef::VeAtomRef()
{
itsAtom = 0;
}
inline VeAtomRef::VeAtomRef(const char *string)
{
itsAtom = VeLookupAtom(string);
}
inline VeAtomRef::VeAtomRef(const wchar_t *string)
{
itsAtom = VeLookupWideAtom(string);
}
inline VeAtomRef::VeAtomRef(const VeString& string)
{
itsAtom = VeLookupAtom((const char *)string);
}
inline VeAtomRef::VeAtomRef(const VwcString& string)
{
itsAtom = VeLookupWideAtom((const wchar_t *)string);
}
inline VeAtomRef::VeAtomRef(VTAtomP atom)
{
itsAtom = atom;
}
inline VeAtomRef::VeAtomRef(const VeAtomRef &from)
{
itsAtom = from.itsAtom;
}
inline VeAtomRef::~VeAtomRef()
{
}
inline VeAtomRef &VeAtomRef::operator=(const VeAtomRef &other)
{
itsAtom = other.itsAtom;
return *this;
}
inline VeAtomRef::operator VTAtomP() const
{
return itsAtom;
}
inline VeAtomRef::operator const char *() const
{
if(itsAtom)
return itsAtom->String();
else
return "";
}
inline VeAtomRef::operator const wchar_t *() const
{
if(itsAtom)
return itsAtom->WideString();
else
return kVwcEmpty;
}
inline bool_t VeAtomRef::Equal(const VeAtomRef &atom) const
{
// Note that Equal is able to a NULL 'this'
return itsAtom->Equal(atom);
}
inline bool_t VeAtomRef::CaselessEqual(const VeAtomRef &atom) const
{
// Note that CaselessEqual is able to a NULL 'this'
return itsAtom->CaselessEqual(atom);
}
inline bool_t VeAtomRef::Equal(const VeAtomRef &atom, VTSearchCase scase) const
{
// Note that Equal is able to a NULL 'this'
return itsAtom->Equal(atom, scase);
}
inline VeAtomRef VeAtomRef::Caseless() const
{
if(itsAtom)
return itsAtom->Caseless();
else
return VeAtomRef();
}
inline bool_t VeAtomRef::IsValid() const
{
if(itsAtom)
return TRUE;
else
return FALSE;
}
#endif /* __cplusplus */
#endif /* VATOM_H */