MessageReporter.h

Go to the documentation of this file.
00001 /*
00002  *  BEEN: Benchmarking Environment
00003  *  ==============================
00004  *
00005  *  File author: Branislav Repcek
00006  *
00007  *  GNU Lesser General Public License Version 2.1
00008  *  ---------------------------------------------
00009  *  Copyright (C) 2004-2006 Distributed Systems Research Group,
00010  *  Faculty of Mathematics and Physics, Charles University in Prague
00011  *
00012  *  This library is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU Lesser General Public
00014  *  License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *  This library 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 GNU
00019  *  Lesser General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU Lesser General Public
00022  *  License along with this library; if not, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *  MA  02111-1307  USA
00025  */
00026 
00034 #ifndef MESSAGE_REPORTER_INCLUDED
00035 #define MESSAGE_REPORTER_INCLUDED
00036 
00037 #include <vector>
00038 #include "UnicodeString.h"
00039 
00040 namespace hwdet
00041 {
00047     class MessageReporter
00048     {
00049     public:
00057         MessageReporter(const String &rep_name, MessageReporter *parent_reporter = NULL) :
00058         parent(parent_reporter),
00059         name(rep_name)
00060         {
00061         }
00062 
00065         virtual ~MessageReporter(void)
00066         {
00067         }
00068 
00073         String GetLastMessage(void) const
00074         {
00075             if (!messages.empty())
00076             {
00077                 return messages.back();
00078             }
00079             else
00080             {
00081                 return String();
00082             }
00083         }
00084 
00089         String GetName(void) const
00090         {
00091             return name;
00092         }
00093 
00099         String GetMessage(size_t index) const
00100         {
00101             if (index < messages.size())
00102             {
00103                 return messages[index];
00104             }
00105             else
00106             {
00107                 return String();
00108             }
00109         }
00110 
00115         size_t GetMessageQueueLength(void) const
00116         {
00117             return messages.size();
00118         }
00119 
00124         void WriteMessagesToStream(OStream &stream)
00125         {
00126             std::vector< String >::const_iterator end = messages.end();
00127             for (std::vector< String >::const_iterator it = messages.begin(); it != end; ++it)
00128             {
00129                 stream << *it << std::endl;
00130             }
00131         }
00132 
00133     protected:
00142         void ReportMessage(const String &new_msg)
00143         {
00144             messages.push_back(name + TXT(": ") + new_msg);
00145             
00146             if (parent)
00147             {
00148                 parent->ChildReportMessage(*messages.rbegin());
00149             }
00150             else
00151             {
00152                 Cout << *messages.rbegin() << std::endl;
00153             }
00154         }
00155         
00156     private:
00158         MessageReporter       *parent;
00159                 
00161         String                name;
00162 
00164         std::vector< String > messages;
00165         
00171         void ChildReportMessage(const String &message)
00172         {
00173             messages.push_back(name + TXT("::") + message);
00174             
00175             if (parent)
00176             {
00177                 parent->ChildReportMessage(*messages.rbegin());
00178             }
00179             else
00180             {
00181                 Cout << *messages.rbegin() << std::endl;
00182             }
00183         }
00184     }; // MessageReporter
00185 
00186 } // namespace hwdet
00187     
00188 #endif

Generated on Tue Dec 19 17:43:52 2006 for Detector for Windows by  doxygen 1.4.7