- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2009 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: IpJournalist.hpp 1479 2009-06-22 22:32:29Z 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_USER1  ,
    00077     J_USER2  ,
    00078     J_USER3  ,
    00079     J_USER4  ,
    00080     J_USER5  ,
    00081     J_USER6  ,
    00082     J_USER7  ,
    00083     J_USER8  ,
    00084     J_USER9  ,
    00085     J_USER10  ,
    00086     J_USER11  ,
    00087     J_USER12  ,
    00088     J_USER13  ,
    00089     J_USER14  ,
    00090     J_USER15  ,
    00091     J_USER16  ,
    00092     J_USER17  ,
    00093     J_LAST_CATEGORY
    00094   };
    00096
    00124   class Journalist : public ReferencedObject
    00125   {
    00126   public:
    00130     Journalist();
    00131
    00133     virtual ~Journalist();
    00135
    00142     void Printf(EJournalLevel level, EJournalCategory category,
    00143                 const char* format, ...) const;
    00144
    00152     void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
    00153                               Index indent_spaces, Index max_length,
    00154                               const std::string& line) const;
    00155
    00157     void PrintfIndented(EJournalLevel level,
    00158                         EJournalCategory category,
    00159                         Index indent_level,
    00160                         const char* format, ...) const;
    00161
    00164     void VPrintf(EJournalLevel level,
    00165                  EJournalCategory category,
    00166                  const char* pformat,
    00167                  va_list ap) const;
    00168
    00171     void VPrintfIndented(EJournalLevel level,
    00172                          EJournalCategory category,
    00173                          Index indent_level,
    00174                          const char* pformat,
    00175                          va_list ap) const;
    00176
    00183     bool ProduceOutput(EJournalLevel level,
    00184                        EJournalCategory category) const;
    00185
    00186
    00191     void FlushBuffer() const;
    00193
    00212     bool AddJournal(const SmartPtr<Journal> jrnl);
    00213
    00221     SmartPtr<Journal> AddFileJournal(
    00222       const std::string& location_name,
    00223       const std::string& fname,
    00224       EJournalLevel default_level = J_WARNING
    00225     );
    00226
    00230     SmartPtr<Journal> GetJournal(const std::string& location_name);
    00231
    00233     void DeleteAllJournals();
    00235
    00236   private:
    00246     Journalist(const Journalist&);
    00247
    00249     void operator=(const Journalist&);
    00251
    00252     //** Private Data Members. */
    00254     std::vector< SmartPtr<Journal> > journals_;
    00256   };
    00257
    00263   class Journal : public ReferencedObject
    00264   {
    00265   public:
    00267     Journal(const std::string& name, EJournalLevel default_level);
    00268
    00270     virtual ~Journal();
    00271
    00273     std::string Name();
    00274
    00276     void SetPrintLevel(
    00277       EJournalCategory category, EJournalLevel level
    00278     );
    00279
    00281     void SetAllPrintLevels(
    00282       EJournalLevel level
    00283     );
    00284
    00296     bool IsAccepted(
    00297       EJournalCategory category, EJournalLevel level
    00298     ) const;
    00299
    00301     void Print(EJournalCategory category, EJournalLevel level,
    00302                const char* str)
    00303     {
    00304       PrintImpl(category, level, str);
    00305     }
    00306
    00308     void Printf(EJournalCategory category, EJournalLevel level,
    00309                 const char* pformat, va_list ap)
    00310     {
    00311       PrintfImpl(category, level, pformat, ap);
    00312     }
    00313
    00315     void FlushBuffer()
    00316     {
    00317       FlushBufferImpl();
    00318     }
    00320
    00321   protected:
    00327     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00328                            const char* str)=0;
    00329
    00331     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00332                             const char* pformat, va_list ap)=0;
    00333
    00335     virtual void FlushBufferImpl()=0;
    00337
    00338   private:
    00348     Journal();
    00349
    00351     Journal(const Journal&);
    00352
    00354     void operator=(const Journal&);
    00356
    00358     std::string name_;
    00359
    00361     Index print_levels_[J_LAST_CATEGORY];
    00362   };
    00363
    00364
    00369   class FileJournal : public Journal
    00370   {
    00371   public:
    00373     FileJournal(const std::string& name, EJournalLevel default_level);
    00374
    00376     virtual ~FileJournal();
    00377
    00385     bool Open(const char* fname);
    00386
    00387   protected:
    00393     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00394                            const char* str);
    00395
    00397     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00398                             const char* pformat, va_list ap);
    00399
    00401     virtual void FlushBufferImpl();
    00403
    00404   private:
    00414     FileJournal();
    00415
    00417     FileJournal(const FileJournal&);
    00418
    00420     void operator=(const FileJournal&);
    00422
    00424     FILE* file_;
    00425   };
    00426
    00430   class StreamJournal : public Journal
    00431   {
    00432   public:
    00434     StreamJournal(const std::string& name, EJournalLevel default_level);
    00435
    00437     virtual ~StreamJournal()
    00438     {}
    00439
    00441     void SetOutputStream(std::ostream* os);
    00442
    00443   protected:
    00449     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00450                            const char* str);
    00451
    00453     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00454                             const char* pformat, va_list ap);
    00455
    00457     virtual void FlushBufferImpl();
    00459
    00460   private:
    00470     StreamJournal();
    00471
    00473     StreamJournal(const StreamJournal&);
    00474
    00476     void operator=(const StreamJournal&);
    00478
    00480     std::ostream* os_;
    00481
    00483     char buffer_[32768];
    00484   };
    00485 }
    00486
    00487 #endif