Orb/Doxygen/src/debug.cpp
changeset 3 d8fccb2cd802
child 4 468f4c8d3d5b
equal deleted inserted replaced
2:932c358ece3e 3:d8fccb2cd802
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  * Documents produced by Doxygen are derivative works derived from the
       
    14  * input used in their production; they are not affected by this license.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <stdarg.h>
       
    19 #include <stdio.h>
       
    20 
       
    21 #include <qdict.h>
       
    22 
       
    23 #include "qtbc.h"
       
    24 #include "debug.h"
       
    25 
       
    26 //------------------------------------------------------------------------
       
    27 
       
    28 struct LabelMap
       
    29 {
       
    30   const char *name;
       
    31   Debug::DebugMask event;
       
    32 };
       
    33 
       
    34 static LabelMap s_labels[] =
       
    35 {
       
    36   { "findmembers",  Debug::FindMembers  },
       
    37   { "functions",    Debug::Functions    },
       
    38   { "variables",    Debug::Variables    },
       
    39   { "preprocessor", Debug::Preprocessor },
       
    40   { "classes",      Debug::Classes      },
       
    41   { "commentcnv",   Debug::CommentCnv   },
       
    42   { "commentscan",  Debug::CommentScan  },
       
    43   { "validate",     Debug::Validate     },
       
    44   { "printtree",    Debug::PrintTree    },
       
    45   { "time",         Debug::Time         },
       
    46   { "extcmd",       Debug::ExtCmd       },
       
    47   { "includes",     Debug::IncludeGraph },
       
    48   { 0,             (Debug::DebugMask)0  }
       
    49 };
       
    50 
       
    51 class LabelMapper
       
    52 {
       
    53   public:
       
    54     LabelMapper() : m_map(17) 
       
    55     {
       
    56       m_map.setAutoDelete(TRUE);
       
    57       LabelMap *p = s_labels;
       
    58       while (p->name)
       
    59       {
       
    60         m_map.insert(p->name,new Debug::DebugMask(p->event));
       
    61         p++;
       
    62       }
       
    63     }
       
    64     Debug::DebugMask *find(const char *s) const 
       
    65     {
       
    66       if (s==0) return 0;
       
    67       return m_map.find(s);
       
    68     }
       
    69   private:
       
    70     QDict<Debug::DebugMask> m_map;
       
    71 };
       
    72 
       
    73 static LabelMapper g_labelMapper;
       
    74 
       
    75 //------------------------------------------------------------------------
       
    76 
       
    77 Debug::DebugMask Debug::curMask = Debug::Quiet;
       
    78 int Debug::curPrio = 0;
       
    79 
       
    80 void Debug::print(DebugMask mask,int prio,const char *fmt,...)
       
    81 {
       
    82   if ((curMask&mask) && prio<=curPrio)
       
    83   {
       
    84     va_list args;
       
    85     va_start(args,fmt);
       
    86     vfprintf(stdout, fmt, args);
       
    87     va_end(args);
       
    88   }
       
    89 }
       
    90 
       
    91 static int labelToEnumValue(const char *l)
       
    92 {
       
    93   QCString label=l;
       
    94   Debug::DebugMask *event = g_labelMapper.find(label.lower());
       
    95   if (event) return *event; else return 0;
       
    96 }
       
    97 
       
    98 void Debug::setFlag(const char *lab)
       
    99 {
       
   100   curMask = (DebugMask)(curMask | labelToEnumValue(lab));   
       
   101 }
       
   102 
       
   103 void Debug::clearFlag(const char *lab)
       
   104 {
       
   105   curMask = (DebugMask)(curMask & ~labelToEnumValue(lab));
       
   106 }
       
   107 
       
   108 void Debug::setPriority(int p)
       
   109 {
       
   110   curPrio = p;
       
   111 }
       
   112 
       
   113 bool Debug::isFlagSet(DebugMask mask)
       
   114 {
       
   115   return (curMask & mask)!=0;
       
   116 }
       
   117