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
00030 namespace Ipopt
00031 {
00032
00033
00034 class Journal;
00035 class FileJournal;
00036
00040 enum EJournalLevel {
00041 J_INSUPPRESSIBLE=-1,
00042 J_NONE=0,
00043 J_ERROR,
00044 J_STRONGWARNING,
00045 J_SUMMARY,
00046 J_WARNING,
00047 J_ITERSUMMARY,
00048 J_DETAILED,
00049 J_MOREDETAILED,
00050 J_VECTOR,
00051 J_MOREVECTOR,
00052 J_MATRIX,
00053 J_MOREMATRIX,
00054 J_ALL,
00055 J_LAST_LEVEL
00056 };
00057
00059 enum EJournalCategory {
00060 J_DBG=0,
00061 J_STATISTICS,
00062 J_MAIN,
00063 J_INITIALIZATION,
00064 J_BARRIER_UPDATE,
00065 J_SOLVE_PD_SYSTEM,
00066 J_FRAC_TO_BOUND,
00067 J_LINEAR_ALGEBRA,
00068 J_LINE_SEARCH,
00069 J_HESSIAN_APPROXIMATION,
00070 J_SOLUTION,
00071 J_DOCUMENTATION,
00072 J_NLP,
00073 J_TIMING_STATISTICS,
00074 J_USER_APPLICATION ,
00075 J_LAST_CATEGORY
00076 };
00078
00106 class Journalist : public ReferencedObject
00107 {
00108 public:
00112 Journalist();
00113
00115 virtual ~Journalist();
00117
00124 void Printf(EJournalLevel level, EJournalCategory category,
00125 const char* format, ...) const;
00126
00134 void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
00135 Index indent_spaces, Index max_length,
00136 const std::string& line) const;
00137
00139 void PrintfIndented(EJournalLevel level,
00140 EJournalCategory category,
00141 Index indent_level,
00142 const char* format, ...) const;
00143
00146 void VPrintf(EJournalLevel level,
00147 EJournalCategory category,
00148 const char* pformat,
00149 va_list ap) const;
00150
00153 void VPrintfIndented(EJournalLevel level,
00154 EJournalCategory category,
00155 Index indent_level,
00156 const char* pformat,
00157 va_list ap) const;
00158
00165 bool ProduceOutput(EJournalLevel level,
00166 EJournalCategory category) const;
00167
00168
00173 void FlushBuffer() const;
00175
00194 bool AddJournal(const SmartPtr<Journal> jrnl);
00195
00203 SmartPtr<Journal> AddFileJournal(
00204 const std::string& location_name,
00205 const std::string& fname,
00206 EJournalLevel default_level = J_WARNING
00207 );
00208
00212 SmartPtr<Journal> GetJournal(const std::string& location_name);
00214
00215 private:
00225 Journalist(const Journalist&);
00226
00228 void operator=(const Journalist&);
00230
00231
00233 std::vector< SmartPtr<Journal> > journals_;
00235 };
00236
00242 class Journal : public ReferencedObject
00243 {
00244 public:
00246 Journal(const std::string& name, EJournalLevel default_level);
00247
00249 virtual ~Journal();
00250
00252 std::string Name();
00253
00255 void SetPrintLevel(
00256 EJournalCategory category, EJournalLevel level
00257 );
00258
00260 void SetAllPrintLevels(
00261 EJournalLevel level
00262 );
00263
00275 bool IsAccepted(
00276 EJournalCategory category, EJournalLevel level
00277 ) const;
00278
00280 void Print(EJournalCategory category, EJournalLevel level,
00281 const char* str)
00282 {
00283 PrintImpl(category, level, str);
00284 }
00285
00287 void Printf(EJournalCategory category, EJournalLevel level,
00288 const char* pformat, va_list ap)
00289 {
00290 PrintfImpl(category, level, pformat, ap);
00291 }
00292
00294 void FlushBuffer()
00295 {
00296 FlushBufferImpl();
00297 }
00299
00300 protected:
00306 virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00307 const char* str)=0;
00308
00310 virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00311 const char* pformat, va_list ap)=0;
00312
00314 virtual void FlushBufferImpl()=0;
00316
00317 private:
00327 Journal();
00328
00330 Journal(const Journal&);
00331
00333 void operator=(const Journal&);
00335
00337 std::string name_;
00338
00340 Index print_levels_[J_LAST_CATEGORY];
00341 };
00342
00343
00348 class FileJournal : public Journal
00349 {
00350 public:
00352 FileJournal(const std::string& name, EJournalLevel default_level);
00353
00355 virtual ~FileJournal();
00356
00364 bool Open(const char* fname);
00365
00366 protected:
00372 virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
00373 const char* str);
00374
00376 virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
00377 const char* pformat, va_list ap);
00378
00380 virtual void FlushBufferImpl();
00382
00383 private:
00393 FileJournal();
00394
00396 FileJournal(const FileJournal&);
00397
00399 void operator=(const FileJournal&);
00401
00403 FILE* file_;
00404 };
00405 }
00406
00407 #endif