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  );
236 
241  virtual SmartPtr<Journal> GetJournal(
242  const std::string& location_name
243  );
244 
246  virtual void DeleteAllJournals();
248 
249 private:
259 
261  Journalist(
262  const Journalist&
263  );
264 
266  void operator=(
267  const Journalist&
268  );
270 
271  //** Private Data Members. */
273  std::vector<SmartPtr<Journal> > journals_;
275 };
276 
283 {
284 public:
286  Journal(
287  const std::string& name,
288  EJournalLevel default_level
289  );
290 
292  virtual ~Journal();
293 
295  virtual std::string Name();
296 
298  virtual void SetPrintLevel(
299  EJournalCategory category,
300  EJournalLevel level
301  );
302 
304  virtual void SetAllPrintLevels(
305  EJournalLevel level
306  );
307 
317 
319  virtual bool IsAccepted(
320  EJournalCategory category,
321  EJournalLevel level
322  ) const;
323 
325  virtual void Print(
326  EJournalCategory category,
327  EJournalLevel level,
328  const char* str
329  )
330  {
331  PrintImpl(category, level, str);
332  }
333 
335  virtual void Printf(
336  EJournalCategory category,
337  EJournalLevel level,
338  const char* pformat,
339  va_list ap
340  )
341  {
342  PrintfImpl(category, level, pformat, ap);
343  }
344 
346  virtual void FlushBuffer()
347  {
348  FlushBufferImpl();
349  }
351 
352 protected:
357 
359  virtual void PrintImpl(
360  EJournalCategory category,
361  EJournalLevel level,
362  const char* str
363  ) = 0;
364 
366  virtual void PrintfImpl(
367  EJournalCategory category,
368  EJournalLevel level,
369  const char* pformat,
370  va_list ap
371  ) = 0;
372 
374  virtual void FlushBufferImpl() = 0;
376 
377 private:
387 
389  Journal();
390 
392  Journal(
393  const Journal&
394  );
395 
397  void operator=(
398  const Journal&
399  );
401 
403  std::string name_;
404 
406  Index print_levels_[J_LAST_CATEGORY];
407 };
408 
416 {
417 public:
419  FileJournal(
420  const std::string& name,
421  EJournalLevel default_level
422  );
423 
425  virtual ~FileJournal();
426 
434  virtual bool Open(
435  const char* fname
436  );
437 
438 protected:
443 
445  virtual void PrintImpl(
446  EJournalCategory /*category*/,
447  EJournalLevel /*level*/,
448  const char* str
449  );
450 
452  virtual void PrintfImpl(
453  EJournalCategory /*category*/,
454  EJournalLevel /*level*/,
455  const char* pformat,
456  va_list ap
457  );
458 
460  virtual void FlushBufferImpl();
462 
463 private:
473 
475  FileJournal();
476 
478  FileJournal(
479  const FileJournal&
480  );
481 
483  void operator=(
484  const FileJournal&
485  );
487 
489  FILE* file_;
490 };
491 
497 {
498 public:
501  const std::string& name,
502  EJournalLevel default_level
503  );
504 
506  virtual ~StreamJournal()
507  { }
508 
510  void SetOutputStream(
511  std::ostream* os
512  );
513 
514 protected:
519 
521  virtual void PrintImpl(
522  EJournalCategory /*category*/,
523  EJournalLevel /*level*/,
524  const char* str
525  );
526 
528  virtual void PrintfImpl(
529  EJournalCategory /*category*/,
530  EJournalLevel /*level*/,
531  const char* pformat,
532  va_list ap
533  );
534 
536  virtual void FlushBufferImpl();
538 
539 private:
549 
551  StreamJournal();
552 
555  const StreamJournal&
556  );
557 
559  void operator=(
560  const StreamJournal&
561  );
563 
565  std::ostream* os_;
566 
568  char buffer_[32768];
569 };
570 
571 } // namespace
572 
573 #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:94
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_