CountersType.h

Go to the documentation of this file.
00001 #ifndef _DESPERADO_COUNTERSTYPE_H_
00002 #define _DESPERADO_COUNTERSTYPE_H_
00003 
00004 /* vim: set ts=4 expandtab shiftwidth=4: */
00005 
00006 /******************************************************************************
00007 
00008     Copyright 2006 Digital Aggregates Corp., Arvada CO 80001-0587, USA.
00009     This file is part of the Digital Aggregates Desperado library.
00010     
00011     This library is free software; you can redistribute it and/or
00012     modify it under the terms of the GNU Lesser General Public
00013     License as published by the Free Software Foundation; either
00014     version 2.1 of the License, or (at your option) any later version.
00015 
00016     As a special exception, if other files instantiate templates or
00017     use macros or inline functions from this file, or you compile
00018     this file and link it with other works to produce a work based on
00019     this file, this file does not by itself cause the resulting work
00020     to be covered by the GNU Lesser General Public License. However
00021     the source code for this file must still be made available in
00022     accordance with the GNU Lesser General Public License.
00023 
00024     This exception does not invalidate any other reasons why a work
00025     based on this file might be covered by the GNU Lesser General
00026     Public License.
00027 
00028     Alternative commercial licensing terms are available from the copyright
00029     holder. Contact Digital Aggregates Corporation for more information.
00030 
00031     This library is distributed in the hope that it will be useful,
00032     but WITHOUT ANY WARRANTY; without even the implied warranty of
00033     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00034     GNU Lesser General Public License for more details.
00035 
00036     You should have received a copy of the GNU Lesser General
00037     Public License along with this library; if not, write to the
00038     Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00039     Boston, MA 02111-1307 USA, or http://www.gnu.org/copyleft/lesser.txt.
00040 
00041     $Name:  $
00042 
00043     $Id: CountersType.h,v 1.5 2006/02/07 00:07:03 jsloan Exp $
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 //  Constructor.
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 //  Destructor.
00168 //
00169 template <size_t _NCOUNTERS_>
00170 CountersType<_NCOUNTERS_>::~CountersType() {
00171 }
00172 
00173 
00174 //
00175 //    Initializer.
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 //  Show this object on the output object.
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
Copyright © 2006 Digital Aggregates Corp., Arvada CO 80001-0587, USA.
Distributed under the terms of the GNU Free Documentation License.
http://www.diag.com/navigation/downloads/Desperado.html