Source: raytracer/statistics.h


Annotated List
Files
Globals
Hierarchy
Index
/* *************************************************************************
                          statistics.h  -  description
                             -------------------
    begin                : Wed Oct 16 2002    
    copyright            : (C) 2002 by Micha Riser
    email                : mriser@gmx.net
 ************************************************************************* */

/* *************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ************************************************************************* */

#ifndef STATISTICS_H
#define STATISTICS_H

#include<string>
#include<vector>
#include<iostream>

using std::string;
using std::cout;

/**Provides a class for gathering statistical values during rendering.
  *@author Micha Riser
  */
class Statistics {

public: // Inner classes

    /**Statistical group.
      */
    class Group {

    public: // Constructor and destructor
        Group() {}
        ~Group() {}

    public: // Public methods
        void registerStat(const Statistics* s);
        void print() const;

    private: // Private attributes
        std::vector<const Statistics*> members;

    };
    
public: // Static members
    /**Default group.
      */
    static Group* global;

    static void init() {if (!global) global = new Group();}
    static void finish() {delete(global);}
    
public: // Constructor and destructor

    Statistics(Group* g=0);

    virtual ~Statistics();

public: // Pulblic pure virtual methods
    virtual void print() const = 0;

private: // Private attributes
    Group* group;

};

class HitStatistics: public Statistics {

public: // Constructor and destructor
  HitStatistics(const string description, const string evaldescription,
    const string succdescription, Group* g = 0): Statistics(g), descr(description),
    evaldescr(evaldescription), succdescr(succdescription) {}

public: // Public methods
    void eval() {evals++;}
    void success() {succ++;}
    void evalSuccess() {evals++; succ++;}
    void evalFailed() {evals++;}

    void print() const;
            
private: // Private attributes
    const string descr;
    const string evaldescr;
    const string succdescr;
    int evals;
    int succ;
};

template <class Type> class MaxStatistics: public Statistics {

public: // Constructor and destructor
    MaxStatistics(const string description): descr(description), currmax(0) {}

public: // Public methods
    void update(Type t) {if (t>currmax) currmax=t;}

    void print() const {
          cout << descr <<": "<<currmax<<"\n";
    }  

private:
    const string descr;
    Type currmax;

};

#endif

Generated by: micha@laptop on Thu Oct 24 20:25:24 2002, using kdoc 2.0a53.