libs/EDoc/StdErrNotifier.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
00017 
00018 *******************************************************************************/
00019 #include "config.h"
00020 
00021 #include "EDoc/StdErrNotifier.h"
00022 
00023 namespace EDoc
00024 {
00025    //===========================================================================
00026    StdErrNotifier::StdErrNotifier(bool show_details_in) :
00027       show_details(show_details_in),
00028       error_count(0)
00029    {
00030       // Register all the standard edoc events.
00031       #define EDOC_EVENT_ITEM(Type, Name, Description) \
00032          RegisterEvent(Type, Name, #Name, Description);
00033       #include "EDoc/events.inc"
00034       #undef EDOC_EVENT_ITEM
00035    }
00036    //===========================================================================
00037    StdErrNotifier::~StdErrNotifier()
00038    {
00039    }
00040    //===========================================================================
00041    void StdErrNotifier::RegisterEvent(EventType type, EventCode code,
00042       std::string name, std::string summary)
00043    {
00044       EDOC_ASSERT(!event_types.count(code), "");
00045       event_types[code] = Details(type, name, summary);
00046    }
00047    //===========================================================================
00048    void StdErrNotifier::PrintEvent(EventCode code, const std::string& message)
00049    {
00050       std::ostringstream stream;
00051 
00052       Details& d = event_types[code];
00053       if (d.type == EVENT_ERROR)
00054       {
00055          stream << "ERROR";
00056       }
00057       else if (d.type == EVENT_WARNING)
00058       {
00059          stream << "WARNING";
00060       }
00061       else
00062       {
00063          EDOC_ASSERT(false, "Unreachable.");
00064       }
00065       stream << "(" << d.name << "): " << d.summary;
00066       if (show_details)
00067       {
00068          stream << " :" << message;
00069       }
00070 
00071       messages.push_back(stream.str());
00072    }
00073    //===========================================================================
00074    void StdErrNotifier::Event(EventCode code, 
00075       const char* EDOC_UNUSED(source_file), 
00076       unsigned int EDOC_UNUSED(source_line), 
00077       std::string message,
00078       const Function* function, 
00079       const File* file, 
00080       uint32_t line, 
00081       const File* rfile, 
00082       uint32_t rline, 
00083       const Type* type, 
00084       const PropogatingException* prop_exc,
00085       const FunctionType* function_type,
00086       const char* extra)
00087    {
00088       if (filter(filter_data, code, event_types[code].name,
00089          event_types[code].type, function, file, line, rfile, rline, type,
00090          prop_exc, function_type, extra))
00091       {
00092          if (event_types[code].type == EVENT_ERROR)
00093          {
00094             error_count++;
00095          }
00096          
00097          PrintEvent(code, message);
00098       }
00099    }
00100    //===========================================================================
00101    std::ostream& StdErrNotifier::Print(std::ostream& out) const
00102    {
00103       for (std::map<EventCode, Details>::const_iterator it = 
00104          event_types.begin();
00105          it != event_types.end(); it++)
00106       {
00107          out << "Code " << it->first 
00108             << ", Name: " << it->second.name
00109             << ", Summary: " << it->second.summary << std::endl;
00110       }
00111 
00112       return out;
00113    }
00114    //===========================================================================
00115    void StdErrNotifier::PrintAll()
00116    {
00117       for(std::list<std::string>::iterator it = messages.begin();
00118          it != messages.end(); it++)
00119       {
00120          std::cerr << *it << std::endl;
00121       }
00122 
00123       messages.erase(messages.begin(), messages.end());
00124    }
00125    //===========================================================================
00126 }
00127 

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1