csutil/nobjvec.h
Go to the documentation of this file.
00001 /* 00002 Crystal Space: Named Object Vector class 00003 Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_NOBJVEC_H__ 00021 #define __CS_NOBJVEC_H__ 00022 00023 //----------------------------------------------------------------------------- 00024 // Note *1*: The explicit "this->" is needed by modern compilers (such as gcc 00025 // 3.4.x) which distinguish between dependent and non-dependent names in 00026 // templates. See: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html 00027 //----------------------------------------------------------------------------- 00028 00029 #include "csextern.h" 00030 #include "csutil/refarr.h" 00031 #include "csutil/weakrefarr.h" 00032 #include "iutil/object.h" 00033 00038 /* Workaround for deprecation warnings caused by types used as the template 00039 * parameter */ 00040 #include "csutil/deprecated_warn_off.h" 00041 00051 template <class T> 00052 class csRefArrayObject : public csRefArray<T> 00053 { 00054 public: 00055 csRefArrayObject (int ilimit = 0, int ithreshold = 0) 00056 : csRefArray<T> (ilimit, ithreshold) 00057 { 00058 } 00059 00060 size_t GetIndexByName (const char* name) const 00061 { 00062 size_t i; 00063 for (i = 0 ; i < this->GetSize () ; i++) // see *1* 00064 { 00065 T* o = (*this)[i]; 00066 const char* n = o->QueryObject ()->GetName (); 00067 if (n && !strcmp (n, name)) 00068 return i; 00069 } 00070 return csArrayItemNotFound; 00071 } 00072 00073 T* FindByName (const char* name) const 00074 { 00075 size_t i = GetIndexByName (name); 00076 if (i != csArrayItemNotFound) 00077 return (*this)[i]; 00078 else 00079 return 0; 00080 } 00081 }; 00082 00091 template <class T> 00092 class csWeakRefArrayObject : public csWeakRefArray<T> 00093 { 00094 public: 00095 csWeakRefArrayObject (int ilimit = 0, int ithreshold = 0) 00096 : csWeakRefArray<T> (ilimit, ithreshold) 00097 { 00098 } 00099 00100 size_t GetIndexByName (const char* name) const 00101 { 00102 size_t i; 00103 for (i = 0 ; i < this->GetSize () ; i++) // see *1* 00104 { 00105 T* o = (*this)[i]; 00106 const char* n = o->QueryObject ()->GetName (); 00107 if (n && !strcmp (n, name)) 00108 return i; 00109 } 00110 return csArrayItemNotFound; 00111 } 00112 00113 T* FindByName (const char* name) const 00114 { 00115 size_t i = GetIndexByName (name); 00116 if (i != csArrayItemNotFound) 00117 return (*this)[i]; 00118 else 00119 return 0; 00120 } 00121 }; 00122 00125 #include "csutil/deprecated_warn_on.h" 00126 00127 #endif // __CS_NOBJVEC_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1