00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 namespace CIMPL
00060 {
00061
00062
00063
00064 template< class T > mli Cleaner<T>::refCountData;
00065
00066 template< class T > mli Cleaner<T>::refCountColumns;
00067
00068
00070 template< class T >
00071 Cleaner<T>::Cleaner(T *_data)
00072 {
00073 data = _data;
00074 columns = 0;
00075
00076
00077 mli::const_iterator tempItData = refCountData.find((long long int)data);
00078 if( tempItData == refCountData.end() )
00079 {
00080 refCountData[(long long int)data] = 1;
00081 }
00082 else
00083 {
00084 if(refCountData[(long long int)data] < 0)
00085 {
00086 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00087 Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00088 }
00089 refCountData[(long long int)data]++;
00090 }
00091
00092 }
00093
00094
00096 template< class T >
00097 Cleaner<T>::Cleaner(Vector<T>* _columns)
00098 {
00099
00100 data = 0;
00101 columns = _columns;
00102
00103
00104 mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);
00105 if( tempItRows == refCountColumns.end() )
00106 {
00107 refCountColumns[(long long int)columns] = 1;
00108 }
00109 else
00110 {
00111 if(refCountColumns[(long long int)columns] < 0)
00112 {
00113 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00114 Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00115 }
00116 refCountColumns[(long long int)columns]++;
00117 }
00118
00119
00120 }
00121
00122
00123 template< class T >
00124 Cleaner<T>::Cleaner(T *_data, Vector<T>* _columns)
00125 {
00126 data = _data;
00127 columns = _columns;
00128
00129
00130 mli::const_iterator tempItData = refCountData.find((long long int)data);
00131 if( tempItData == refCountData.end() )
00132 {
00133 refCountData[(long long int)data] = 1;
00134 }
00135 else
00136 {
00137 if(refCountData[(long long int)data] < 0)
00138 {
00139 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00140 Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00141 }
00142 refCountData[(long long int)data]++;
00143 }
00144
00145
00146
00147 mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);
00148 if( tempItRows == refCountColumns.end() )
00149 {
00150 refCountColumns[(long long int)columns] = 1;
00151 }
00152 else
00153 {
00154 if(refCountColumns[(long long int)columns] < 0)
00155 {
00156 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00157 Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00158 }
00159 refCountColumns[(long long int)columns]++;
00160 }
00161
00162
00163
00164 }
00165
00166
00167
00169 template< class T >
00170 Cleaner<T>::~Cleaner()
00171 {
00172
00173 if(data != 0){
00174
00175 mli::const_iterator tempItData = refCountData.find((long long int)data);
00176 if( tempItData == refCountData.end() )
00177 {
00178
00179 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00180 Utility::Warning("Weird! data does not exist in memory hash. Something might be wrong.");
00181 }
00182 else if(refCountData[(long long int)data] == 1)
00183 {
00184 refCountData.erase((long long int)data);
00185 delete [] data;
00186 }
00187 else if(refCountData[(long long int)data] <= 0)
00188 {
00189 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00190 Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00191 }
00192 else
00193 {
00194 refCountData[(long long int)data]--;
00195
00196 }
00197 }
00198
00199 if(columns != 0){
00200
00201 mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);
00202 if( tempItRows == refCountColumns.end() )
00203 {
00204
00205 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00206 Utility::Warning("Weird! columns does not exist in memory hash. Something might be wrong.");
00207 }
00208 else if(refCountColumns[(long long int)columns] == 1)
00209 {
00210 refCountColumns.erase((long long int)columns);
00211 delete [] columns;
00212 }
00213 else if(refCountColumns[(long long int)columns] <= 0)
00214 {
00215 cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00216 Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00217 }
00218 else
00219 {
00220 refCountColumns[(long long int)columns]--;
00221 }
00222
00223 }
00224
00225
00226 }
00227
00228
00229
00230
00231
00233 template< class T >
00234 void Cleaner<T>::Display(void)
00235 {
00236 cout << endl;
00237 cout << "======MEMORY DISPLAY======" << endl;
00238 cout << "Memory references for (data):" << endl;
00239 for( mli::const_iterator it1 = refCountData.begin();
00240 it1 != refCountData.end(); it1++ )
00241 {
00242 cout << it1->first << '\t' << it1->second << endl;
00243
00244 }
00245
00246 cout << endl;
00247 cout << "Memory references for (columns):" << endl;
00248 for( mli::const_iterator it2 = refCountColumns.begin();
00249 it2 != refCountColumns.end(); it2++ )
00250 {
00251 cout << it2->first << '\t' << it2->second << endl;
00252 }
00253 cout << "===========END============" << endl;
00254 cout << endl;
00255 }
00256
00257
00258 template< class T >
00259 void Cleaner<T>::Display(char * s)
00260 {
00261 cout << endl;
00262 cout << "======MEMORY DISPLAY (" << s << ") ======" << endl;
00263 cout << "Memory references for (data):" << endl;
00264 for( mli::const_iterator it1 = refCountData.begin();
00265 it1 != refCountData.end(); it1++ )
00266 {
00267 cout << it1->first << '\t' << it1->second << endl;
00268
00269 }
00270
00271 cout << endl;
00272 cout << "Memory references for (columns):" << endl;
00273 for( mli::const_iterator it2 = refCountColumns.begin();
00274 it2 != refCountColumns.end(); it2++ )
00275 {
00276 cout << it2->first << '\t' << it2->second << endl;
00277 }
00278 cout << "===========END============" << endl;
00279 cout << endl;
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 };
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305