Ipopt  3.12.13
IpJournalist.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2009 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id$
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPJOURNALIST_HPP__
10 #define __IPJOURNALIST_HPP__
11 
12 #include "IpoptConfig.h"
13 #include "IpTypes.hpp"
14 #include "IpReferenced.hpp"
15 #include "IpSmartPtr.hpp"
16 
17 #ifdef HAVE_CSTDARG
18 # include <cstdarg>
19 #else
20 # ifdef HAVE_STDARG_H
21 # include <stdarg.h>
22 # else
23 # 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
24 # endif
25 #endif
26 
27 #ifdef HAVE_CSTDIO
28 # include <cstdio>
29 #else
30 # ifdef HAVE_STDIO_H
31 # include <stdio.h>
32 # else
33 # 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
34 # endif
35 #endif
36 
37 #include <string>
38 #include <vector>
39 #include <ostream>
40 
41 namespace Ipopt
42 {
43 
44  // forward declarations
45  class Journal;
46  class FileJournal;
47 
53  J_NONE=0,
67  };
68 
71  J_DBG=0,
104  };
106 
135  {
136  public:
140  Journalist();
141 
143  virtual ~Journalist();
145 
152  virtual void Printf(EJournalLevel level, EJournalCategory category,
153  const char* format, ...) const;
154 
162  virtual void PrintStringOverLines(EJournalLevel level, EJournalCategory category,
163  Index indent_spaces, Index max_length,
164  const std::string& line) const;
165 
167  virtual void PrintfIndented(EJournalLevel level,
168  EJournalCategory category,
169  Index indent_level,
170  const char* format, ...) const;
171 
174  virtual void VPrintf(EJournalLevel level,
175  EJournalCategory category,
176  const char* pformat,
177  va_list ap) const;
178 
181  virtual void VPrintfIndented(EJournalLevel level,
182  EJournalCategory category,
183  Index indent_level,
184  const char* pformat,
185  va_list ap) const;
186 
193  virtual bool ProduceOutput(EJournalLevel level,
194  EJournalCategory category) const;
195 
196 
201  virtual void FlushBuffer() const;
203 
222  virtual bool AddJournal(const SmartPtr<Journal> jrnl);
223 
232  const std::string& location_name,
233  const std::string& fname,
234  EJournalLevel default_level = J_WARNING
235  );
236 
240  virtual SmartPtr<Journal> GetJournal(const std::string& location_name);
241 
243  virtual void DeleteAllJournals();
245 
246  private:
256  Journalist(const Journalist&);
257 
259  void operator=(const Journalist&);
261 
262  //** Private Data Members. */
264  std::vector< SmartPtr<Journal> > journals_;
266  };
267 
273  class Journal : public ReferencedObject
274  {
275  public:
277  Journal(const std::string& name, EJournalLevel default_level);
278 
280  virtual ~Journal();
281 
283  virtual std::string Name();
284 
286  virtual void SetPrintLevel(
287  EJournalCategory category, EJournalLevel level
288  );
289 
291  virtual void SetAllPrintLevels(
292  EJournalLevel level
293  );
294 
306  virtual bool IsAccepted(
307  EJournalCategory category, EJournalLevel level
308  ) const;
309 
311  virtual void Print(EJournalCategory category, EJournalLevel level,
312  const char* str)
313  {
314  PrintImpl(category, level, str);
315  }
316 
318  virtual void Printf(EJournalCategory category, EJournalLevel level,
319  const char* pformat, va_list ap)
320  {
321  PrintfImpl(category, level, pformat, ap);
322  }
323 
325  virtual void FlushBuffer()
326  {
327  FlushBufferImpl();
328  }
330 
331  protected:
337  virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
338  const char* str)=0;
339 
341  virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
342  const char* pformat, va_list ap)=0;
343 
345  virtual void FlushBufferImpl()=0;
347 
348  private:
358  Journal();
359 
361  Journal(const Journal&);
362 
364  void operator=(const Journal&);
366 
368  std::string name_;
369 
372  };
373 
374 
379  class FileJournal : public Journal
380  {
381  public:
383  FileJournal(const std::string& name, EJournalLevel default_level);
384 
386  virtual ~FileJournal();
387 
395  virtual bool Open(const char* fname);
396 
397  protected:
403  virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
404  const char* str);
405 
407  virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
408  const char* pformat, va_list ap);
409 
411  virtual void FlushBufferImpl();
413 
414  private:
424  FileJournal();
425 
427  FileJournal(const FileJournal&);
428 
430  void operator=(const FileJournal&);
432 
434  FILE* file_;
435  };
436 
440  class StreamJournal : public Journal
441  {
442  public:
444  StreamJournal(const std::string& name, EJournalLevel default_level);
445 
447  virtual ~StreamJournal()
448  {}
449 
451  void SetOutputStream(std::ostream* os);
452 
453  protected:
459  virtual void PrintImpl(EJournalCategory category, EJournalLevel level,
460  const char* str);
461 
463  virtual void PrintfImpl(EJournalCategory category, EJournalLevel level,
464  const char* pformat, va_list ap);
465 
467  virtual void FlushBufferImpl();
469 
470  private:
480  StreamJournal();
481 
484 
486  void operator=(const StreamJournal&);
488 
490  std::ostream* os_;
491 
493  char buffer_[32768];
494  };
495 }
496 
497 #endif
Ipopt::FileJournal::PrintImpl
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
Ipopt::J_USER5
This can be used by the user's application.
Definition: IpJournalist.hpp:90
Ipopt::J_INSUPPRESSIBLE
Definition: IpJournalist.hpp:52
Ipopt::Journalist::Printf
virtual void Printf(EJournalLevel level, EJournalCategory category, const char *format,...) const
Method to print a formatted string.
Ipopt::Journalist::Journalist
Journalist()
Constructor.
Ipopt::Journalist::DeleteAllJournals
virtual void DeleteAllJournals()
Delete all journals curently known by the journalist.
Ipopt::J_MAIN
Definition: IpJournalist.hpp:73
Ipopt::Journal::Printf
virtual void Printf(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
Definition: IpJournalist.hpp:318
Ipopt::J_USER10
This can be used by the user's application.
Definition: IpJournalist.hpp:95
Ipopt::FileJournal
FileJournal class.
Definition: IpJournalist.hpp:379
Ipopt::J_MOREVECTOR
Definition: IpJournalist.hpp:62
Ipopt::Journal::IsAccepted
virtual bool IsAccepted(EJournalCategory category, EJournalLevel level) const
Ask if a particular print level/category is accepted by the journal.
Ipopt::J_BARRIER_UPDATE
Definition: IpJournalist.hpp:75
Ipopt::J_USER7
This can be used by the user's application.
Definition: IpJournalist.hpp:92
Ipopt::Journalist::VPrintf
virtual void VPrintf(EJournalLevel level, EJournalCategory category, const char *pformat, va_list ap) const
Method to print a formatted string using the va_list argument.
Ipopt::J_WARNING
Definition: IpJournalist.hpp:57
IpSmartPtr.hpp
Ipopt::J_SOLVE_PD_SYSTEM
Definition: IpJournalist.hpp:76
Ipopt::Journalist::PrintfIndented
virtual void PrintfIndented(EJournalLevel level, EJournalCategory category, Index indent_level, const char *format,...) const
Method to print a formatted string with indentation.
Ipopt::J_SOLUTION
Definition: IpJournalist.hpp:81
Ipopt
Definition: matlabjournal.hpp:14
Ipopt::J_USER6
This can be used by the user's application.
Definition: IpJournalist.hpp:91
Ipopt::J_MATRIX
Definition: IpJournalist.hpp:63
Ipopt::J_SUMMARY
Definition: IpJournalist.hpp:56
Ipopt::FileJournal::PrintfImpl
virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
Ipopt::J_ALL
Definition: IpJournalist.hpp:65
Ipopt::J_USER9
This can be used by the user's application.
Definition: IpJournalist.hpp:94
Ipopt::J_LINE_SEARCH
Definition: IpJournalist.hpp:79
Ipopt::J_ERROR
Definition: IpJournalist.hpp:54
Ipopt::J_USER13
This can be used by the user's application.
Definition: IpJournalist.hpp:98
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
Ipopt::StreamJournal::operator=
void operator=(const StreamJournal &)
Overloaded Equals Operator.
Ipopt::Journalist::FlushBuffer
virtual void FlushBuffer() const
Method that flushes the current buffer for all Journalists.
Ipopt::J_FRAC_TO_BOUND
Definition: IpJournalist.hpp:77
Ipopt::Journalist::PrintStringOverLines
virtual void PrintStringOverLines(EJournalLevel level, EJournalCategory category, Index indent_spaces, Index max_length, const std::string &line) const
Method to print a long string including indentation.
Ipopt::Journalist::ProduceOutput
virtual bool ProduceOutput(EJournalLevel level, EJournalCategory category) const
Method that returns true if there is a Journal that would write output for the given JournalLevel and...
Ipopt::Journalist::VPrintfIndented
virtual void VPrintfIndented(EJournalLevel level, EJournalCategory category, Index indent_level, const char *pformat, va_list ap) const
Method to print a formatted string with indentation, using the va_list argument.
Ipopt::Journal::~Journal
virtual ~Journal()
Destructor.
Ipopt::StreamJournal::SetOutputStream
void SetOutputStream(std::ostream *os)
Setting the output stream pointer.
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::J_MOREMATRIX
Definition: IpJournalist.hpp:64
Ipopt::StreamJournal::PrintfImpl
virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
Ipopt::J_USER17
This can be used by the user's application.
Definition: IpJournalist.hpp:102
Ipopt::FileJournal::~FileJournal
virtual ~FileJournal()
Destructor.
Ipopt::Journal
Journal class (part of the Journalist implementation.).
Definition: IpJournalist.hpp:273
Ipopt::J_STATISTICS
Definition: IpJournalist.hpp:72
Ipopt::Journal::FlushBufferImpl
virtual void FlushBufferImpl()=0
Flush output buffer.
Ipopt::J_NONE
Definition: IpJournalist.hpp:53
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::J_DOCUMENTATION
Definition: IpJournalist.hpp:82
Ipopt::J_USER8
This can be used by the user's application.
Definition: IpJournalist.hpp:93
Ipopt::J_USER15
This can be used by the user's application.
Definition: IpJournalist.hpp:100
IpTypes.hpp
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::Journal::FlushBuffer
virtual void FlushBuffer()
Flush output buffer.
Definition: IpJournalist.hpp:325
Ipopt::J_VECTOR
Definition: IpJournalist.hpp:61
Ipopt::J_USER14
This can be used by the user's application.
Definition: IpJournalist.hpp:99
Ipopt::J_STRONGWARNING
Definition: IpJournalist.hpp:55
Ipopt::Journal::SetPrintLevel
virtual void SetPrintLevel(EJournalCategory category, EJournalLevel level)
Set the print level for a particular category.
Ipopt::J_INITIALIZATION
Definition: IpJournalist.hpp:74
IpReferenced.hpp
Ipopt::Journal::print_levels_
Index print_levels_[J_LAST_CATEGORY]
vector of integers indicating the level for each category
Definition: IpJournalist.hpp:371
Ipopt::Journal::Journal
Journal()
Default Constructor.
Ipopt::J_LAST_LEVEL
Definition: IpJournalist.hpp:66
Ipopt::J_TIMING_STATISTICS
Definition: IpJournalist.hpp:84
Ipopt::Journal::PrintfImpl
virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)=0
Printf to the designated output location.
Ipopt::J_USER11
This can be used by the user's application.
Definition: IpJournalist.hpp:96
IpoptConfig.h
Ipopt::Journal::Name
virtual std::string Name()
Get the name of the Journal.
Ipopt::Journal::Print
virtual void Print(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
Definition: IpJournalist.hpp:311
Ipopt::FileJournal::FlushBufferImpl
virtual void FlushBufferImpl()
Flush output buffer.
Ipopt::Journal::SetAllPrintLevels
virtual void SetAllPrintLevels(EJournalLevel level)
Set the print level for all category.
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::J_DETAILED
Definition: IpJournalist.hpp:59
Ipopt::StreamJournal::FlushBufferImpl
virtual void FlushBufferImpl()
Flush output buffer.
Ipopt::Journal::operator=
void operator=(const Journal &)
Overloaded Equals Operator.
Ipopt::FileJournal::Open
virtual bool Open(const char *fname)
Open a new file for the output location.
Ipopt::StreamJournal::PrintImpl
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
Ipopt::FileJournal::file_
FILE * file_
FILE pointer for the output destination.
Definition: IpJournalist.hpp:434
Ipopt::FileJournal::operator=
void operator=(const FileJournal &)
Overloaded Equals Operator.
Ipopt::J_USER12
This can be used by the user's application.
Definition: IpJournalist.hpp:97
Ipopt::Journalist::AddFileJournal
virtual SmartPtr< Journal > AddFileJournal(const std::string &location_name, const std::string &fname, EJournalLevel default_level=J_WARNING)
Add a new FileJournal.
Ipopt::J_LINEAR_ALGEBRA
Definition: IpJournalist.hpp:78
Ipopt::J_HESSIAN_APPROXIMATION
Definition: IpJournalist.hpp:80
Ipopt::Journalist::AddJournal
virtual bool AddJournal(const SmartPtr< Journal > jrnl)
Add a new journal.
Ipopt::Journalist::journals_
std::vector< SmartPtr< Journal > > journals_
Definition: IpJournalist.hpp:264
Ipopt::StreamJournal
StreamJournal class.
Definition: IpJournalist.hpp:440
Ipopt::Journalist::~Journalist
virtual ~Journalist()
Destructor...
Ipopt::FileJournal::FileJournal
FileJournal()
Default Constructor.
Ipopt::J_LAST_CATEGORY
Definition: IpJournalist.hpp:103
Ipopt::Journalist::GetJournal
virtual SmartPtr< Journal > GetJournal(const std::string &location_name)
Get an existing journal.
Ipopt::J_MOREDETAILED
Definition: IpJournalist.hpp:60
Ipopt::J_USER_APPLICATION
This can be used by the user's application.
Definition: IpJournalist.hpp:85
Ipopt::Journalist::operator=
void operator=(const Journalist &)
Overloaded Equals Operator.
Ipopt::StreamJournal::os_
std::ostream * os_
pointer to output stream for the output destination
Definition: IpJournalist.hpp:490
Ipopt::J_ITERSUMMARY
Definition: IpJournalist.hpp:58
Ipopt::J_DBG
Definition: IpJournalist.hpp:71
Ipopt::Journal::name_
std::string name_
Name of the output location.
Definition: IpJournalist.hpp:368
Ipopt::J_USER1
This can be used by the user's application.
Definition: IpJournalist.hpp:86
Ipopt::Journal::PrintImpl
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)=0
Print to the designated output location.
Ipopt::J_USER3
This can be used by the user's application.
Definition: IpJournalist.hpp:88
Ipopt::StreamJournal::StreamJournal
StreamJournal()
Default Constructor.
Ipopt::J_USER4
This can be used by the user's application.
Definition: IpJournalist.hpp:89
Ipopt::J_USER2
This can be used by the user's application.
Definition: IpJournalist.hpp:87
Ipopt::ReferencedObject
ReferencedObject class.
Definition: IpReferenced.hpp:174
Ipopt::J_USER16
This can be used by the user's application.
Definition: IpJournalist.hpp:101
Ipopt::StreamJournal::buffer_
char buffer_[32768]
buffer for sprintf.
Definition: IpJournalist.hpp:493
Ipopt::J_NLP
Definition: IpJournalist.hpp:83
Ipopt::StreamJournal::~StreamJournal
virtual ~StreamJournal()
Destructor.
Definition: IpJournalist.hpp:447