#ifndef FILE_SYMBOLTA #define FILE_SYMBOLTA /**************************************************************************/ /* File: symbolta.hh */ /* Author: Joachim Schoeberl */ /* Date: 01. Jun. 95 */ /**************************************************************************/ namespace netgen { /** Base class for the generic SYMBOLTABLE. An array of identifiers is maintained. */ class DLL_HEADER BASE_SYMBOLTABLE { protected: /// identifiers Array names; public: /// Constructor BASE_SYMBOLTABLE (); /// ~BASE_SYMBOLTABLE (); /// void DelNames (); /// Index of symbol name, returns 0 if not used. int Index (const char * name) const; }; /** Abstract data type Symbol Table. To a string an value of the generic type T is associated. The string is not copied into the symbol table class! */ template class SYMBOLTABLE : public BASE_SYMBOLTABLE { private: /// Associated data Array data; public: /// Creates a symboltable inline SYMBOLTABLE (); /// Returns size of symboltable inline INDEX Size() const; /// Returns reference to element, error if not used inline T & Elem (const char * name); /// Returns reference to i-th element inline T & Elem (int i) { return data.Elem(i); } /// Returns element, error if not used inline const T & Get (const char * name) const; /// Returns i-th element inline const T & Get (int i) const; /// Returns name of i-th element inline const char* GetName (int i) const; /// Associates el to the string name, overrides if name is used inline void Set (const char * name, const T & el); /// Checks whether name is used inline bool Used (const char * name) const; /// Deletes symboltable inline void DeleteAll (); void DoArchive(Archive& archive) { archive & names & data;} inline T & operator[] (int i) { return data[i]; } inline const T & operator[] (int i) const { return data[i]; } private: /// Prevents from copying symboltable by pointer assignment SYMBOLTABLE & operator= (SYMBOLTABLE &); }; template inline SYMBOLTABLE :: SYMBOLTABLE () { ; } template inline INDEX SYMBOLTABLE :: Size() const { return data.Size(); } template inline T & SYMBOLTABLE :: Elem (const char * name) { int i = Index (name); if (i) return data.Elem (i); else return data.Elem(1); } template inline const T & SYMBOLTABLE :: Get (const char * name) const { int i; i = Index (name); if (i) return data.Get(i); else return data.Get(1); } template inline const T & SYMBOLTABLE :: Get (int i) const { return data.Get(i); } template inline const char* SYMBOLTABLE :: GetName (int i) const { return names.Get(i); } template inline void SYMBOLTABLE :: Set (const char * name, const T & el) { int i; i = Index (name); if (i) data.Set(i, el); else { data.Append (el); char * hname = new char [strlen (name) + 1]; strcpy (hname, name); names.Append (hname); } } template inline bool SYMBOLTABLE :: Used (const char * name) const { return (Index(name)) ? true : false; } template inline void SYMBOLTABLE :: DeleteAll () { DelNames(); data.DeleteAll(); } } #endif