Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
appender.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_APPENDER_H_)
21 #define __MITSUBA_CORE_APPENDER_H_
22 
23 #include <mitsuba/mitsuba.h>
24 
26 
27 /** \brief This class defines an abstract destination
28  * for logging-relevant information
29  *
30  * \ingroup libcore
31  * \ingroup libpython
32  */
34 public:
35  /// Append a line of text with the given log level
36  virtual void append(ELogLevel level, const std::string &text) = 0;
37 
38  /**
39  * \brief Process a progress message
40  * \param progress Percentage value in [0,100]
41  * \param name Title of the progress message
42  * \param formatted Formatted string representation of the message
43  * \param eta Estimated time until 100% is reached.
44  * \param ptr Custom pointer payload. This is used to express the
45  * context of a progress message. When rendering a scene, it
46  * will usually contain a pointer to the associated \c RenderJob.
47  * \remark The \c ptr argument is missing in the Python bindings
48  */
49  virtual void logProgress(Float progress, const std::string &name,
50  const std::string &formatted, const std::string &eta,
51  const void *ptr) = 0;
52 
54 protected:
55  /// Virtual destructor
56  virtual ~Appender() { }
57 };
58 
59 /** \brief %Appender implementation, which writes to an
60  * arbitrary C++ output stream
61  *
62  * \ingroup libcore
63  * \ingroup libpython
64  */
66 public:
67  /**
68  * Create a new stream appender
69  * \remark This constructor is not exposed in the Python bindings
70  */
71  StreamAppender(std::ostream *pStream);
72 
73  /// Create a new stream appender logging to a file
74  StreamAppender(const std::string &filename);
75 
76  /// Append a line of text
77  void append(ELogLevel level, const std::string &pText);
78 
79  /// Process a progress message
80  void logProgress(Float progress, const std::string &name,
81  const std::string &formatted, const std::string &eta,
82  const void *ptr);
83 
84  /// Does this appender log to a file
85  inline bool logsToFile() const { return m_isFile; }
86 
87  /// Return the contents of the log file as a string
88  void readLog(std::string &target);
89 
90  /// Return a string representation
91  std::string toString() const;
92 
94 protected:
95  /// Virtual destructor
96  virtual ~StreamAppender();
97 private:
98  std::ostream *m_stream;
99  std::string m_fileName;
100  bool m_isFile;
101  bool m_lastMessageWasProgress;
102 };
103 
104 /** \brief %Appender implementation, which writes directly
105  * to an UNIX-style unbuffered file descriptor.
106  *
107  * \ingroup libcore
108  */
110 public:
111  /// Create a new appender
112  UnbufferedAppender(int fd);
113 
114  /// Append a line of text
115  void append(ELogLevel level, const std::string &pText);
116 
117  /// Process a progress message
118  void logProgress(Float progress, const std::string &name,
119  const std::string &formatted, const std::string &eta,
120  const void *ptr);
121 
122  /// Return a string representation
123  std::string toString() const;
124 
126 protected:
127  /// Virtual destructor
128  virtual ~UnbufferedAppender();
129 private:
130  int m_fd;
131  bool m_lastMessageWasProgress;
132 };
133 
135 
136 #endif /* __MITSUBA_CORE_APPENDER_H_ */
Appender implementation, which writes to an arbitrary C++ output stream
Definition: appender.h:65
virtual void logProgress(Float progress, const std::string &name, const std::string &formatted, const std::string &eta, const void *ptr)=0
Process a progress message.
bool logsToFile() const
Does this appender log to a file.
Definition: appender.h:85
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Appender implementation, which writes directly to an UNIX-style unbuffered file descriptor.
Definition: appender.h:109
virtual void append(ELogLevel level, const std::string &text)=0
Append a line of text with the given log level.
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
This class defines an abstract destination for logging-relevant information.
Definition: appender.h:33
ELogLevel
Available Log message types.
Definition: formatter.h:28
Parent of all Mitsuba classes.
Definition: object.h:38
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
#define MTS_NAMESPACE_END
Definition: platform.h:138