00001 //STARTHEADER 00002 // $Id: LimitedWarning.hh 1761 2010-09-16 10:43:18Z soyez $ 00003 // 00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam 00005 // 00006 //---------------------------------------------------------------------- 00007 // This file is part of FastJet. 00008 // 00009 // FastJet is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // The algorithms that underlie FastJet have required considerable 00015 // development and are described in hep-ph/0512210. If you use 00016 // FastJet as part of work towards a scientific publication, please 00017 // include a citation to the FastJet paper. 00018 // 00019 // FastJet is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with FastJet; if not, write to the Free Software 00026 // Foundation, Inc.: 00027 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 //---------------------------------------------------------------------- 00029 //ENDHEADER 00030 00031 00032 #ifndef __FASTJET_LIMITEDWARNING_HH__ 00033 #define __FASTJET_LIMITEDWARNING_HH__ 00034 00035 #include<iostream> 00036 #include<string> 00037 00038 /// \if internal_doc 00039 /// @ingroup internal 00040 /// \class LimitedWarning 00041 /// class to provide facilities for giving warnings up to some maximum 00042 /// number of times 00043 /// \endif 00044 class LimitedWarning { 00045 public: 00046 00047 /// constructor that provides a default maximum number of warnings 00048 LimitedWarning() : _max_warn(_max_warn_default), _n_warn_so_far(0) {} 00049 00050 /// constructor that provides a used-set max number of warnings 00051 LimitedWarning(int max_warn) : _max_warn(max_warn), _n_warn_so_far(0) {} 00052 00053 /// output a warning to ostr 00054 void warn(const std::string & warning, std::ostream & ostr = std::cerr) { 00055 if (_n_warn_so_far < _max_warn) { 00056 ostr << "WARNING: "; 00057 ostr << warning; 00058 _n_warn_so_far++; 00059 if (_n_warn_so_far == _max_warn) ostr << " (LAST SUCH WARNING)"; 00060 ostr << std::endl; 00061 } 00062 } 00063 00064 private: 00065 int _max_warn, _n_warn_so_far; 00066 static const int _max_warn_default = 5; 00067 00068 }; 00069 00070 #endif // __FASTJET_LIMITEDWARNING_HH__