00001 #ifndef _DESPERADO_COUNTERSTYPE_H_
00002 #define _DESPERADO_COUNTERSTYPE_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00065 #include <new>
00066 #include "Counters.h"
00067 #include "Platform.h"
00068 #include "Output.h"
00069 #include "Print.h"
00070
00071
00079 template <size_t _NCOUNTERS_>
00080 class CountersType : public Counters {
00081
00082 public:
00083
00093 explicit CountersType(const char** vlabels = 0);
00094
00098 virtual ~CountersType();
00099
00121 virtual bool initialize(const char** vlabels = 0);
00122
00144 virtual void show(int level = 0, Output* display = 0, int indent = 0) const;
00145
00146 private:
00147
00151 Counter vcounters[_NCOUNTERS_];
00152
00153 };
00154
00155
00156
00157
00158
00159 template <size_t _NCOUNTERS_>
00160 inline CountersType<_NCOUNTERS_>::CountersType(const char** vlabels) :
00161 Counters(_NCOUNTERS_, this->vcounters, vlabels)
00162 {
00163 }
00164
00165
00166
00167
00168
00169 template <size_t _NCOUNTERS_>
00170 CountersType<_NCOUNTERS_>::~CountersType() {
00171 }
00172
00173
00174
00175
00176
00177 template <size_t _NCOUNTERS_>
00178 bool CountersType<_NCOUNTERS_>::initialize(const char** vlabels) {
00179 bool rc = false;
00180 try {
00181 this->CountersType<_NCOUNTERS_>::~CountersType();
00182 new(this) CountersType<_NCOUNTERS_>(vlabels);
00183 rc = true;
00184 } catch (...) {
00185 rc = false;
00186 }
00187 return rc;
00188 }
00189
00190
00191
00192
00193
00194 template <size_t _NCOUNTERS_>
00195 void CountersType<_NCOUNTERS_>::show(
00196 int level,
00197 Output* display,
00198 int indent
00199 ) const {
00200 Platform& pl = Platform::instance();
00201 Print printf(display);
00202 const char* sp = printf.output().indentation(indent);
00203 char component[sizeof(__FILE__)];
00204 printf("%s%s(%p)[%lu]\n",
00205 sp, pl.component(__FILE__, component, sizeof(component)),
00206 this, sizeof(*this));
00207 this->Counters::show(level, display, indent + 1);
00208 }
00209
00210
00211 #endif