Ipopt Documentation  
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 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPJOURNALIST_HPP__
8 #define __IPJOURNALIST_HPP__
9 
10 #include "IpoptConfig.h"
11 #include "IpTypes.hpp"
12 #include "IpReferenced.hpp"
13 #include "IpSmartPtr.hpp"
14 
15 #include <cstdarg>
16 #include <cstdio>
17 #include <string>
18 #include <vector>
19 #include <ostream>
20 
21 namespace Ipopt
22 {
23 
24 // forward declarations
25 class Journal;
26 class FileJournal;
27 
30 
32 {
34  J_NONE = 0,
48 };
49 
52 {
53  J_DBG = 0,
86 };
88 
117 {
118 public:
121 
123 
125  virtual ~Journalist();
127 
133 
134  virtual void Printf(
135  EJournalLevel level,
136  EJournalCategory category,
137  const char* format,
138  ...
139  ) const;
140 
150  virtual void PrintStringOverLines(
151  EJournalLevel level,
152  EJournalCategory category,
153  Index indent_spaces,
154  Index max_length,
155  const std::string& line
156  ) const;
157 
159  virtual void PrintfIndented(
160  EJournalLevel level,
161  EJournalCategory category,
162  Index indent_level,
163  const char* format,
164  ...
165  ) const;
166 
168  virtual void VPrintf(
169  EJournalLevel level,
170  EJournalCategory category,
171  const char* pformat,
172  va_list ap
173  ) const;
174 
176  virtual void VPrintfIndented(
177  EJournalLevel level,
178  EJournalCategory category,
179  Index indent_level,
180  const char* pformat,
181  va_list ap
182  ) const;
183 
191  virtual bool ProduceOutput(
192  EJournalLevel level,
193  EJournalCategory category
194  ) const;
195 
202  virtual void FlushBuffer() const;
204 
216 
217  virtual bool AddJournal(
218  const SmartPtr<Journal> jrnl
219  );
220 
226  const std::string& location_name,
227  const std::string& fname,
228  EJournalLevel default_level = J_WARNING
229  );
230 
236  const std::string& location_name
237  );
238 
240  virtual void DeleteAllJournals();
242 
243 private:
254 
256  const Journalist&
257  );
258 
260  void operator=(
261  const Journalist&
262  );
264 
265  //** Private Data Members. */
267  std::vector<SmartPtr<Journal> > journals_;
269 };
270 
277 {
278 public:
281  const std::string& name,
282  EJournalLevel default_level
283  );
284 
286  virtual ~Journal();
287 
289  virtual std::string Name();
290 
292  virtual void SetPrintLevel(
293  EJournalCategory category,
294  EJournalLevel level
295  );
296 
298  virtual void SetAllPrintLevels(
299  EJournalLevel level
300  );
301 
312 
313  virtual bool IsAccepted(
314  EJournalCategory category,
315  EJournalLevel level
316  ) const;
317 
319  virtual void Print(
320  EJournalCategory category,
321  EJournalLevel level,
322  const char* str
323  )
324  {
325  PrintImpl(category, level, str);
326  }
327 
329  virtual void Printf(
330  EJournalCategory category,
331  EJournalLevel level,
332  const char* pformat,
333  va_list ap
334  )
335  {
336  PrintfImpl(category, level, pformat, ap);
337  }
338 
340  virtual void FlushBuffer()
341  {
342  FlushBufferImpl();
343  }
345 
346 protected:
352 
353  virtual void PrintImpl(
354  EJournalCategory category,
355  EJournalLevel level,
356  const char* str
357  ) = 0;
358 
360  virtual void PrintfImpl(
361  EJournalCategory category,
362  EJournalLevel level,
363  const char* pformat,
364  va_list ap
365  ) = 0;
366 
368  virtual void FlushBufferImpl() = 0;
370 
371 private:
382 
384 
387  const Journal&
388  );
389 
391  void operator=(
392  const Journal&
393  );
395 
397  std::string name_;
398 
400  Index print_levels_[J_LAST_CATEGORY];
401 };
402 
410 {
411 public:
414  const std::string& name,
415  EJournalLevel default_level
416  );
417 
419  virtual ~FileJournal();
420 
428  virtual bool Open(
429  const char* fname
430  );
431 
432 protected:
438 
439  virtual void PrintImpl(
440  EJournalCategory /*category*/,
441  EJournalLevel /*level*/,
442  const char* str
443  );
444 
446  virtual void PrintfImpl(
447  EJournalCategory /*category*/,
448  EJournalLevel /*level*/,
449  const char* pformat,
450  va_list ap
451  );
452 
454  virtual void FlushBufferImpl();
456 
457 private:
468 
470 
473  const FileJournal&
474  );
475 
477  void operator=(
478  const FileJournal&
479  );
481 
483  FILE* file_;
484 };
485 
491 {
492 public:
495  const std::string& name,
496  EJournalLevel default_level
497  );
498 
500  virtual ~StreamJournal()
501  { }
502 
505  std::ostream* os
506  );
507 
508 protected:
514 
515  virtual void PrintImpl(
516  EJournalCategory /*category*/,
517  EJournalLevel /*level*/,
518  const char* str
519  );
520 
522  virtual void PrintfImpl(
523  EJournalCategory /*category*/,
524  EJournalLevel /*level*/,
525  const char* pformat,
526  va_list ap
527  );
528 
530  virtual void FlushBufferImpl();
532 
533 private:
544 
546 
549  const StreamJournal&
550  );
551 
553  void operator=(
554  const StreamJournal&
555  );
557 
559  std::ostream* os_;
560 
562  char buffer_[32768];
563 };
564 
565 } // namespace
566 
567 #endif
FileJournal class.
FileJournal()
Default Constructor.
virtual ~FileJournal()
Destructor.
virtual void FlushBufferImpl()
Flush output buffer.
FILE * file_
FILE pointer for the output destination.
virtual bool Open(const char *fname)
Open a new file for the output location.
FileJournal(const std::string &name, EJournalLevel default_level)
Constructor.
virtual void PrintImpl(EJournalCategory, EJournalLevel, const char *str)
Print to the designated output location.
FileJournal(const FileJournal &)
Copy Constructor.
void operator=(const FileJournal &)
Default Assignment Operator.
virtual void PrintfImpl(EJournalCategory, EJournalLevel, const char *pformat, va_list ap)
Printf to the designated output location.
Journal class (part of the Journalist implementation.).
virtual void Printf(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
void operator=(const Journal &)
Default Assignment Operator.
virtual void SetPrintLevel(EJournalCategory category, EJournalLevel level)
Set the print level for a particular category.
Journal()
Default Constructor.
virtual void Print(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
virtual std::string Name()
Get the name of the Journal.
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)=0
Print to the designated output location.
virtual bool IsAccepted(EJournalCategory category, EJournalLevel level) const
Ask if a particular print level/category is accepted by the journal.
Journal(const Journal &)
Copy Constructor.
std::string name_
Name of the output location.
Journal(const std::string &name, EJournalLevel default_level)
Constructor.
virtual void FlushBufferImpl()=0
Flush output buffer.
virtual ~Journal()
Destructor.
virtual void SetAllPrintLevels(EJournalLevel level)
Set the print level for all category.
virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)=0
Printf to the designated output location.
virtual void FlushBuffer()
Flush output buffer.
Class responsible for all message output.
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.
Journalist(const Journalist &)
Copy Constructor.
virtual bool AddJournal(const SmartPtr< Journal > jrnl)
Add a new journal.
virtual void FlushBuffer() const
Method that flushes the current buffer for all Journalists.
void operator=(const Journalist &)
Default Assignment Operator.
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 DeleteAllJournals()
Delete all journals currently known by the journalist.
virtual void PrintfIndented(EJournalLevel level, EJournalCategory category, Index indent_level, const char *format,...) const
Method to print a formatted string with indentation.
std::vector< SmartPtr< Journal > > journals_
virtual SmartPtr< Journal > GetJournal(const std::string &location_name)
Get an existing journal.
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.
virtual void Printf(EJournalLevel level, EJournalCategory category, const char *format,...) const
Method to print a formatted string.
virtual SmartPtr< Journal > AddFileJournal(const std::string &location_name, const std::string &fname, EJournalLevel default_level=J_WARNING)
Add a new FileJournal.
virtual ~Journalist()
Destructor...
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...
Journalist()
Constructor.
Storing the reference count of all the smart pointers that currently reference it.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
StreamJournal class.
virtual void PrintImpl(EJournalCategory, EJournalLevel, const char *str)
Print to the designated output location.
virtual void FlushBufferImpl()
Flush output buffer.
virtual void PrintfImpl(EJournalCategory, EJournalLevel, const char *pformat, va_list ap)
Printf to the designated output location.
virtual ~StreamJournal()
Destructor.
StreamJournal(const std::string &name, EJournalLevel default_level)
Constructor.
StreamJournal(const StreamJournal &)
Copy Constructor.
StreamJournal()
Default Constructor.
void SetOutputStream(std::ostream *os)
Setting the output stream pointer.
void operator=(const StreamJournal &)
Default Assignment Operator.
std::ostream * os_
pointer to output stream for the output destination
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
EJournalCategory
Category Selection Enum.
@ J_USER16
This can be used by the user's application.
@ J_USER4
This can be used by the user's application.
@ J_USER7
This can be used by the user's application.
@ J_USER13
This can be used by the user's application.
@ J_INITIALIZATION
@ J_USER14
This can be used by the user's application.
@ J_LINEAR_ALGEBRA
@ J_USER_APPLICATION
This can be used by the user's application.
@ J_SOLUTION
@ J_TIMING_STATISTICS
@ J_USER9
This can be used by the user's application.
@ J_LINE_SEARCH
@ J_USER11
This can be used by the user's application.
@ J_DOCUMENTATION
@ J_USER2
This can be used by the user's application.
@ J_STATISTICS
@ J_USER1
This can be used by the user's application.
@ J_FRAC_TO_BOUND
@ J_USER17
This can be used by the user's application.
@ J_USER15
This can be used by the user's application.
@ J_BARRIER_UPDATE
@ J_LAST_CATEGORY
@ J_USER3
This can be used by the user's application.
@ J_USER12
This can be used by the user's application.
@ J_SOLVE_PD_SYSTEM
@ J_USER8
This can be used by the user's application.
@ J_USER10
This can be used by the user's application.
@ J_USER6
This can be used by the user's application.
@ J_USER5
This can be used by the user's application.
@ J_HESSIAN_APPROXIMATION
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
EJournalLevel
Print Level Enum.
@ J_ITERSUMMARY
@ J_STRONGWARNING
@ J_MOREMATRIX
@ J_LAST_LEVEL
@ J_MOREDETAILED
@ J_MOREVECTOR
@ J_INSUPPRESSIBLE
@ J_DETAILED