iutil/strset.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Anders Stenberg 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_IUTIL_STRINGSET_H__ 00020 #define __CS_IUTIL_STRINGSET_H__ 00021 00027 #include "csutil/scf_interface.h" 00028 00029 namespace CS 00030 { 00032 typedef unsigned int StringIDValue; 00033 00042 template<typename Tag> 00043 struct StringID 00044 { 00045 protected: 00046 StringIDValue id; 00047 00048 public: 00049 StringID() {} 00050 StringID (const StringID& other) : id (other.id) {} 00051 StringID (StringIDValue id) : id (id) {} 00052 00053 // Detect attempts to mix string IDs with different tags 00054 template<typename Tag2> 00055 CS_DEPRECATED_METHOD_MSG("Mixing string IDs with different tags may " 00056 "indicate an error. Explicit construct if really needed") 00057 StringID (const StringID<Tag2>& other) : id ((StringIDValue)other) {} 00058 00059 StringID& operator=(const StringID& other) 00060 { 00061 id = other.id; 00062 return *this; 00063 } 00064 00065 // Detect attempts to mix string IDs with different tags 00066 template<typename Tag2> 00067 CS_DEPRECATED_METHOD_MSG("Mixing string IDs with different tags may " 00068 "indicate an error. Explicit construct if really needed") 00069 StringID& operator=(const StringID<Tag2>& other) 00070 { 00071 id = (StringIDValue)other; 00072 return *this; 00073 } 00074 00075 operator StringIDValue() const { return id; } 00076 00077 unsigned int GetHash() const { return id; } 00078 }; 00079 00081 template<typename Tag> 00082 struct InvalidStringID : public StringID<Tag> 00083 { 00084 InvalidStringID() { this->id = (StringIDValue)~0; } 00085 }; 00086 } // namespace CS 00087 00088 00113 template<typename Tag> 00114 struct iStringSetBase : public virtual iBase 00115 { 00116 typedef Tag TagType; 00117 00118 //SCF_INTERFACE(iStringSet, 2,0,0); 00125 virtual CS::StringID<Tag> Request(const char*) = 0; 00126 00132 virtual const char* Request(CS::StringID<Tag>) const = 0; 00133 00137 virtual bool Contains(char const*) const = 0; 00138 00144 virtual bool Contains(CS::StringID<Tag>) const = 0; 00145 00150 virtual bool Delete(char const*) = 0; 00151 00156 virtual bool Delete(CS::StringID<Tag>) = 0; 00157 00162 virtual void Empty() = 0; 00163 00168 CS_DEPRECATED_METHOD_MSG("Use Empty() instead.") 00169 virtual void Clear() = 0; 00170 00172 virtual size_t GetSize () const = 0; 00173 00179 virtual bool IsEmpty() const = 0; 00180 }; 00181 00182 #define CS_ISTRINGSSET_SCF_VERSION(Class) SCF_INTERFACE(Class, 2, 0, 0) 00183 00184 namespace CS 00185 { 00186 namespace StringSetTag 00187 { 00188 struct General; 00189 } // namespace StringSetTag 00190 } // namespace CS 00191 00192 #if defined(SWIG) 00193 // Templated classes must be declared before we actually use 00194 // them, so we have to declare the following here. 00195 %template(iGeneralStringSetBase) iStringSetBase<CS::StringSetTag::General>; 00196 #endif 00197 00199 struct iStringSet : public iStringSetBase<CS::StringSetTag::General> 00200 { 00201 CS_ISTRINGSSET_SCF_VERSION(iStringSet); 00202 }; 00203 00205 typedef CS::StringID<CS::StringSetTag::General> csStringID; 00207 csStringID const csInvalidStringID = CS::InvalidStringID<CS::StringSetTag::General> (); 00208 00211 #endif // __CS_IUTIL_STRINGSET_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1