# 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 Eclipse Public License.
    00004 //
    00005 // $Id: IpJournalist.hpp 2204 2013-04-13 13:49:26Z stefan $
    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 #  include <cstdarg>  // if this header is included by someone who does not define HAVE_CSTDARG or HAVE_STDARG, let's hope that cstdarg is available
    00024 # endif
    00025 #endif
    00026
    00027 #ifdef HAVE_CSTDIO
    00028 # include <cstdio>
    00029 #else
    00030 # ifdef HAVE_STDIO_H
    00031 #  include <stdio.h>
    00032 # else
    00033 #  include <cstdio>  // if this header is included by someone who does not define HAVE_CSTDIO or HAVE_STDIO, let's hope that cstdio is available
    00034 # endif
    00035 #endif
    00036
    00037 #include <string>
    00038 #include <vector>
    00039 #include <ostream>
    00040
    00041 namespace Ipopt
    00042 {
    00043
    00044   // forward declarations
    00045   class Journal;
    00046   class FileJournal;
    00047
    00051   enum EJournalLevel {
    00052     J_INSUPPRESSIBLE=-1,
    00053     J_NONE=0,
    00054     J_ERROR,
    00055     J_STRONGWARNING,
    00056     J_SUMMARY,
    00057     J_WARNING,
    00058     J_ITERSUMMARY,
    00059     J_DETAILED,
    00060     J_MOREDETAILED,
    00061     J_VECTOR,
    00062     J_MOREVECTOR,
    00063     J_MATRIX,
    00064     J_MOREMATRIX,
    00065     J_ALL,
    00066     J_LAST_LEVEL
    00067   };
    00068
    00070   enum EJournalCategory {
    00071     J_DBG=0,
    00072     J_STATISTICS,
    00073     J_MAIN,
    00074     J_INITIALIZATION,
    00075     J_BARRIER_UPDATE,
    00076     J_SOLVE_PD_SYSTEM,
    00077     J_FRAC_TO_BOUND,
    00078     J_LINEAR_ALGEBRA,
    00079     J_LINE_SEARCH,
    00080     J_HESSIAN_APPROXIMATION,
    00081     J_SOLUTION,
    00082     J_DOCUMENTATION,
    00083     J_NLP,
    00084     J_TIMING_STATISTICS,
    00085     J_USER_APPLICATION  ,
    00086     J_USER1  ,
    00087     J_USER2  ,
    00088     J_USER3  ,
    00089     J_USER4  ,
    00090     J_USER5  ,
    00091     J_USER6  ,
    00092     J_USER7  ,
    00093     J_USER8  ,
    00094     J_USER9  ,
    00095     J_USER10  ,
    00096     J_USER11  ,
    00097     J_USER12  ,
    00098     J_USER13  ,
    00099     J_USER14  ,
    00100     J_USER15  ,
    00101     J_USER16  ,
    00102     J_USER17  ,
    00103     J_LAST_CATEGORY
    00104   };
    00106
    00134   class Journalist : public ReferencedObject
    00135   {
    00136   public:
    00140     Journalist();
    00141
    00143     virtual ~Journalist();
    00145
    00152     virtual void Printf(EJournalLevel level, EJournalCategory category,
    00153                         const char* format, ...) const;
    00154
    00162     virtual void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
    00163                                       Index indent_spaces, Index max_length,
    00164                                       const std::string& line) const;
    00165
    00167     virtual void PrintfIndented(EJournalLevel level,
    00168                                 EJournalCategory category,
    00169                                 Index indent_level,
    00170                                 const char* format, ...) const;
    00171
    00174     virtual void VPrintf(EJournalLevel level,
    00175                          EJournalCategory category,
    00176                          const char* pformat,
    00177                          va_list ap) const;
    00178
    00181     virtual void VPrintfIndented(EJournalLevel level,
    00182                                  EJournalCategory category,
    00183                                  Index indent_level,
    00184                                  const char* pformat,
    00185                                  va_list ap) const;
    00186
    00193     virtual bool ProduceOutput(EJournalLevel level,
    00194                                EJournalCategory category) const;
    00195
    00196
    00201     virtual void FlushBuffer() const;
    00203
    00222     virtual bool AddJournal(const SmartPtr<Journal> jrnl);
    00223
    00231     virtual SmartPtr<Journal> AddFileJournal(
    00232       const std::string& location_name,
    00233       const std::string& fname,
    00234       EJournalLevel default_level = J_WARNING
    00235     );
    00236
    00240     virtual SmartPtr<Journal> GetJournal(const std::string& location_name);
    00241
    00243     virtual void DeleteAllJournals();
    00245
    00246   private:
    00256     Journalist(const Journalist&);
    00257
    00259     void operator=(const Journalist&);
    00261
    00262     //** Private Data Members. */
    00264     std::vector< SmartPtr<Journal> > journals_;
    00266   };
    00267
    00273   class Journal : public ReferencedObject
    00274   {
    00275   public:
    00277     Journal(const std::string& name, EJournalLevel default_level);
    00278
    00280     virtual ~Journal();
    00281
    00283     virtual std::string Name();
    00284
    00286     virtual void SetPrintLevel(
    00287       EJournalCategory category, EJournalLevel level
    00288     );
    00289
    00291     virtual void SetAllPrintLevels(
    00292       EJournalLevel level
    00293     );
    00294
    00306     virtual bool IsAccepted(
    00307       EJournalCategory category, EJournalLevel level
    00308     ) const;
    00309
    00311     virtual void Print(EJournalCategory category, EJournalLevel level,
    00312                        const char* str)
    00313     {
    00314       PrintImpl(category, level, str);
    00315     }
    00316
    00318     virtual void Printf(EJournalCategory category, EJournalLevel level,
    00319                         const char* pformat, va_list ap)
    00320     {
    00321       PrintfImpl(category, level, pformat, ap);
    00322     }
    00323
    00325     virtual void FlushBuffer()
    00326     {
    00327       FlushBufferImpl();
    00328     }
    00330
    00331   protected:
    00337     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00338                            const char* str)=0;
    00339
    00341     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00342                             const char* pformat, va_list ap)=0;
    00343
    00345     virtual void FlushBufferImpl()=0;
    00347
    00348   private:
    00358     Journal();
    00359
    00361     Journal(const Journal&);
    00362
    00364     void operator=(const Journal&);
    00366
    00368     std::string name_;
    00369
    00371     Index print_levels_[J_LAST_CATEGORY];
    00372   };
    00373
    00374
    00379   class FileJournal : public Journal
    00380   {
    00381   public:
    00383     FileJournal(const std::string& name, EJournalLevel default_level);
    00384
    00386     virtual ~FileJournal();
    00387
    00395     virtual bool Open(const char* fname);
    00396
    00397   protected:
    00403     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00404                            const char* str);
    00405
    00407     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00408                             const char* pformat, va_list ap);
    00409
    00411     virtual void FlushBufferImpl();
    00413
    00414   private:
    00424     FileJournal();
    00425
    00427     FileJournal(const FileJournal&);
    00428
    00430     void operator=(const FileJournal&);
    00432
    00434     FILE* file_;
    00435   };
    00436
    00440   class StreamJournal : public Journal
    00441   {
    00442   public:
    00444     StreamJournal(const std::string& name, EJournalLevel default_level);
    00445
    00447     virtual ~StreamJournal()
    00448     {}
    00449
    00451     void SetOutputStream(std::ostream* os);
    00452
    00453   protected:
    00459     virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
    00460                            const char* str);
    00461
    00463     virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
    00464                             const char* pformat, va_list ap);
    00465
    00467     virtual void FlushBufferImpl();
    00469
    00470   private:
    00480     StreamJournal();
    00481
    00483     StreamJournal(const StreamJournal&);
    00484
    00486     void operator=(const StreamJournal&);
    00488
    00490     std::ostream* os_;
    00491
    00493     char buffer_[32768];
    00494   };
    00495 }
    00496
    00497 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines