ESyS-Particle  2.3
Counter.h
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef _COUNTER_H_
14 #define _COUNTER_H_
15 #include "t_list.h"
16 
17 //--- IO includes ---
18 #include <iostream>
19 #include <cstdio>
20 using std::ostream;
21 
22 //--- system includes ---
23 #include <string.h>
24 
29 class CCounter {
30 protected:
31  char *Name ;
32  int Value ;
33  int Id ;
34 public:
35  CCounter() ;
36  CCounter(char *Name, int Id=0) ;
37  virtual ~CCounter() ;
38 
39  void create(char *Name, int Id=0) ;
40  CCounter & operator +=(int n) ;
41  CCounter & operator -=(int n) ;
42  CCounter & operator ++() ;
43  CCounter & operator --() ;
44  CCounter & operator ++(int) ;
45  CCounter & operator --(int) ;
46  CCounter & reset() ;
47  char *getName() ;
48  operator int () ;
49  ostream& print(ostream& Out) ;
50 } ;
55 class CListCounters : public List<CCounter> {
56 } ;
57 
61 class CCounterList {
62 protected:
64 public:
65  CCounterList() ;
66  virtual ~CCounterList() ;
67 
68  CCounterList & operator << (CCounter &Counter) ;
69  CCounterList & addCounter(char *name) ;
70  CCounter & counter(char *name) ;
71  CCounter & operator()(char *Name) ;
72  ostream& print(ostream& Out) ;
73  inline CListCounters & getList()
74  { return m_Counters; } ;
75 } ;
76 
77 // out-of-class method to print-out counter values
78 ostream& operator<<(ostream& Out, CCounter &P) ;
79 ostream& operator<<(ostream& Out, CCounterList &P) ;
80 
81 #endif
82 
char * Name
Name is allocated or deallocated on construction or destruction, respectively.
Definition: Counter.h:31
CCounter & operator--()
decrement counter by 1
Definition: Counter.cpp:48
CCounter & operator()(char *Name)
return the counter "name"
Definition: Counter.cpp:109
ostream & operator<<(ostream &Out, CCounter &P)
Definition: Counter.cpp:128
int Value
Definition: Counter.h:32
Definition: Counter.h:55
void create(char *Name, int Id=0)
create counter, call by constructor
Definition: Counter.cpp:29
virtual ~CCounter()
Definition: Counter.cpp:25
ostream & print(ostream &Out)
method to print the value
Definition: Counter.cpp:123
CCounter & counter(char *name)
return the counter "name"
Definition: Counter.cpp:90
CCounter & operator+=(int n)
increment counter by n
Definition: Counter.cpp:36
Definition: Counter.h:61
CListCounters m_Counters
Definition: Counter.h:63
virtual ~CCounterList()
Definition: Counter.cpp:76
Definition: t_list.h:40
Definition: Counter.h:29
CCounter()
Definition: Counter.cpp:17
CCounter & operator++()
increment counter by 1
Definition: Counter.cpp:44
CCounterList & addCounter(char *name)
add a counter of name "name"
Definition: Counter.cpp:103
int Id
Definition: Counter.h:33
CCounter & reset()
reset the counter to 0
Definition: Counter.cpp:60
ostream & print(ostream &Out)
method to print out all counters
Definition: Counter.cpp:113
CCounter & operator-=(int n)
decrement counter by n
Definition: Counter.cpp:40
CCounterList()
Definition: Counter.cpp:73
char * getName()
return name of counter
Definition: Counter.cpp:65
CCounterList & operator<<(CCounter &Counter)
add a counter "Counter"
Definition: Counter.cpp:84
CListCounters & getList()
Definition: Counter.h:73