Disk ARchive  2.4.15
statistics.hpp
Go to the documentation of this file.
1 //*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef STATISTICS_HPP
27 #define STATISTICS_HPP
28 
29 #include "../my_config.h"
30 
31 #include "infinint.hpp"
32 #include "user_interaction.hpp"
33 
34 extern "C"
35 {
36 #if MUTEX_WORKS
37 #if HAVE_PTHREAD_H
38 #include <pthread.h>
39 #endif
40 #endif
41 }
42 
45 
46 #if MUTEX_WORKS
47 #define LOCK_IN pthread_mutex_lock(&lock_mutex)
48 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex)
49 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex))
50 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex))
51 #else
52 #define LOCK_IN //
53 #define LOCK_OUT //
54 #define LOCK_IN_CONST //
55 #define LOCK_OUT_CONST //
56 #endif
57 
58 namespace libdar
59 {
60 
62 
66  // are their meaning see the archive class constructor and methods documentation
68  class statistics
69  {
70  public:
72 
78  statistics(bool lock = true) { init(lock); clear(); };
79  statistics(const statistics & ref) { copy_from(ref); };
80  const statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; };
81 
83  ~statistics() { detruit(); };
84 
86  void clear();
87 
89  infinint total() const;
90 
91  void incr_treated() { (this->*increment)(&treated); };
92  void incr_hard_links() { (this->*increment)(&hard_links); };
93  void incr_skipped() { (this->*increment)(&skipped); };
94  void incr_ignored() { (this->*increment)(&ignored); };
95  void incr_tooold() { (this->*increment)(&tooold); };
96  void incr_errored() { (this->*increment)(&errored); };
97  void incr_deleted() { (this->*increment)(&deleted); };
98  void incr_ea_treated() { (this->*increment)(&ea_treated); };
99 
100  void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); };
101  void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); };
102  void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); };
103  void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); };
104 
105  void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); };
106  void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); };
107  void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); };
108 
109  infinint get_treated() const { return (this->*returned)(&treated); };
110  infinint get_hard_links() const { return (this->*returned)(&hard_links); };
111  infinint get_skipped() const { return (this->*returned)(&skipped); };
112  infinint get_ignored() const { return (this->*returned)(&ignored); };
113  infinint get_tooold() const { return (this->*returned)(&tooold); };
114  infinint get_errored() const { return (this->*returned)(&errored); };
115  infinint get_deleted() const { return (this->*returned)(&deleted); };
116  infinint get_ea_treated() const { return (this->*returned)(&ea_treated); };
117  infinint get_byte_amount() const { return (this->*returned)(&byte_amount); };
118 
119  void decr_treated() { (this->*decrement)(&treated); };
120  void decr_hard_links() { (this->*decrement)(&hard_links); };
121  void decr_skipped() { (this->*decrement)(&skipped); };
122  void decr_ignored() { (this->*decrement)(&ignored); };
123  void decr_tooold() { (this->*decrement)(&tooold); };
124  void decr_errored() { (this->*decrement)(&errored); };
125  void decr_deleted() { (this->*decrement)(&deleted); };
126  void decr_ea_treated() { (this->*decrement)(&ea_treated); };
127 
128  void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); };
129 
130  // debuging method
131  void dump(user_interaction & dialog) const;
132 
133  private:
134 #if MUTEX_WORKS
135  pthread_mutex_t lock_mutex;
136 #endif
137  bool locking;
138 
139  infinint treated;
140  infinint hard_links;
141  infinint skipped;
142  infinint ignored;
143  infinint tooold;
144  infinint errored;
145  infinint deleted;
146  infinint ea_treated;
147  infinint byte_amount;
148 
149 
150  void (statistics::*increment)(infinint * var);
151  void (statistics::*add_to)(infinint * var, const infinint & val);
152  infinint (statistics::*returned)(const infinint * var) const;
153  void (statistics::*decrement)(infinint * var);
154  void (statistics::*set_to)(infinint * var, const infinint & val);
155  void (statistics::*sub_from)(infinint *var, const infinint & val);
156 
157  void increment_locked(infinint * var)
158  {
159  LOCK_IN;
160  (*var)++;
161  LOCK_OUT;
162  };
163 
164  void increment_unlocked(infinint * var)
165  {
166  (*var)++;
167  }
168 
169  void add_to_locked(infinint * var, const infinint & val)
170  {
171  LOCK_IN;
172  (*var) += val;
173  LOCK_OUT;
174  }
175 
176  void add_to_unlocked(infinint *var, const infinint & val)
177  {
178  (*var) += val;
179  }
180 
181  infinint returned_locked(const infinint * var) const
182  {
183  infinint ret;
184 
185  LOCK_IN_CONST;
186  ret = *var;
187  LOCK_OUT_CONST;
188 
189  return ret;
190  };
191 
192  infinint returned_unlocked(const infinint * var) const
193  {
194  return *var;
195  };
196 
197  void decrement_locked(infinint * var)
198  {
199  LOCK_IN;
200  (*var)--;
201  LOCK_OUT;
202  }
203 
204  void decrement_unlocked(infinint * var)
205  {
206  (*var)--;
207  }
208 
209  void set_to_locked(infinint *var, const infinint & val)
210  {
211  LOCK_IN;
212  (*var) = val;
213  LOCK_OUT;
214  }
215 
216  void set_to_unlocked(infinint *var, const infinint & val)
217  {
218  *var = val;
219  }
220 
221  void sub_from_unlocked(infinint *var, const infinint & val)
222  {
223  *var -= val;
224  }
225 
226  void sub_from_locked(infinint *var, const infinint & val)
227  {
228  LOCK_IN;
229  *var -= val;
230  LOCK_OUT;
231  }
232 
233 
234  void init(bool lock); // set locking & mutex
235  void detruit(); // release and free the mutex
236  void copy_from(const statistics & ref); // reset mutex and copy data from the object of reference
237 
238  };
239 
240 } // end of namespace
241 
243 
244 #endif
void decr_deleted()
decrement by one the errored counter
Definition: statistics.hpp:125
infinint get_skipped() const
returns the current value of the hard_links counter
Definition: statistics.hpp:111
infinint get_deleted() const
returns the current value of the errored counter
Definition: statistics.hpp:115
void decr_errored()
decrement by one the toold counter
Definition: statistics.hpp:124
void decr_skipped()
decrement by one the hard_links counter
Definition: statistics.hpp:121
void clear()
reset counters to zero
void decr_tooold()
decrement by one the ignored counter
Definition: statistics.hpp:123
the deleted file entry
Definition: catalogue.hpp:906
void incr_deleted()
increment by one the errored counter
Definition: statistics.hpp:97
infinint get_ea_treated() const
returns the current value of the deleted counter
Definition: statistics.hpp:116
void add_to_ignored(const infinint &val)
increment by one the ea_treated counter
Definition: statistics.hpp:100
void sub_from_treated(const infinint &val)
increment the byte amount counter by a given value
Definition: statistics.hpp:105
void decr_hard_links()
decrement by one the treated counter
Definition: statistics.hpp:120
~statistics()
destructor
Definition: statistics.hpp:83
This is a pure virtual class that is used by libdar when interaction with the user is required...
infinint get_tooold() const
returns the current value of the ignored counter
Definition: statistics.hpp:113
void incr_ea_treated()
increment by one the deleted counter
Definition: statistics.hpp:98
the present file to ignore (not to be recorded as deleted later)
Definition: catalogue.hpp:933
statistics(bool lock=true)
constructor
Definition: statistics.hpp:78
void add_to_deleted(const infinint &val)
increment the errored counter by a given value
Definition: statistics.hpp:102
infinint get_byte_amount() const
returns the current value of the ea_treated counter
Definition: statistics.hpp:117
infinint total() const
total number of file treated
void decr_treated()
returns the current value of the byte_amount counter
Definition: statistics.hpp:119
void dump(user_interaction &dialog) const
set to the given value the byte_amount counter
defines the interaction between libdar and the user.Three classes are defined
void incr_ignored()
increment by one the skipped counter
Definition: statistics.hpp:94
void decr_ea_treated()
decrement by one the deleted counter
Definition: statistics.hpp:126
void incr_skipped()
increment by one the hard_links counter
Definition: statistics.hpp:93
void add_to_byte_amount(const infinint &val)
increment the deleted counter by a given value
Definition: statistics.hpp:103
void incr_hard_links()
increment by one the treated counter
Definition: statistics.hpp:92
void incr_errored()
increment by one the tooold counter
Definition: statistics.hpp:96
void incr_tooold()
increment by one the ignored counter
Definition: statistics.hpp:95
switch module to limitint (32 ou 64 bits integers) or infinint
infinint get_ignored() const
returns the current value of the skipped counter
Definition: statistics.hpp:112
infinint get_hard_links() const
returns the current value of the treated counter
Definition: statistics.hpp:110
the arbitrary large positive integer class
void set_byte_amount(const infinint &val)
decrement by one the ea_treated counter
Definition: statistics.hpp:128
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43
void decr_ignored()
decrement by one the skipped counter
Definition: statistics.hpp:122
infinint get_errored() const
returns the current value of the tooold counter
Definition: statistics.hpp:114
structure returned by libdar call to give a summary of the operation done in term of file treated ...
Definition: statistics.hpp:68
void add_to_errored(const infinint &val)
increment the ignored counter by a given value
Definition: statistics.hpp:101