Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
32 {
34  J_NONE = 0,
48 };
49 
52 {
53  J_DBG = 0,
86 };
88 
117 {
118 public:
122  Journalist();
123 
125  virtual ~Journalist();
127 
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 
217  virtual bool AddJournal(
218  const SmartPtr<Journal> jrnl
219  );
220 
225  virtual SmartPtr<Journal> AddFileJournal(
226  const std::string& location_name,
227  const std::string& fname,
228  EJournalLevel default_level = J_WARNING
229  );
230 
235  virtual SmartPtr<Journal> GetJournal(
236  const std::string& location_name
237  );
238 
240  virtual void DeleteAllJournals();
242 
243 private:
255  Journalist(
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:
280  Journal(
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 
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:
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:
383  Journal();
384 
386  Journal(
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:
413  FileJournal(
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:
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:
469  FileJournal();
470 
472  FileJournal(
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 
504  void SetOutputStream(
505  std::ostream* os
506  );
507 
508 protected:
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:
545  StreamJournal();
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
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.
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.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
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.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
This can be used by the user&#39;s application.
This can be used by the user&#39;s application.
#define IPOPTLIB_EXPORT
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_