Cleaner.inl

Go to the documentation of this file.
00001 //Copyright (c) 2004-2005, Baris Sumengen
00002 //All rights reserved.
00003 //
00004 // CIMPL Matrix Performance Library
00005 //
00006 //Redistribution and use in source and binary
00007 //forms, with or without modification, are
00008 //permitted provided that the following
00009 //conditions are met:
00010 //
00011 //    * No commercial use is allowed. 
00012 //    This software can only be used
00013 //    for non-commercial purposes. This 
00014 //    distribution is mainly intended for
00015 //    academic research and teaching.
00016 //    * Redistributions of source code must
00017 //    retain the above copyright notice, this
00018 //    list of conditions and the following
00019 //    disclaimer.
00020 //    * Redistributions of binary form must
00021 //    mention the above copyright notice, this
00022 //    list of conditions and the following
00023 //    disclaimer in a clearly visible part 
00024 //    in associated product manual, 
00025 //    readme, and web site of the redistributed 
00026 //    software.
00027 //    * Redistributions in binary form must
00028 //    reproduce the above copyright notice,
00029 //    this list of conditions and the
00030 //    following disclaimer in the
00031 //    documentation and/or other materials
00032 //    provided with the distribution.
00033 //    * The name of Baris Sumengen may not be
00034 //    used to endorse or promote products
00035 //    derived from this software without
00036 //    specific prior written permission.
00037 //
00038 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
00039 //HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00040 //EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
00041 //NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00042 //MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00043 //PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00044 //CONTRIBUTORS BE LIABLE FOR ANY
00045 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00046 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00047 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00048 //OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00049 //DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00050 //HOWEVER CAUSED AND ON ANY THEORY OF
00051 //LIABILITY, WHETHER IN CONTRACT, STRICT
00052 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00053 //OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00054 //OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00055 //POSSIBILITY OF SUCH DAMAGE.
00056 
00057 
00058 
00059 namespace CIMPL
00060 {
00061 
00062 
00063 
00064 template< class T > mli Cleaner<T>::refCountData;
00065 //template< class T > mli Cleaner<T>::refCountDataPtrs;
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         // increase data ref count
00077         mli::const_iterator tempItData = refCountData.find((long long int)data);        // check existance
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         // increase columns ref count
00104         mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
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         // increase data ref count
00130         mli::const_iterator tempItData = refCountData.find((long long int)data);        // check existance
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         // increase columns ref count
00147         mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
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                 // Take care of (delete) data ref count
00175                 mli::const_iterator tempItData = refCountData.find((long long int)data);        // check existance
00176                 if( tempItData == refCountData.end() )
00177                 {
00178                         // do nothing. Probably issue a warning.
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                 // Take care of (delete) columns ref count
00201                 mli::const_iterator tempItRows = refCountColumns.find((long long int)columns);  // check existance
00202                 if( tempItRows == refCountColumns.end() )
00203                 {
00204                         // do nothing. Probably issue a warning.
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 }; //namespace
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 
00304 
00305 

Generated on Thu Jan 20 08:43:40 2005 for CIMPL by  doxygen 1.3.9.1