Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

verbosity.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 //Created by ilm, Nov 16, 1997
00042 
00043 #ifdef _MSC_VER
00044 #pragma warning(disable:4786)
00045 #endif
00046 
00047 
00048 #include <limits.h>
00049 #include <stdarg.h>
00050 #include <string>
00051 #include <vector>
00052 #include <iostream>
00053 #include "abkcommon.h"
00054 #include "verbosity.h"
00055 Verbosity& Verbosity::operator=(const Verbosity& v)
00056       {
00057          abkwarn(v.getNumTypes()<=_levels.size(),
00058                  "  Losing debug levels while assigning Verbosities\n  Use copy-construction");
00059          for(unsigned k=0;k<v.getNumTypes();k++)
00060              _levels[k]=v._levels[k];
00061          _levels.erase(_levels.begin()+v.getNumTypes(),
00062                        _levels.begin()+getNumTypes());
00063          return *this;
00064       }
00065 
00066 ostream& operator<<(ostream& os, const Verbosity& verbsty)
00067 {
00068         unsigned numLevels=verbsty._levels.size(); 
00069 
00070         os << " Verbosity levels : " << numLevels << endl;
00071         os << " For actions : " << verbsty.forActions << ",  "
00072            << " For sys resources : " << verbsty.forSysRes << ",  "
00073            << " For major stats : " << verbsty.forMajStats << endl;
00074       
00075         if (numLevels > 3)
00076         {
00077           os << " Other levels : " ;
00078           for (unsigned i=3; i!=numLevels; ++i)
00079           {
00080                 if ( i % 10 == 0 )
00081                 {
00082                     if (i) os << endl;
00083                     os <<"      ";
00084                 }
00085                 os<<setw(3)<<verbsty._levels[i]<<" ";
00086           }
00087           os << endl;
00088         }
00089 
00090     return os;
00091 }
00092 
00093 void Verbosity::_ctructFromString(const char* levels)
00094 {
00095    if (levels==NULL || 
00096        !strcmp(levels,"0") || !strcasecmp(levels,"silent"))
00097    {
00098       _levels.erase(_levels.begin()+3,_levels.end());
00099       return;
00100    }
00101 
00102    unsigned len=strlen(levels);
00103    char * levs=new char[len+1];
00104    for(unsigned c=0;c<len;c++) 
00105    if (levels[c]=='_') levs[c]=' '; else levs[c]=levels[c];
00106    levs[len]='\0';
00107 
00108    unsigned  numLev=0;
00109    char *start =levs;
00110    char *finish=levs;
00111    while (start<levs+len)
00112    {
00113       unsigned tmp=strtoul(start,&finish,10);
00114       if (start==finish) start++;
00115       else 
00116       { 
00117          abkfatal(tmp<=INT_MAX,"Verbosity levels can't be >INT_MAX");
00118          abkfatal(numLev<100,"This ctor can't work with 100+ verbosity levels");
00119          _levels[numLev]=tmp;
00120          start=finish;
00121          numLev++;
00122       }
00123    }
00124    abkfatal(numLev>2," Can't ctruct Verbosity: need at least 3 levels\n ");
00125    _levels.erase(_levels.begin()+numLev,_levels.end());
00126    delete[] levs;
00127 }
00128 
00129 Verbosity::Verbosity(const char* levels)
00130 // space or underscore-separated unsigneds
00131 :_levels(100,0),
00132 forActions(_levels[0]),forSysRes(_levels[1]),forMajStats(_levels[2])
00133 {
00134   _ctructFromString(levels);
00135 }
00136 
00137 Verbosity::Verbosity(int argc, const char *argv[]) // catches -verb
00138 :_levels(100,0),
00139 forActions(_levels[0]),forSysRes(_levels[1]),forMajStats(_levels[2])
00140 {
00141     StringParam verb("verb",argc,argv);
00142     BoolParam helpRequest1("h",argc,argv);
00143     BoolParam helpRequest2("help",argc,argv);
00144 
00145     if (helpRequest1.found() || helpRequest2.found())
00146     {
00147       cout << " -verb 1_1_1 | silent " << endl; 
00148       _levels.erase(_levels.begin()+3,_levels.end());
00149       return;
00150     }
00151   
00152     if (verb.found())  _ctructFromString(verb);
00153     else 
00154     { 
00155        _levels.erase(_levels.begin()+3,_levels.end());
00156        _levels[0]=_levels[1]=_levels[2]=1;
00157     }
00158 }
00159 
00160 Verbosity::Verbosity():
00161 _levels(3,1),
00162 forActions(_levels[0]),forSysRes(_levels[1]),forMajStats(_levels[2])
00163 {
00164 }
00165 
00166 Verbosity::Verbosity(const std::vector<unsigned>& levels):
00167 _levels(levels),
00168 forActions(_levels[0]),forSysRes(_levels[1]),forMajStats(_levels[2])
00169 {
00170    abkfatal(levels.size()>=3,
00171             "Can not initialize verbosity --- too few levels\n ");
00172 }
00173 
00174 
00175 Verbosity::Verbosity(unsigned numLevels, unsigned ForActions,
00176                      unsigned ForSysRes, unsigned ForMajStats, ...):
00177 _levels(numLevels,0),
00178 forActions(_levels[0]),forSysRes(_levels[1]),forMajStats(_levels[2])
00179 {
00180    abkfatal(numLevels>=3,"Can not initialize verbosity --- too few levels\n ");
00181    _levels[0]=ForActions;
00182    _levels[1]=ForSysRes;
00183    _levels[2]=ForMajStats;
00184 
00185    va_list ap;
00186    va_start(ap,ForMajStats);
00187 
00188    for(unsigned k=3;k<numLevels;k++)
00189    {
00190      _levels[k]=va_arg(ap,unsigned);
00191      abkfatal(_levels[k]<INT_MAX/2," Verbosity levels can't be > INT_MAX /2");
00192    }
00193 }
00194 
00195 unsigned & Verbosity::operator[](unsigned diagType)
00196 { 
00197    abkfatal(diagType<_levels.size(),"Inexistant diagnostic type");
00198    return _levels[diagType];
00199 }
00200 

Generated on Mon Apr 25 01:09:25 2005 for Parquete by doxygen 1.3.2