// Copyright(c)'2011, by JG Dumas
#include <iostream>
#include <omp.h>

struct OMPTimer {
protected:
    double _c;
public:
    void start() { _c = omp_get_wtime(); }
    void stop() { _c = omp_get_wtime() - _c; }
    void clear() { _c = 0.0; }
    double realtime() { return _c; }
    double usertime() { return _c; }
    double time() const { return _c; }

    friend std::ostream& operator<<(std::ostream& o, const OMPTimer& t) {
        return o << t._c << 's';
    }

    OMPTimer& operator =(const OMPTimer& t) { _c = t._c; return *this; }
    OMPTimer& operator+=(const OMPTimer& t) { _c += t._c; return *this; }
    OMPTimer& operator-=(const OMPTimer& t) { _c -= t._c; return *this; }
    OMPTimer  operator +(const OMPTimer& t) const { 
        OMPTimer r; r._c = _c + t._c; return r; }
    OMPTimer  operator -(const OMPTimer& t) const { 
        OMPTimer r; r._c = _c - t._c; return r; }
    OMPTimer  operator -() { OMPTimer r; r._c = - _c; return r; }
};


