NAME
OTC_Symbol -
Symbol class for a string identifier.
SYNOPSIS
#include <OTC/text/symbol.hh>
class OTC_Symbol : public OTC_SObject
{
public:
static os_typespec* get_os_typespec();
~OTC_Symbol();
OTC_Symbol();
inline OTC_Symbol(OTC_Symbol const& theSymbol);
OTC_Symbol(char const* theString);
OTC_Symbol(char const* theString, u_int theLength);
OTC_Symbol(char theChar, u_int theNum=1);
OTC_Symbol(OTC_String const& theString);
OTC_Symbol(OTC_String const& theString, u_int theLength);
inline OTC_Symbol& operator=(OTC_Symbol const& theSymbol);
inline OTC_Boolean isEmpty() const;
char operator[](u_int theIndex) const;
inline char const* string() const;
inline u_int length() const;
inline static OTC_Boolean exists(char const* theString);
static OTC_Boolean exists(char const* theString, u_int theLength);
inline OTC_Boolean operator==(OTC_Symbol const& theSymbol) const;
inline OTC_Boolean operator!=(OTC_Symbol const& theSymbol) const;
inline OTC_Boolean operator==(OTC_String const& theString) const;
inline OTC_Boolean operator!=(OTC_String const& theString) const;
friend OTC_Boolean operator==(
OTC_String const& theString,
OTC_Symbol const& theSymbol
);
friend OTC_Boolean operator!=(
OTC_String const& theString,
OTC_Symbol const& theSymbol
);
inline OTC_Boolean operator==(char const* theString) const;
inline OTC_Boolean operator!=(char const* theString) const;
friend OTC_Boolean operator==(
char const* theString,
OTC_Symbol const& theSymbol
);
friend OTC_Boolean operator!=(
char const* theString,
OTC_Symbol const& theSymbol
);
inline int rank(OTC_Symbol const& theSymbol) const;
inline int hash() const;
static OTC_Symbol const& nullSymbol();
friend ostream& operator<<(
ostream& outs,
OTC_Symbol const& theSymbol
);
protected:
OTC_RString rawString() const;
};
CLASS TYPE
Concrete
DESCRIPTION
The OTC_Symbol class is an alternative to using the OTC_String
class as an identifier. The benefits of this class are that it
doesn't actually keep a copy of the string in the class. Instead,
all strings are kept in a central symbol table with this class
holding a pointer to the central string. This allows equality tests
to be very quick as it requires a pointer comparison only. Also,
as there is only one copy of the string in a central symbol table
excess memory will not be consumed due to duplicate copies of the
string.
CONSTRUCTION
OTC_Symbol();
Creates an instance of a symbol class
to represent the null string.
inline OTC_Symbol(OTC_Symbol const& theSymbol);
Creates an instance of the symbol
class which is the same as theSymbol.
OTC_Symbol(char const* theString);
Creates an instance of the symbol
class to represent theString.
OTC_Symbol(char const* theString, u_int theLength);
Creates an instance of the symbol
class to represent the first theLength
characters of theString.
OTC_Symbol(char theChar, u_int theNum=1);
Creates an instance of the symbol
class to represent a string containing
theNum instances of theString.
OTC_Symbol(OTC_String const& theString);
Creates an instance of the symbol class to
represent theString. If theString
represents a symbol, ie., it was created
through a conversion of a symbol to a
string, the conversion back to a symbol is
trivial provided that theString hadn't
been used in such a way that the delayed
copy linkage was broken.
OTC_Symbol(OTC_String const& theString, u_int theLength);
Creates an instance of the symbol
class to represent the first theLength
characters of theString.
inline OTC_Symbol& operator=(OTC_Symbol const& theSymbol);
Sets this symbol to be the same as
theSymbol.
QUERY
inline OTC_Boolean isEmpty() const;
Returns OTCLIB_TRUE if this symbol
is that of an empty string.
char operator[](u_int theIndex) const;
Returns the character at the location in
the string for this symbol, given by
theIndex. If theIndex is greater than
or equal to the length of the string for
this symbol, an exception is raised.
inline char const* string() const;
Returns a pointer to the character
string for the symbol.
inline u_int length() const;
Returns the length of the character
string for the symbol.
inline static OTC_Boolean exists(char const* theString);
Returns OTCLIB_TRUE if theString
already exists as a symbol. The null
symbol always exists.
static OTC_Boolean exists(char const* theString, u_int theLength);
Returns OTCLIB_TRUE if the symbol given
by the first theLength characters of
theString already exists as a symbol.
The null symbol always exists.
INEQUALITY
inline OTC_Boolean operator==(OTC_Symbol const& theSymbol) const;
Returns OTCLIB_TRUE if this symbol
is the same as theSymbol.
inline OTC_Boolean operator!=(OTC_Symbol const& theSymbol) const;
Returns OTCLIB_TRUE if this symbol
is not the same as theSymbol.
Following versions are provided so that comparisons against
instances of OTC_String and char const* will not result in
an entry being added to the symbol database.
inline OTC_Boolean operator==(OTC_String const& theString) const;
Returns OTCLIB_TRUE if this symbol
is the same as theString.
inline OTC_Boolean operator!=(OTC_String const& theString) const;
Returns OTCLIB_TRUE if this symbol
is not the same as theString.
friend OTC_Boolean operator==(
OTC_String const& theString,
OTC_Symbol const& theSymbol
);
Returns OTCLIB_TRUE if theSymbol
is the same as theString.
friend OTC_Boolean operator!=(
OTC_String const& theString,
OTC_Symbol const& theSymbol
);
Returns OTCLIB_TRUE if theSymbol
is not the same as theString.
inline OTC_Boolean operator==(char const* theString) const;
Returns OTCLIB_TRUE if this symbol
is the same as theString.
inline OTC_Boolean operator!=(char const* theString) const;
Returns OTCLIB_TRUE if this symbol
is not the same as theString.
friend OTC_Boolean operator==(
char const* theString,
OTC_Symbol const& theSymbol
);
Returns OTCLIB_TRUE if theSymbol
is the same as theString.
friend OTC_Boolean operator!=(
char const* theString,
OTC_Symbol const& theSymbol
);
Returns OTCLIB_TRUE if theSymbol
is not the same as theString.
RANKING
inline int rank(OTC_Symbol const& theSymbol) const;
Ranks this symbol against theSymbol.
HASHING
inline int hash() const;
Returns a hash value for the symbol.
NULL SYMBOL
static OTC_Symbol const& nullSymbol();
Returns a reference to the null symbol.
DISPLAY
friend ostream& operator<<(
ostream& outs,
OTC_Symbol const& theSymbol
);
Prints theSymbol on the stream outs.
CONVERSION
OTC_RString rawString() const;
Returns the string which the symbol
represents.
NOTES
Instances of OTC_Symbol cannot be stored in an ObjectStore
database.
SEE ALSO
OTC_String
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1993 OTC LIMITED
Copyright 1994 TELSTRA CORPORATION LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED