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 
29 
32 {
34  J_NONE = 0,
48 };
49 
52 {
53  J_DBG = 0,
86 };
88 
117 {
118 public:
120 
122  Journalist();
123 
125  virtual ~Journalist();
127 
132 
134 #ifdef __GNUC__
135  __attribute__((format(printf, 4, 5)))
136 #endif
137  virtual void Printf(
138  EJournalLevel level,
139  EJournalCategory category,
140  const char* format,
141  ...
142  ) const;
143 
153  virtual void PrintStringOverLines(
154  EJournalLevel level,
155  EJournalCategory category,
156  Index indent_spaces,
157  Index max_length,
158  const std::string& line
159  ) const;
160 
162 #ifdef __GNUC__
163  __attribute__((format(printf, 5, 6)))
164 #endif
165  virtual void PrintfIndented(
166  EJournalLevel level,
167  EJournalCategory category,
168  Index indent_level,
169  const char* format,
170  ...
171  ) const;
172 
174  virtual void VPrintf(
175  EJournalLevel level,
176  EJournalCategory category,
177  const char* pformat,
178  va_list ap
179  ) const;
180 
182  virtual void VPrintfIndented(
183  EJournalLevel level,
184  EJournalCategory category,
185  Index indent_level,
186  const char* pformat,
187  va_list ap
188  ) const;
189 
197  virtual bool ProduceOutput(
198  EJournalLevel level,
199  EJournalCategory category
200  ) const;
201 
208  virtual void FlushBuffer() const;
210 
221 
223  virtual bool AddJournal(
224  const SmartPtr<Journal> jrnl
225  );
226 
231  virtual SmartPtr<Journal> AddFileJournal(
232  const std::string& location_name,
233  const std::string& fname,
234  EJournalLevel default_level = J_WARNING,
235  bool file_append = false
236  );
237 
242  virtual SmartPtr<Journal> GetJournal(
243  const std::string& location_name
244  );
245 
247  virtual void DeleteAllJournals();
249 
250 private:
260 
262  Journalist(
263  const Journalist&
264  );
265 
267  void operator=(
268  const Journalist&
269  );
271 
272  //** Private Data Members. */
274  std::vector<SmartPtr<Journal> > journals_;
276 };
277 
284 {
285 public:
287  Journal(
288  const std::string& name,
289  EJournalLevel default_level
290  );
291 
293  virtual ~Journal();
294 
296  virtual std::string Name();
297 
299  virtual void SetPrintLevel(
300  EJournalCategory category,
301  EJournalLevel level
302  );
303 
305  virtual void SetAllPrintLevels(
306  EJournalLevel level
307  );
308 
318 
320  virtual bool IsAccepted(
321  EJournalCategory category,
322  EJournalLevel level
323  ) const;
324 
326  virtual void Print(
327  EJournalCategory category,
328  EJournalLevel level,
329  const char* str
330  )
331  {
332  PrintImpl(category, level, str);
333  }
334 
336  virtual void Printf(
337  EJournalCategory category,
338  EJournalLevel level,
339  const char* pformat,
340  va_list ap
341  )
342  {
343  PrintfImpl(category, level, pformat, ap);
344  }
345 
347  virtual void FlushBuffer()
348  {
349  FlushBufferImpl();
350  }
352 
353 protected:
358 
360  virtual void PrintImpl(
361  EJournalCategory category,
362  EJournalLevel level,
363  const char* str
364  ) = 0;
365 
367  virtual void PrintfImpl(
368  EJournalCategory category,
369  EJournalLevel level,
370  const char* pformat,
371  va_list ap
372  ) = 0;
373 
375  virtual void FlushBufferImpl() = 0;
377 
378 private:
388 
390  Journal();
391 
393  Journal(
394  const Journal&
395  );
396 
398  void operator=(
399  const Journal&
400  );
402 
404  std::string name_;
405 
407  Index print_levels_[J_LAST_CATEGORY];
408 };
409 
417 {
418 public:
420  FileJournal(
421  const std::string& name,
422  EJournalLevel default_level
423  );
424 
426  virtual ~FileJournal();
427 
435  virtual bool Open(
436  const char* fname,
437  bool fappend = false
438  );
439 
440 protected:
445 
447  virtual void PrintImpl(
448  EJournalCategory /*category*/,
449  EJournalLevel /*level*/,
450  const char* str
451  );
452 
454  virtual void PrintfImpl(
455  EJournalCategory /*category*/,
456  EJournalLevel /*level*/,
457  const char* pformat,
458  va_list ap
459  );
460 
462  virtual void FlushBufferImpl();
464 
465 private:
475 
477  FileJournal();
478 
480  FileJournal(
481  const FileJournal&
482  );
483 
485  void operator=(
486  const FileJournal&
487  );
489 
491  FILE* file_;
492 };
493 
499 {
500 public:
503  const std::string& name,
504  EJournalLevel default_level
505  );
506 
508  virtual ~StreamJournal()
509  { }
510 
512  void SetOutputStream(
513  std::ostream* os
514  );
515 
516 protected:
521 
523  virtual void PrintImpl(
524  EJournalCategory /*category*/,
525  EJournalLevel /*level*/,
526  const char* str
527  );
528 
530  virtual void PrintfImpl(
531  EJournalCategory /*category*/,
532  EJournalLevel /*level*/,
533  const char* pformat,
534  va_list ap
535  );
536 
538  virtual void FlushBufferImpl();
540 
541 private:
551 
553  StreamJournal();
554 
557  const StreamJournal&
558  );
559 
561  void operator=(
562  const StreamJournal&
563  );
565 
567  std::ostream* os_;
568 
570  char buffer_[32768];
571 };
572 
573 } // namespace
574 
575 #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.
#define IPOPTLIB_EXPORT
Definition: config.h:88
std::ostream * os_
pointer to output stream for the output destination
This can be used by the user&#39;s application.
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.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
This file contains a base class for all exceptions and a set of macros to help with exceptions...
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:164
virtual ~StreamJournal()
Destructor.
Storing the reference count of all the smart pointers that currently reference it.
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.
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.
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.
FileJournal class.
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
Journal class (part of the Journalist implementation.).
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 void Print(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
std::vector< SmartPtr< Journal > > journals_