00001 /* 00002 Copyright (C) 1999 Carsten Winkelholz 00003 00004 Address: FGAN Forschungsgesellschaft fr Angewandte Naturwissenschaften e. V. 00005 Neuenahrer Str. 20 00006 D - 53343 Wachtberg 00007 00008 Email: winkelholz@fgan.de 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 */ 00024 00025 00026 #ifndef IDMAPC_H 00027 #define IDMAPC_H 00028 00029 00030 #include <assert.h> 00031 #include "arrayc.h" 00032 00033 #include "../oawconfig.h" 00034 00035 OAW_BEGIN_NAMESPACE 00036 00037 template <class Typ> 00038 class IDMapC 00039 { 00040 public: 00041 00042 IDMapC(){ 00043 m_occupied.SetBlankAndClear(0); 00044 } 00045 00046 IDMapC(const IDMapC<Typ>& a) 00047 { 00048 m_freeIndexes = a.m_freeIndexes; 00049 m_occupied=a.m_occupied; 00050 m_type = a.m_type; 00051 } 00052 00053 inline long size() const {return m_type.size();} 00054 00055 long add(const Typ& t){ 00056 long ix; 00057 if(m_freeIndexes.size()>0){ 00058 m_freeIndexes.pop_back(ix); 00059 m_type[ix]=t; 00060 m_occupied[ix]=1; 00061 }else{ 00062 ix=m_type.size(); 00063 m_type.push_back(t); 00064 m_occupied.push_back(1); 00065 } 00066 return ix; 00067 } 00068 00069 inline const Typ& get(long i) const{ 00070 if((i>=0)&&(i<m_occupied.size())){ 00071 if(m_occupied.get(i)){return m_type.get(i);} 00072 } 00073 return m_blanc; 00074 } 00075 00076 00077 inline void set(long i,const Typ& t){ 00078 if(i<m_occupied.size()){ 00079 m_occupied[i]=1; 00080 m_type[i]=t; 00081 m_freeIndexes.RemoveElement(i); 00082 }else{ 00083 long l = m_occupied.size(); 00084 m_occupied.set(i,1); 00085 m_type.set(i,t); 00086 long j; 00087 for(j=l;j<m_occupied.size()-1;j++){ 00088 m_freeIndexes.push_back(j); 00089 } 00090 } 00091 } 00092 00093 inline long GetID(const Typ& t) const{ 00094 return m_type.GetIndexOf(t); 00095 } 00096 00097 void Remove(long ix){ 00098 if(ix>=m_occupied.size()){return;} 00099 m_occupied[ix]=0; 00100 m_type[ix]=m_blanc; 00101 m_freeIndexes.push_back(ix); 00102 } 00103 00104 const IDMapC<Typ>& operator = (const IDMapC<Typ>& a){ 00105 if (this == &a) return *this; 00106 m_occupied.push_back(1); 00107 m_occupied.push_back(1); 00108 m_occupied=a.m_occupied; 00109 m_type = a.m_type; 00110 m_freeIndexes = a.m_freeIndexes; 00111 return *this; 00112 } 00113 00114 00115 void SetBlanc(const Typ& t){ 00116 m_type.SetBlankAndClear(m_blanc); 00117 m_blanc = t; 00118 } 00119 00120 protected: 00121 ArrayC<long> m_freeIndexes; 00122 ArrayC<short> m_occupied; 00123 ArrayC<Typ> m_type; 00124 Typ m_blanc; 00125 }; 00126 00127 OAW_END_NAMESPACE 00128 00129 00130 #endif 00131 00132 00133 00134 00135 00136
1.3-rc2