00001
00002
00003
00004
00005
00006
00007
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
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);
00232
00233 private:
00243 Journalist(const Journalist&);
00244
00246 void operator=(const Journalist&);
00248
00249
00251 std::vector< SmartPtr<Journal> > journals_;
00253 };
00254
00260 class Journal : public ReferencedObject
00261 {
00262 public:
00264 Journal(const std::string& name, EJournalLevel default_level);
00265
00267 virtual ~Journal();
00268
00270 std::string Name();
00271
00273 void SetPrintLevel(
00274 EJournalCategory category, EJournalLevel level
00275 );
00276
00278 void SetAllPrintLevels(
00279 EJournalLevel level
00280 );
00281
00293 bool IsAccepted(
00294 EJournalCategory category, EJournalLevel level
00295 ) const;
00296
00298 void Print(EJournalCategory category, EJournalLevel level,
00299 const char* str)
00300 {
00301 PrintImpl(category, level, str);
00302 }
00303
00305 void Printf(EJournalCategory category, EJournalLevel level,
00306 const char* pformat, va_list ap)
00307 {
00308 PrintfImpl(category, level, pformat, ap);
00309 }
00310
00312 void FlushBuffer()
00313 {
00314 FlushBufferImpl();
00315 }
00317
00318 protected:
00324 virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00325 const char* str)=0;
00326
00328 virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00329 const char* pformat, va_list ap)=0;
00330
00332 virtual void FlushBufferImpl()=0;
00334
00335 private:
00345 Journal();
00346
00348 Journal(const Journal&);
00349
00351 void operator=(const Journal&);
00353
00355 std::string name_;
00356
00358 Index print_levels_[J_LAST_CATEGORY];
00359 };
00360
00361
00366 class FileJournal : public Journal
00367 {
00368 public:
00370 FileJournal(const std::string& name, EJournalLevel default_level);
00371
00373 virtual ~FileJournal();
00374
00382 bool Open(const char* fname);
00383
00384 protected:
00390 virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00391 const char* str);
00392
00394 virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00395 const char* pformat, va_list ap);
00396
00398 virtual void FlushBufferImpl();
00400
00401 private:
00411 FileJournal();
00412
00414 FileJournal(const FileJournal&);
00415
00417 void operator=(const FileJournal&);
00419
00421 FILE* file_;
00422 };
00423
00427 class StreamJournal : public Journal
00428 {
00429 public:
00431 StreamJournal(const std::string& name, EJournalLevel default_level);
00432
00434 virtual ~StreamJournal()
00435 {}
00436
00438 void SetOutputStream(std::ostream* os);
00439
00440 protected:
00446 virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00447 const char* str);
00448
00450 virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00451 const char* pformat, va_list ap);
00452
00454 virtual void FlushBufferImpl();
00456
00457 private:
00467 StreamJournal();
00468
00470 StreamJournal(const StreamJournal&);
00471
00473 void operator=(const StreamJournal&);
00475
00477 std::ostream* os_;
00478
00480 char buffer_[32768];
00481 };
00482 }
00483
00484 #endif