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 
00060 template< class T > mli Cleaner<T>::refCountData;
00061 //template< class T > mli Cleaner<T>::refCountDataPtrs;
00062 template< class T > mli Cleaner<T>::refCountColumns;
00063 
00064 
00066 template< class T >
00067 Cleaner<T>::Cleaner(T *_data)
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 }
00089 
00090 
00092 template< class T >
00093 Cleaner<T>::Cleaner(Vector<T>* _columns)
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 }
00117 
00118 
00119 template< class T >
00120 Cleaner<T>::Cleaner(T *_data, Vector<T>* _columns)
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 }
00161 
00162 
00163 
00165 template< class T >
00166 Cleaner<T>::~Cleaner()
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 }
00223 
00224 
00225 
00226 
00227 
00229 template< class T >
00230 void Cleaner<T>::Display(void)
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 }
00252 
00253 
00254 template< class T >
00255 void Cleaner<T>::Display(char * s)
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 }
00277 
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 

CIMPL 0.1 Code Reference. Copyright © 2004, Baris Sumengen. All rights reserved.