debug.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * $Id: debug.cpp,v 1.7 2001/03/19 19:27:40 root Exp $
00004  *
00005  * Copyright (C) 1997-2008 by Dimitri van Heesch.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and its
00008  * documentation under the terms of the GNU General Public License is hereby 
00009  * granted. No representations are made about the suitability of this software 
00010  * for any purpose. It is provided "as is" without express or implied warranty.
00011  * See the GNU General Public License for more details.
00012  *
00013  * Documents produced by Doxygen are derivative works derived from the
00014  * input used in their production; they are not affected by this license.
00015  *
00016  */
00017 
00018 #include <stdarg.h>
00019 #include <stdio.h>
00020 
00021 #include <qdict.h>
00022 
00023 #include "qtbc.h"
00024 #include "debug.h"
00025 
00026 //------------------------------------------------------------------------
00027 
00028 struct LabelMap
00029 {
00030   const char *name;
00031   Debug::DebugMask event;
00032 };
00033 
00034 static LabelMap s_labels[] =
00035 {
00036   { "findmembers",  Debug::FindMembers  },
00037   { "functions",    Debug::Functions    },
00038   { "variables",    Debug::Variables    },
00039   { "preprocessor", Debug::Preprocessor },
00040   { "classes",      Debug::Classes      },
00041   { "commentcnv",   Debug::CommentCnv   },
00042   { "commentscan",  Debug::CommentScan  },
00043   { "validate",     Debug::Validate     },
00044   { "printtree",    Debug::PrintTree    },
00045   { "time",         Debug::Time         },
00046   { "extcmd",       Debug::ExtCmd       },
00047   { 0,             (Debug::DebugMask)0  }
00048 };
00049 
00050 class LabelMapper
00051 {
00052   public:
00053     LabelMapper() : m_map(17) 
00054     {
00055       m_map.setAutoDelete(TRUE);
00056       LabelMap *p = s_labels;
00057       while (p->name)
00058       {
00059         m_map.insert(p->name,new Debug::DebugMask(p->event));
00060         p++;
00061       }
00062     }
00063     Debug::DebugMask *find(const char *s) const 
00064     {
00065       if (s==0) return 0;
00066       return m_map.find(s);
00067     }
00068   private:
00069     QDict<Debug::DebugMask> m_map;
00070 };
00071 
00072 static LabelMapper g_labelMapper;
00073 
00074 //------------------------------------------------------------------------
00075 
00076 Debug::DebugMask Debug::curMask = Debug::Quiet;
00077 int Debug::curPrio = 0;
00078 
00079 void Debug::print(DebugMask mask,int prio,const char *fmt,...)
00080 {
00081   if ((curMask&mask) && prio<=curPrio)
00082   {
00083     va_list args;
00084     va_start(args,fmt);
00085     vfprintf(stdout, fmt, args);
00086     va_end(args);
00087   }
00088 }
00089 
00090 static int labelToEnumValue(const char *l)
00091 {
00092   QCString label=l;
00093   Debug::DebugMask *event = g_labelMapper.find(label.lower());
00094   if (event) return *event; else return 0;
00095 }
00096 
00097 void Debug::setFlag(const char *lab)
00098 {
00099   curMask = (DebugMask)(curMask | labelToEnumValue(lab));   
00100 }
00101 
00102 void Debug::clearFlag(const char *lab)
00103 {
00104   curMask = (DebugMask)(curMask & ~labelToEnumValue(lab));
00105 }
00106 
00107 void Debug::setPriority(int p)
00108 {
00109   curPrio = p;
00110 }
00111 
00112 bool Debug::isFlagSet(DebugMask mask)
00113 {
00114   return (curMask & mask)!=0;
00115 }
00116 



Generated on Mon Mar 31 10:58:34 2008 by  doxygen 1.5.1