Ipopt 3.11.9
Loading...
Searching...
No Matches
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
41namespace Ipopt
42{
43
44 // forward declarations
45 class Journal;
46 class FileJournal;
47
68
106
135 {
136 public:
141
143 virtual ~Journalist();
145
152 virtual void Printf(EJournalLevel level, EJournalCategory category,
153 const char* format, ...) const;
154
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:
257
259 void operator=(const Journalist&);
261
262 //** Private Data Members. */
264 std::vector< SmartPtr<Journal> > journals_;
266 };
267
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 {
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:
359
362
364 void operator=(const Journal&);
366
368 std::string name_;
369
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:
425
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
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:
481
484
488
490 std::ostream* os_;
491
493 char buffer_[32768];
494 };
495}
496
497#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 PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
FileJournal(const FileJournal &)
Copy Constructor.
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
void operator=(const FileJournal &)
Overloaded Equals Operator.
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 &)
Overloaded Equals 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.
Index print_levels_[J_LAST_CATEGORY]
vector of integers indicating the level for each category
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.
std::vector< SmartPtr< Journal > > journals_
Journalist(const Journalist &)
Copy Constructor.
virtual bool AddJournal(const SmartPtr< Journal > jrnl)
Add a new journal.
virtual SmartPtr< Journal > GetJournal(const std::string &location_name)
Get an existing journal.
virtual void FlushBuffer() const
Method that flushes the current buffer for all Journalists.
void operator=(const Journalist &)
Overloaded Equals 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 curently 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.
virtual SmartPtr< Journal > AddFileJournal(const std::string &location_name, const std::string &fname, EJournalLevel default_level=J_WARNING)
Add a new FileJournal.
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 ~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.
ReferencedObject class.
Template class for Smart Pointers.
StreamJournal class.
virtual void FlushBufferImpl()
Flush output buffer.
virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, const char *pformat, va_list ap)
Printf to the designated output location.
virtual void PrintImpl(EJournalCategory category, EJournalLevel level, const char *str)
Print to the designated output location.
virtual ~StreamJournal()
Destructor.
char buffer_[32768]
buffer for sprintf.
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 &)
Overloaded Equals Operator.
std::ostream * os_
pointer to output stream for the output destination
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_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_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:19
EJournalLevel
Print Level Enum.
@ J_ITERSUMMARY
@ J_STRONGWARNING
@ J_MOREDETAILED
@ J_INSUPPRESSIBLE