• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/collection/StringTable.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _stringtable_h
00018 #define _stringtable_h
00019 
00020 #include <spl/collection/Hashtable.h>
00021 #include <spl/collection/List.h>
00022 #include <spl/String.h>
00023 #include <spl/text/StringBuffer.h>
00024 #include <spl/collection/Vector.h>
00025 
00033 class StringTable : public IMemoryValidate
00034 {
00035 protected:
00036         Hashtable<int, Vector<String *> *> m_stringIdx;
00037         Vector<String *> m_strings;
00038         List<Vector<String *> *> m_lists;
00039 
00040 public:
00041         StringTable(const StringTable& st);
00042         StringTable();
00043         virtual ~StringTable();
00044 
00045         StringTable& operator =(const StringTable& st);
00046 
00047         void Clear();
00048 
00049         inline int Count() const { return m_strings.Count(); }
00050 
00051         inline String *GetPtr(StringBuffer *str) { return GetPtr(str->GetChars()); }
00052         inline String *GetPtr(const StringBuffer& str) { return GetPtr(str.GetChars()); }
00053         inline String *GetPtr(String *str) { return GetPtr(str->GetChars()); }
00054         inline String *GetPtr(const String& str) { return GetPtr(str.GetChars()); }
00055         String *GetPtr(const char *str);
00056         inline String* GetPtr(int idx) const { return m_strings.ElementAt(idx); }
00057 
00058         inline String& Get(StringBuffer *str) { return *GetPtr(str->GetChars()); }
00059         inline String& Get(const StringBuffer& str) { return *GetPtr(str.GetChars()); }
00060         inline String& Get(String *str) { return *GetPtr(str->GetChars()); }
00061         inline String& Get(const String& str) { return *GetPtr(str.GetChars()); }
00062         inline String& Get(const char *str) { return *GetPtr(str); }
00063         inline String& Get(int idx) const { return *m_strings.ElementAt(idx); }
00064 
00065         int PositionOf(const String& str);
00066         inline int PositionOf(const String* str) { return PositionOf(*str); }
00067 
00068 #ifdef DEBUG
00069         virtual void ValidateMem() const;
00070         virtual void CheckMem() const;
00071 #endif
00072 };
00073 
00074 REGISTER_TYPEOF( 406, StringTable );
00075 
00078 #endif