- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2006 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: IpJournalist.hpp 759 2006-07-07 03:07:08Z 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
    00030 namespace Ipopt
    00031 {
    00032
    00033   // forward declarations
    00034   class Journal;
    00035   class FileJournal;
    00036
    00040   enum EJournalLevel {
    00041     J_INSUPPRESSIBLE=-1,
    00042     J_NONE=0,
    00043     J_ERROR,
    00044     J_WARNING,
    00045     J_SUMMARY,
    00046     J_ITERSUMMARY,
    00047     J_DETAILED,
    00048     J_MOREDETAILED,
    00049     J_VECTOR,
    00050     J_MOREVECTOR,
    00051     J_MATRIX,
    00052     J_MOREMATRIX,
    00053     J_ALL,
    00054     J_LAST_LEVEL
    00055   };
    00056
    00058   enum EJournalCategory {
    00059     J_DBG=0,
    00060     J_STATISTICS,
    00061     J_MAIN,
    00062     J_INITIALIZATION,
    00063     J_BARRIER_UPDATE,
    00064     J_SOLVE_PD_SYSTEM,
    00065     J_FRAC_TO_BOUND,
    00066     J_LINEAR_ALGEBRA,
    00067     J_LINE_SEARCH,
    00068     J_HESSIAN_APPROXIMATION,
    00069     J_SOLUTION,
    00070     J_DOCUMENTATION,
    00071     J_NLP,
    00072     J_TIMING_STATISTICS,
    00073     J_USER_APPLICATION  ,
    00074     J_LAST_CATEGORY
    00075   };
    00077
    00105   class Journalist : public ReferencedObject
    00106   {
    00107   public:
    00111     Journalist();
    00112
    00114     virtual ~Journalist();
    00116
    00123     void Printf(EJournalLevel level, EJournalCategory category,
    00124                 const char* format, ...) const;
    00125
    00133     void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
    00134                               Index indent_spaces, Index max_length,
    00135                               const std::string& line) const;
    00136
    00138     void PrintfIndented(EJournalLevel level,
    00139                         EJournalCategory category,
    00140                         Index indent_level,
    00141                         const char* format, ...) const;
    00142
    00145     void VPrintf(EJournalLevel level,
    00146                  EJournalCategory category,
    00147                  const char* pformat,
    00148                  va_list ap) const;
    00149
    00152     void VPrintfIndented(EJournalLevel level,
    00153                          EJournalCategory category,
    00154                          Index indent_level,
    00155                          const char* pformat,
    00156                          va_list ap) const;
    00157
    00164     bool ProduceOutput(EJournalLevel level,
    00165                        EJournalCategory category) const;
    00166
    00167
    00172     void FlushBuffer() const;
    00174
    00193     bool AddJournal(const SmartPtr<Journal> jrnl);
    00194
    00202     SmartPtr<Journal> AddFileJournal(
    00203       const std::string& location_name,
    00204       const std::string& fname,
    00205       EJournalLevel default_level = J_WARNING
    00206     );
    00207
    00211     SmartPtr<Journal> GetJournal(const std::string& location_name);
    00213
    00214   private:
    00224     Journalist(const Journalist&);
    00225
    00227     void operator=(const Journalist&);
    00229
    00230     //** Private Data Members. */
    00232     std::vector< SmartPtr<Journal> > journals_;
    00234   };
    00235
    00241   class Journal : public ReferencedObject
    00242   {
    00243   public:
    00245     Journal(const std::string& name, EJournalLevel default_level);
    00246
    00248     virtual ~Journal();
    00249
    00251     std::string Name();
    00252
    00254     void SetPrintLevel(
    00255       EJournalCategory category, EJournalLevel level
    00256     );
    00257
    00259     void SetAllPrintLevels(
    00260       EJournalLevel level
    00261     );
    00262
    00274     bool IsAccepted(
    00275       EJournalCategory category, EJournalLevel level
    00276     ) const;
    00277
    00279     void Print(const char* str)
    00280     {
    00281       PrintImpl(str);
    00282     }
    00283
    00285     void Printf(const char* pformat, va_list ap)
    00286     {
    00287       PrintfImpl(pformat, ap);
    00288     }
    00289
    00291     void FlushBuffer()
    00292     {
    00293       FlushBufferImpl();
    00294     }
    00296
    00297   protected:
    00303     virtual void PrintImpl(const char* str)=0;
    00304
    00306     virtual void PrintfImpl(const char* pformat, va_list ap)=0;
    00307
    00309     virtual void FlushBufferImpl()=0;
    00311
    00312   private:
    00322     Journal();
    00323
    00325     Journal(const Journal&);
    00326
    00328     void operator=(const Journal&);
    00330
    00332     std::string name_;
    00333
    00335     Index print_levels_[J_LAST_CATEGORY];
    00336   };
    00337
    00338
    00343   class FileJournal : public Journal
    00344   {
    00345   public:
    00347     FileJournal(const std::string& name, EJournalLevel default_level);
    00348
    00350     virtual ~FileJournal();
    00351
    00359     bool Open(const char* fname);
    00360
    00361   protected:
    00367     virtual void PrintImpl(const char* str);
    00368
    00370     virtual void PrintfImpl(const char* pformat, va_list ap);
    00371
    00373     virtual void FlushBufferImpl();
    00375
    00376   private:
    00386     FileJournal();
    00387
    00389     FileJournal(const FileJournal&);
    00390
    00392     void operator=(const FileJournal&);
    00394
    00396     FILE* file_;
    00397   };
    00398 }
    00399
    00400 #endif