Main Page | Class Hierarchy | Class List | File List | Class Members

statistics.h

00001 /* ************************************************************************* 00002 statistics.h - description 00003 ------------------- 00004 begin : Wed Oct 16 2002 00005 copyright : (C) 2002 by Micha Riser 00006 email : mriser@gmx.net 00007 00008 $Id: statistics_8h-source.html,v 1.1 2005/02/04 21:02:27 micha Exp $ 00009 00010 ************************************************************************* */ 00011 00012 /* ************************************************************************* 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 ************************************************************************* */ 00020 00021 #ifndef STATISTICS_H 00022 #define STATISTICS_H 00023 00024 #include<string> 00025 #include<vector> 00026 #include<iostream> 00027 00031 class Statistics { 00032 00033 public: // Inner classes 00034 00037 class Group { 00038 00039 public: // Constructor and destructor 00040 Group(): members() {} 00041 ~Group() {} 00042 00043 public: // Public methods 00044 void registerStat(const Statistics* s); 00045 void unregisterStat(const Statistics* s); 00046 void print() const; 00047 00048 private: // Private attributes 00049 std::vector<const Statistics*> members; 00050 00051 }; 00052 00053 public: // Static members 00056 static Group* global; 00057 00058 static void init() {if (!global) global = new Group();} 00059 static void finish() {delete(global); global = 0;} 00060 00061 public: // Constructor and destructor 00062 Statistics(Group* g=0); 00063 virtual ~Statistics(); 00064 private: 00065 Statistics(const Statistics&); 00066 Statistics& operator=(const Statistics&); 00067 00068 public: // Pulblic pure virtual methods 00069 virtual void print() const = 0; 00070 00071 private: // Private attributes 00072 Group* group; 00073 00074 }; 00075 00076 class HitStatistics: public Statistics { 00077 00078 public: // Constructor and destructor 00079 HitStatistics(const std::string description, const std::string evaldescription, 00080 const std::string succdescription, Group* g = 0): Statistics(g), descr(description), 00081 evaldescr(evaldescription), succdescr(succdescription), evals(0), succ(0) {} 00082 00083 public: // Public methods 00084 void eval() {evals++;} 00085 void success() {succ++;} 00086 void evalSuccess() {evals++; succ++;} 00087 void evalFailed() {evals++;} 00088 00089 int getSuccessCount() {return succ;} 00090 int getEvalCount() {return evals;} 00091 00092 void print() const; 00093 00094 private: // Private attributes 00095 const std::string descr; 00096 const std::string evaldescr; 00097 const std::string succdescr; 00098 int evals; 00099 int succ; 00100 }; 00101 00102 template <class Type> class MaxStatistics: public Statistics { 00103 00104 public: // Constructor and destructor 00105 MaxStatistics(const std::string description): descr(description), currmax(0) {} 00106 00107 public: // Public methods 00108 void update(Type t) {if (t>currmax) currmax=t;} 00109 00110 void print() const { 00111 std::cout << descr <<": "<<currmax<<"\n"; 00112 } 00113 00114 private: 00115 const std::string descr; 00116 Type currmax; 00117 00118 }; 00119 00120 #endif

Generated on Thu Jan 27 12:16:06 2005 for raytracer.kdevelop by doxygen 1.3.8