counter.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  File:       counter.hpp
00004 //  Created:    2005/10/24    2:10
00005 //
00006 //  Author: Andrey Somsikov
00007 */
00008 
00009 #ifndef __ARAGELI_counter_hpp__
00010 #define __ARAGELI_counter_hpp__
00011 
00012 #include "config.hpp"
00013 #include <string>
00014 
00015 namespace Arageli
00016 {
00017 class CCounter;
00018 typedef unsigned long long counter_t;
00019 
00020 
00021 class CCounter
00022 {
00023 public:
00024     void add(counter_t a)
00025     {
00026         if (suspended)
00027             return;
00028         sum += a;
00029         if (max < a) max = a;
00030         if (min > a) min = a;
00031         counter++;
00032     }
00033     counter_t getMax() { return max; }
00034     counter_t getMin() { return min; }
00035     counter_t getSum() { return sum; }
00036     counter_t getAverage() { return sum/counter; }
00037     std::string getName() { return name; }
00038     void reset()
00039     {
00040         max = 0;
00041         min = 0;
00042         sum = 0;
00043         counter = 0;
00044     }
00045     void suspend() { suspended = true; }
00046     void resume() { suspended = false; }
00047 public:
00048     CCounter& operator += (counter_t a)
00049     {
00050         add(a);
00051         return *this;
00052     }
00053     CCounter& operator ++ ()
00054     {
00055         return *this += 1;
00056     }
00057 public:
00058     CCounter()
00059     {
00060         max = 0;
00061         min = 0;
00062         sum = 0;
00063         counter = 0;
00064         suspended = false;
00065     }
00066     CCounter(std::string _name)
00067     {
00068         max = 0;
00069         min = 0;
00070         sum = 0;
00071         counter = 0;
00072         name = _name;
00073         suspended = false;
00074     }
00075     CCounter(const CCounter& c)
00076     {
00077         max = c.max;
00078         min = c.min;
00079         sum = c.sum;
00080         counter = c.counter;
00081         name = c.name;
00082         suspended = false;
00083     }
00084 protected:
00085     std::string name;
00086     counter_t max;
00087     counter_t min;
00088     counter_t sum;
00089     counter_t counter;
00090     bool suspended;
00091 };
00092 
00093 extern CCounter counter_big_int_sum_GC;
00094 extern CCounter counter_big_int_mul_GC;
00095 extern CCounter counter_big_int_div_GC;
00096 
00097 } // namespace Arageli
00098 
00099 /*
00100 #ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00101     #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_counter
00102     #include "counter.cpp"
00103     #undef  ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_counter
00104 #endif
00105 */
00106 
00107 #endif /*__ARAGELI_counter_hpp__*/
00108 /* End of file counter.hpp */

Generated on Thu Aug 31 17:38:05 2006 for Arageli by  doxygen 1.4.7