Ipopt  3.12.8
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: IpJournalist.hpp 2204 2013-04-13 13:49:26Z stefan $
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 
371  Index print_levels_[J_LAST_CATEGORY];
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
This can be used by the user&#39;s application.
virtual void FlushBuffer()
Flush output buffer.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
void operator=(const Journalist &)
Overloaded Equals Operator.
virtual void FlushBuffer() const
Method that flushes the current buffer for all Journalists.
virtual void PrintfIndented(EJournalLevel level, EJournalCategory category, Index indent_level, const char *format,...) const
Method to print a formatted string with indentation.
std::ostream * os_
pointer to output stream for the output destination
This can be used by the user&#39;s application.
virtual SmartPtr< Journal > AddFileJournal(const std::string &location_name, const std::string &fname, EJournalLevel default_level=J_WARNING)
Add a new FileJournal.
std::string name_
Name of the output location.
FILE * file_
FILE pointer for the output destination.
This can be used by the user&#39;s application.
EJournalLevel
Print Level Enum.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
virtual ~StreamJournal()
Destructor.
ReferencedObject class.
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.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
virtual bool AddJournal(const SmartPtr< Journal > jrnl)
Add a new journal.
This can be used by the user&#39;s application.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
This can be used by the user&#39;s application.
Journalist()
Constructor.
virtual ~Journalist()
Destructor...
This can be used by the user&#39;s application.
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.
StreamJournal class.
Class responsible for all message output.
This can be used by the user&#39;s application.
virtual void Printf(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
virtual void DeleteAllJournals()
Delete all journals curently known by the journalist.
FileJournal class.
This can be used by the user&#39;s application.
std::vector< SmartPtr< Journal > > journals_
This can be used by the user&#39;s application.
Journal class (part of the Journalist implementation.).
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...
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.
virtual void Printf(EJournalLevel level, EJournalCategory category, const char *format,...) const
Method to print a formatted string.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
EJournalCategory
Category Selection Enum.
virtual SmartPtr< Journal > GetJournal(const std::string &location_name)
Get an existing journal.
virtual void Print(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.