Cleaner< T > Class Template Reference

#include <Cleaner.h>

List of all members.


Detailed Description

template<class T>
class Cleaner< T >

Reference counting Garbage Collector (sort of) for Array, Matrix and Vector data.

Definition at line 83 of file Cleaner.h.

Public Member Functions

 Cleaner ()
 Cleaner (T *_data)
 Creates a cleaner object for Array class (uses only the data pointer).
 Cleaner (Vector< T > *_columns)
 Creates a cleaner object for SubMatrix class (uses only the columns pointer).
 Cleaner (T *_data, Vector< T > *_columns)
 ~Cleaner ()
 Clear or reduce count of the memory ref.

Static Public Member Functions

void Display (void)
 Display memory references.
void Display (char *s)

Protected Attributes

T * data
Vector< T > * columns

Static Protected Attributes

mli refCountData
mli refCountColumns


Constructor & Destructor Documentation

template<class T>
Cleaner< T >::Cleaner  )  [inline]
 

Definition at line 94 of file Cleaner.h.

00095     {
00096         data = 0;
00097         columns = 0;
00098         cout << "Empty Cleaner created" << endl;
00099     }

template<class T>
Cleaner< T >::Cleaner T *  _data  )  [explicit]
 

Creates a cleaner object for Array class (uses only the data pointer).

Definition at line 67 of file Cleaner.inl.

References Cleaner< T >::columns, Cleaner< T >::data, Cleaner< T >::refCountData, and Utility::Warning().

00068 {
00069     data = _data;
00070     columns = 0;
00071     
00072     // increase data ref count
00073     mli::const_iterator tempItData = refCountData.find((long long int)data);    // check existance
00074     if( tempItData == refCountData.end() )
00075     {
00076         refCountData[(long long int)data] = 1;
00077     }
00078     else
00079     {
00080         if(refCountData[(long long int)data] < 0)
00081         {
00082             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00083             Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00084         }
00085         refCountData[(long long int)data]++;
00086     }
00087     
00088 }

template<class T>
Cleaner< T >::Cleaner Vector< T > *  _columns  )  [explicit]
 

Creates a cleaner object for SubMatrix class (uses only the columns pointer).

Definition at line 93 of file Cleaner.inl.

References Cleaner< T >::columns, Cleaner< T >::data, Cleaner< T >::refCountColumns, and Utility::Warning().

00094 {
00095 
00096     data = 0;
00097     columns = _columns;
00098 
00099     // increase columns ref count
00100     mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
00101     if( tempItRows == refCountColumns.end() )
00102     {
00103         refCountColumns[(long long int)columns] = 1;
00104     }
00105     else
00106     {
00107         if(refCountColumns[(long long int)columns] < 0)
00108         {
00109             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00110             Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00111         }
00112         refCountColumns[(long long int)columns]++;
00113     }
00114     
00115 
00116 }

template<class T>
Cleaner< T >::Cleaner T *  _data,
Vector< T > *  _columns
 

Definition at line 120 of file Cleaner.inl.

References Cleaner< T >::columns, Cleaner< T >::data, Cleaner< T >::refCountColumns, Cleaner< T >::refCountData, and Utility::Warning().

00121 {
00122     data = _data;
00123     columns = _columns;
00124     
00125     // increase data ref count
00126     mli::const_iterator tempItData = refCountData.find((long long int)data);    // check existance
00127     if( tempItData == refCountData.end() )
00128     {
00129         refCountData[(long long int)data] = 1;
00130     }
00131     else
00132     {
00133         if(refCountData[(long long int)data] < 0)
00134         {
00135             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00136             Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00137         }
00138         refCountData[(long long int)data]++;
00139     }
00140     
00141     
00142     // increase columns ref count
00143     mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
00144     if( tempItRows == refCountColumns.end() )
00145     {
00146         refCountColumns[(long long int)columns] = 1;
00147     }
00148     else
00149     {
00150         if(refCountColumns[(long long int)columns] < 0)
00151         {
00152             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00153             Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00154         }
00155         refCountColumns[(long long int)columns]++;
00156     }
00157     
00158 
00159 
00160 }

template<class T>
Cleaner< T >::~Cleaner  ) 
 

Clear or reduce count of the memory ref.

Definition at line 166 of file Cleaner.inl.

References Cleaner< T >::columns, Cleaner< T >::data, Cleaner< T >::refCountColumns, Cleaner< T >::refCountData, and Utility::Warning().

00167 {
00168 
00169     if(data != 0){
00170         // Take care of (delete) data ref count
00171         mli::const_iterator tempItData = refCountData.find((long long int)data);    // check existance
00172         if( tempItData == refCountData.end() )
00173         {
00174             // do nothing. Probably issue a warning.
00175             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00176             Utility::Warning("Weird! data does not exist in memory hash. Something might be wrong.");
00177         }
00178         else if(refCountData[(long long int)data] == 1)
00179         {
00180             refCountData.erase((long long int)data);
00181             delete [] data;
00182         }
00183         else if(refCountData[(long long int)data] <= 0)
00184         {
00185             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00186             Utility::Warning("Weird! data ref count is negative in memory hash. Something might be wrong.");
00187         }
00188         else
00189         {
00190             refCountData[(long long int)data]--;
00191 
00192         }
00193     }
00194     
00195     if(columns != 0){
00196         // Take care of (delete) columns ref count
00197         mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
00198         if( tempItRows == refCountColumns.end() )
00199         {
00200             // do nothing. Probably issue a warning.
00201             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00202             Utility::Warning("Weird! columns does not exist in memory hash. Something might be wrong.");
00203         }
00204         else if(refCountColumns[(long long int)columns] == 1)
00205         {
00206             refCountColumns.erase((long long int)columns);
00207             delete [] columns;
00208         }
00209         else if(refCountColumns[(long long int)columns] <= 0)
00210         {
00211             cout << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00212             Utility::Warning("Weird! columns ref count is negative in memory hash. Something might be wrong.");
00213         }
00214         else
00215         {
00216             refCountColumns[(long long int)columns]--;
00217         }
00218 
00219     }
00220 
00221 
00222 }


Member Function Documentation

template<class T>
void Cleaner< T >::Display char *  s  )  [static]
 

Definition at line 255 of file Cleaner.inl.

References Cleaner< T >::refCountColumns, and Cleaner< T >::refCountData.

00256 {
00257     cout << endl;
00258     cout << "======MEMORY DISPLAY (" << s << ") ======" << endl;
00259     cout << "Memory references for (data):" << endl;
00260     for( mli::const_iterator it1 = refCountData.begin(); 
00261             it1 != refCountData.end(); it1++ )
00262     {
00263         cout << it1->first << '\t' << it1->second << endl;
00264     
00265     }
00266 
00267     cout << endl;
00268     cout << "Memory references for (columns):" << endl;
00269     for( mli::const_iterator it2 = refCountColumns.begin(); 
00270             it2 != refCountColumns.end(); it2++ )
00271     {
00272         cout << it2->first << '\t' << it2->second << endl;
00273     }
00274     cout << "===========END============" << endl;
00275     cout << endl;
00276 }

template<class T>
void Cleaner< T >::Display void   )  [static]
 

Display memory references.

Definition at line 230 of file Cleaner.inl.

References Cleaner< T >::refCountColumns, and Cleaner< T >::refCountData.

00231 {
00232     cout << endl;
00233     cout << "======MEMORY DISPLAY======" << endl;
00234     cout << "Memory references for (data):" << endl;
00235     for( mli::const_iterator it1 = refCountData.begin(); 
00236             it1 != refCountData.end(); it1++ )
00237     {
00238         cout << it1->first << '\t' << it1->second << endl;
00239     
00240     }
00241 
00242     cout << endl;
00243     cout << "Memory references for (columns):" << endl;
00244     for( mli::const_iterator it2 = refCountColumns.begin(); 
00245             it2 != refCountColumns.end(); it2++ )
00246     {
00247         cout << it2->first << '\t' << it2->second << endl;
00248     }
00249     cout << "===========END============" << endl;
00250     cout << endl;
00251 }


Member Data Documentation

template<class T>
Vector<T>* Cleaner< T >::columns [protected]
 

Definition at line 88 of file Cleaner.h.

Referenced by Cleaner< T >::Cleaner(), and Cleaner< T >::~Cleaner().

template<class T>
T* Cleaner< T >::data [protected]
 

Definition at line 87 of file Cleaner.h.

Referenced by Cleaner< T >::Cleaner(), and Cleaner< T >::~Cleaner().

template<class T>
mli Cleaner< T >::refCountColumns [static, protected]
 

Definition at line 62 of file Cleaner.inl.

Referenced by Cleaner< T >::Cleaner(), Cleaner< T >::Display(), and Cleaner< T >::~Cleaner().

template<class T>
mli Cleaner< T >::refCountData [static, protected]
 

Definition at line 60 of file Cleaner.inl.

Referenced by Cleaner< T >::Cleaner(), Cleaner< T >::Display(), and Cleaner< T >::~Cleaner().


The documentation for this class was generated from the following files:
CIMPL 0.1 Code Reference. Copyright © 2004, Baris Sumengen. All rights reserved.