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();
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);

QUERY

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);

INEQUALITY

inline OTC_Boolean operator==(OTC_Symbol const& theSymbol) const;
inline OTC_Boolean operator!=(OTC_Symbol const& theSymbol) const;
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;
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
);

RANKING

inline int rank(OTC_Symbol const& theSymbol) const;

HASHING

inline int hash() const;

NULL SYMBOL

static OTC_Symbol const& nullSymbol();

DISPLAY

friend ostream& operator<<(
  ostream& outs,
  OTC_Symbol const& theSymbol
);

CONVERSION

OTC_RString rawString() const;

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