/home/coin/SVN-release/Ipopt-3.3.3/Ipopt/src/Common/IpJournalist.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2007 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpJournalist.hpp 1091 2007-09-25 12:16:28Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPJOURNALIST_HPP__
00010 #define __IPJOURNALIST_HPP__
00011 
00012 #include "IpoptConfig.h"
00013 #include "IpTypes.hpp"
00014 #include "IpReferenced.hpp"
00015 #include "IpSmartPtr.hpp"
00016 
00017 #ifdef HAVE_CSTDARG
00018 # include <cstdarg>
00019 #else
00020 # ifdef HAVE_STDARG_H
00021 #  include <stdarg.h>
00022 # else
00023 #  error "don't have header file for stdarg"
00024 # endif
00025 #endif
00026 
00027 #include <string>
00028 #include <vector>
00029 #include <ostream>
00030 
00031 namespace Ipopt
00032 {
00033 
00034   // forward declarations
00035   class Journal;
00036   class FileJournal;
00037 
00041   enum EJournalLevel {
00042     J_INSUPPRESSIBLE=-1,
00043     J_NONE=0,
00044     J_ERROR,
00045     J_STRONGWARNING,
00046     J_SUMMARY,
00047     J_WARNING,
00048     J_ITERSUMMARY,
00049     J_DETAILED,
00050     J_MOREDETAILED,
00051     J_VECTOR,
00052     J_MOREVECTOR,
00053     J_MATRIX,
00054     J_MOREMATRIX,
00055     J_ALL,
00056     J_LAST_LEVEL
00057   };
00058 
00060   enum EJournalCategory {
00061     J_DBG=0,
00062     J_STATISTICS,
00063     J_MAIN,
00064     J_INITIALIZATION,
00065     J_BARRIER_UPDATE,
00066     J_SOLVE_PD_SYSTEM,
00067     J_FRAC_TO_BOUND,
00068     J_LINEAR_ALGEBRA,
00069     J_LINE_SEARCH,
00070     J_HESSIAN_APPROXIMATION,
00071     J_SOLUTION,
00072     J_DOCUMENTATION,
00073     J_NLP,
00074     J_TIMING_STATISTICS,
00075     J_USER_APPLICATION  ,
00076     J_LAST_CATEGORY
00077   };
00079 
00107   class Journalist : public ReferencedObject
00108   {
00109   public:
00113     Journalist();
00114 
00116     virtual ~Journalist();
00118 
00125     void Printf(EJournalLevel level, EJournalCategory category,
00126                 const char* format, ...) const;
00127 
00135     void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
00136                               Index indent_spaces, Index max_length,
00137                               const std::string& line) const;
00138 
00140     void PrintfIndented(EJournalLevel level,
00141                         EJournalCategory category,
00142                         Index indent_level,
00143                         const char* format, ...) const;
00144 
00147     void VPrintf(EJournalLevel level,
00148                  EJournalCategory category,
00149                  const char* pformat,
00150                  va_list ap) const;
00151 
00154     void VPrintfIndented(EJournalLevel level,
00155                          EJournalCategory category,
00156                          Index indent_level,
00157                          const char* pformat,
00158                          va_list ap) const;
00159 
00166     bool ProduceOutput(EJournalLevel level,
00167                        EJournalCategory category) const;
00168 
00169 
00174     void FlushBuffer() const;
00176 
00195     bool AddJournal(const SmartPtr<Journal> jrnl);
00196 
00204     SmartPtr<Journal> AddFileJournal(
00205       const std::string& location_name,    
00206       const std::string& fname,
00207       EJournalLevel default_level = J_WARNING
00208     );
00209 
00213     SmartPtr<Journal> GetJournal(const std::string& location_name);
00215 
00216   private:
00226     Journalist(const Journalist&);
00227 
00229     void operator=(const Journalist&);
00231 
00232     //** Private Data Members. */
00234     std::vector< SmartPtr<Journal> > journals_;
00236   };
00237 
00243   class Journal : public ReferencedObject
00244   {
00245   public:
00247     Journal(const std::string& name, EJournalLevel default_level);
00248 
00250     virtual ~Journal();
00251 
00253     std::string Name();
00254 
00256     void SetPrintLevel(
00257       EJournalCategory category, EJournalLevel level
00258     );
00259 
00261     void SetAllPrintLevels(
00262       EJournalLevel level
00263     );
00264 
00276     bool IsAccepted(
00277       EJournalCategory category, EJournalLevel level
00278     ) const;
00279 
00281     void Print(EJournalCategory category, EJournalLevel level,
00282                const char* str)
00283     {
00284       PrintImpl(category, level, str);
00285     }
00286 
00288     void Printf(EJournalCategory category, EJournalLevel level,
00289                 const char* pformat, va_list ap)
00290     {
00291       PrintfImpl(category, level, pformat, ap);
00292     }
00293 
00295     void FlushBuffer()
00296     {
00297       FlushBufferImpl();
00298     }
00300 
00301   protected:
00307     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00308                            const char* str)=0;
00309 
00311     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00312                             const char* pformat, va_list ap)=0;
00313 
00315     virtual void FlushBufferImpl()=0;
00317 
00318   private:
00328     Journal();
00329 
00331     Journal(const Journal&);
00332 
00334     void operator=(const Journal&);
00336 
00338     std::string name_;
00339 
00341     Index print_levels_[J_LAST_CATEGORY];
00342   };
00343 
00344 
00349   class FileJournal : public Journal
00350   {
00351   public:
00353     FileJournal(const std::string& name, EJournalLevel default_level);
00354 
00356     virtual ~FileJournal();
00357 
00365     bool Open(const char* fname);
00366 
00367   protected:
00373     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00374                            const char* str);
00375 
00377     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00378                             const char* pformat, va_list ap);
00379 
00381     virtual void FlushBufferImpl();
00383 
00384   private:
00394     FileJournal();
00395 
00397     FileJournal(const FileJournal&);
00398 
00400     void operator=(const FileJournal&);
00402 
00404     FILE* file_;
00405   };
00406 
00410   class StreamJournal : public Journal
00411   {
00412   public:
00414     StreamJournal(const std::string& name, EJournalLevel default_level);
00415 
00417     virtual ~StreamJournal()
00418     {}
00419 
00421     void SetOutputStream(std::ostream* os);
00422 
00423   protected:
00429     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00430                            const char* str);
00431 
00433     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00434                             const char* pformat, va_list ap);
00435 
00437     virtual void FlushBufferImpl();
00439 
00440   private:
00450     StreamJournal();
00451 
00453     StreamJournal(const StreamJournal&);
00454 
00456     void operator=(const StreamJournal&);
00458 
00460     std::ostream* os_;
00461 
00463     char buffer_[32768];
00464   };
00465 }
00466 
00467 #endif

Generated on Thu May 15 22:29:56 2008 by  doxygen 1.4.7