Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
statistics.hpp
Go to the documentation of this file.
00001 //*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef STATISTICS_HPP
00027 #define STATISTICS_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #include "infinint.hpp"
00032 #include "user_interaction.hpp"
00033 
00034 extern "C"
00035 {
00036 #if MUTEX_WORKS
00037 #if HAVE_PTHREAD_H
00038 #include <pthread.h>
00039 #endif
00040 #endif
00041 }
00042 
00045 
00046 #if MUTEX_WORKS
00047 #define LOCK_IN pthread_mutex_lock(&lock_mutex)
00048 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex)
00049 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex))
00050 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex))
00051 #else
00052 #define LOCK_IN //
00053 #define LOCK_OUT //
00054 #define LOCK_IN_CONST //
00055 #define LOCK_OUT_CONST //
00056 #endif
00057 
00058 namespace libdar
00059 {
00060 
00062 
00066     // are their meaning see the archive class constructor and methods documentation
00068     class statistics
00069     {
00070     public:
00072 
00078     statistics(bool lock = true) { init(lock); clear(); };
00079     statistics(const statistics & ref) { copy_from(ref); };
00080     const statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; };
00081 
00083     ~statistics() { detruit(); };
00084 
00086         void clear();
00087 
00089         infinint total() const;
00090 
00091     void incr_treated() { (this->*increment)(&treated); };       
00092     void incr_hard_links() { (this->*increment)(&hard_links); }; 
00093     void incr_skipped() { (this->*increment)(&skipped); };       
00094     void incr_ignored() { (this->*increment)(&ignored); };       
00095     void incr_tooold() { (this->*increment)(&tooold); };         
00096     void incr_errored() { (this->*increment)(&errored); };       
00097     void incr_deleted() { (this->*increment)(&deleted); };       
00098     void incr_ea_treated() { (this->*increment)(&ea_treated); }; 
00099     void incr_fsa_treated() { (this->*increment)(&fsa_treated); }; 
00100 
00101     void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); };  
00102     void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); };  
00103     void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); };  
00104     void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); }; 
00105 
00106     void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); };
00107     void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); };
00108     void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); };
00109     void sub_from_fsa_treated(const infinint & val) { (this->*sub_from)(&fsa_treated, val); };
00110 
00111     infinint get_treated() const { return (this->*returned)(&treated); };     
00112     infinint get_hard_links() const { return (this->*returned)(&hard_links); }; 
00113     infinint get_skipped() const { return (this->*returned)(&skipped); };     
00114     infinint get_ignored() const { return (this->*returned)(&ignored); };     
00115     infinint get_tooold() const { return (this->*returned)(&tooold); };       
00116     infinint get_errored() const { return (this->*returned)(&errored); };     
00117     infinint get_deleted() const { return (this->*returned)(&deleted); };     
00118     infinint get_ea_treated() const { return (this->*returned)(&ea_treated); };  
00119     infinint get_byte_amount() const { return (this->*returned)(&byte_amount); };  
00120     infinint get_fsa_treated() const { return (this->*returned)(&fsa_treated); }; 
00121 
00122     void decr_treated() { (this->*decrement)(&treated); };        
00123     void decr_hard_links() { (this->*decrement)(&hard_links); };  
00124     void decr_skipped() { (this->*decrement)(&skipped); };        
00125     void decr_ignored() { (this->*decrement)(&ignored); };        
00126     void decr_tooold() { (this->*decrement)(&tooold); };          
00127     void decr_errored() { (this->*decrement)(&errored); };        
00128     void decr_deleted() { (this->*decrement)(&deleted); };        
00129     void decr_ea_treated() { (this->*decrement)(&ea_treated); };  
00130     void decr_fsa_treated() { (this->*decrement)(&fsa_treated); };
00131 
00132     void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); }; 
00133 
00134         // debuging method
00135     void dump(user_interaction & dialog) const;
00136 
00137     private:
00138 #if MUTEX_WORKS
00139     pthread_mutex_t lock_mutex;   
00140 #endif
00141     bool locking;           
00142 
00143         infinint treated;       
00144         infinint hard_links;    
00145         infinint skipped;       
00146         infinint ignored;       
00147         infinint tooold;        
00148         infinint errored;       
00149         infinint deleted;       
00150         infinint ea_treated;    
00151     infinint byte_amount;   
00152     infinint fsa_treated;   
00153 
00154 
00155     void (statistics::*increment)(infinint * var);                    
00156     void (statistics::*add_to)(infinint * var, const infinint & val); 
00157     infinint (statistics::*returned)(const infinint * var) const;     
00158     void (statistics::*decrement)(infinint * var);                    
00159     void (statistics::*set_to)(infinint * var, const infinint & val); 
00160     void (statistics::*sub_from)(infinint *var, const infinint & val);
00161 
00162     void increment_locked(infinint * var)
00163     {
00164         LOCK_IN;
00165         (*var)++;
00166         LOCK_OUT;
00167     };
00168 
00169     void increment_unlocked(infinint * var)
00170     {
00171         (*var)++;
00172     }
00173 
00174     void add_to_locked(infinint * var, const infinint & val)
00175     {
00176         LOCK_IN;
00177         (*var) += val;
00178         LOCK_OUT;
00179     }
00180 
00181     void add_to_unlocked(infinint *var, const infinint & val)
00182     {
00183         (*var) += val;
00184     }
00185 
00186     infinint returned_locked(const infinint * var) const
00187     {
00188         infinint ret;
00189 
00190         LOCK_IN_CONST;
00191         ret = *var;
00192         LOCK_OUT_CONST;
00193 
00194         return ret;
00195     };
00196 
00197     infinint returned_unlocked(const infinint * var) const
00198     {
00199         return *var;
00200     };
00201 
00202     void decrement_locked(infinint * var)
00203     {
00204         LOCK_IN;
00205         (*var)--;
00206         LOCK_OUT;
00207     }
00208 
00209     void decrement_unlocked(infinint * var)
00210     {
00211         (*var)--;
00212     }
00213 
00214     void set_to_locked(infinint *var, const infinint & val)
00215     {
00216         LOCK_IN;
00217         (*var) = val;
00218         LOCK_OUT;
00219     }
00220 
00221     void set_to_unlocked(infinint *var, const infinint & val)
00222     {
00223         *var = val;
00224     }
00225 
00226     void sub_from_unlocked(infinint *var, const infinint & val)
00227     {
00228         *var -= val;
00229     }
00230 
00231     void sub_from_locked(infinint *var, const infinint & val)
00232     {
00233         LOCK_IN;
00234         *var -= val;
00235         LOCK_OUT;
00236     }
00237 
00238 
00239     void init(bool lock); // set locking & mutex
00240     void detruit();       // release and free the mutex
00241     void copy_from(const statistics & ref); // reset mutex and copy data from the object of reference
00242 
00243     };
00244 
00245 } // end of namespace
00246 
00248 
00249 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines