tracer.h
00001 /* 00002 * 00003 * Copyright (c) 2003 Robert McLay 00004 * 00005 * Author: Robert McLay <mclay@zaniahgroup.com> 00006 */ 00007 00008 /* 00009 * This file is part of traceString. 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the Lesser GNU General Public License as published by 00013 * the Free Software Foundation; either version 2, or (at your option) 00014 * any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the Lesser GNU General Public License 00022 * along with this program; see the file COPYING. If not, write to 00023 * the Free Software Foundation, 59 Temple Place - Suite 330, 00024 * Boston, MA 02111-1307, USA. 00025 */ 00026 00027 #ifndef TRACER_H 00028 #define TRACER_H 00029 00030 #include <vector> 00031 00032 #if (defined(USE_TRACER)) 00033 # define TRACER(t,name,klass) Tracer t(name,klass) 00034 #else 00035 # define TRACER(t,name,klass) 00036 #endif 00037 00038 #define STRCMP(a,test,b) (strcmp(a,b) test 0) 00039 00040 typedef std::vector<char *> NamesList; 00041 00042 //==================================================== 00075 //==================================================== 00076 class Tracer 00077 { 00078 public: 00080 enum Kind_t {EMPTY = 0, INCLUDE, EXCLUDE}; 00081 00084 enum List_t {KLASS = 0, FUNCTION, ALWAYS_EXCLUDE, KLASS_WATCH, 00085 FUNCTION_WATCH, LISTSIZE}; 00086 00087 //==================================================== 00096 //==================================================== 00097 Tracer(const char* name, const char* klass) 00098 : mp_name(0) { if (ms_traceOn) entering(name,klass); } 00099 00100 //==================================================== 00112 //==================================================== 00113 ~Tracer() { if (ms_traceOn && mp_name) leaving(); } 00114 00115 00116 //==================================================== 00123 //==================================================== 00124 static void turnOn(std::ostream* s) { msp_stream = s; ms_traceOn = 1; } 00125 00126 //==================================================== 00133 //==================================================== 00134 static void turnOn(std::ostream& s) { msp_stream = &s; ms_traceOn = 1; } 00135 00136 //==================================================== 00141 //==================================================== 00142 static void turnOnEnv(std::ostream* s); 00143 00144 //==================================================== 00149 //==================================================== 00150 static void turnOnEnv(std::ostream& s); 00151 00152 //==================================================== 00156 //==================================================== 00157 static int traceOn() { return ms_traceOn; } 00158 00159 //==================================================== 00163 //==================================================== 00164 static void turnOff() { ms_traceOn = 0; } 00165 00166 //==================================================== 00174 //==================================================== 00175 static void applyList(NamesList& nl, List_t listType, Kind_t kind); 00176 00177 static void applyList(const char* file, List_t listType, Kind_t kind); 00178 00179 00180 private: 00181 //==================================================== 00189 //==================================================== 00190 class TracerHelper 00191 { 00192 public: 00193 TracerHelper() {} 00194 ~TracerHelper() { Tracer::cleanup(); } 00195 00196 private: 00197 TracerHelper (const TracerHelper&); 00198 TracerHelper& operator=(const TracerHelper&); 00199 }; 00200 00201 friend class TracerHelper; 00202 private: 00203 //==================================================== 00231 //==================================================== 00232 void entering(const char* name, const char* klass); 00233 00234 //==================================================== 00243 //==================================================== 00244 void leaving(); 00245 00246 //==================================================== 00255 //==================================================== 00256 static bool printMe(Kind_t t, NamesList& s, const char* name); 00257 00258 //==================================================== 00271 //==================================================== 00272 static void buildList(const char* fn, NamesList* nl); 00273 00274 //==================================================== 00281 //==================================================== 00282 static void cleanup(); 00283 00284 static void cleanup(NamesList* nl); 00285 00286 00287 private: 00288 //==================================================== 00292 //==================================================== 00293 char* mp_name; 00294 00295 //==================================================== 00299 //==================================================== 00300 static char* msp_watch; 00301 00302 //==================================================== 00306 //==================================================== 00307 static int ms_traceOn; 00308 00309 //==================================================== 00313 //==================================================== 00314 static int ms_watchOn; 00315 00316 //==================================================== 00320 //==================================================== 00321 static int ms_watchList; 00322 00323 //==================================================== 00327 //==================================================== 00328 static int ms_indentLvl; 00329 00330 //==================================================== 00334 //==================================================== 00335 static std::ostream* msp_stream; 00336 00337 //==================================================== 00341 //==================================================== 00342 static NamesList* msp_list[LISTSIZE]; 00343 00344 //==================================================== 00348 //==================================================== 00349 static Kind_t ms_listK[LISTSIZE]; 00350 00351 //==================================================== 00356 //==================================================== 00357 static TracerHelper ms_tracerHelper; 00358 00359 }; 00360 00361 00362 #endif //TRACER_H 00363 00364 00365