Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cobject.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_COBJECT_H_)
21 #define __MITSUBA_CORE_COBJECT_H_
22 
23 #include <mitsuba/mitsuba.h>
26 
28 
29 /** \brief Generic serializable object, which supports construction
30 * from a Properties instance.
31  *
32  * All plugins in Mitsuba derive from ConfigurableObject. This mechanism
33  * lets them accept parameters specified in an external XML file. Additionally,
34  * they can have child objects, which correspond to nested instantiation
35  * requests in the XML file.
36  *
37  * \ingroup libcore
38  * \ingroup libpython
39  */
41 public:
42  /**
43  * \brief Notify the \ref ConfigurableObject instance about
44  * its parent object
45  *
46  * The default implementation does nothing.
47  */
48  virtual void setParent(ConfigurableObject *parent);
49 
50  /// Add a child (default implementation throws an error)
51  virtual void addChild(const std::string &name, ConfigurableObject *child);
52 
53  /// Add an unnamed child
54  inline void addChild(ConfigurableObject *child) { addChild("", child); }
55 
56  /** \brief Configure the object (called \a once after construction
57  and addition of all child \ref ConfigurableObject instances)) */
58  virtual void configure();
59 
60  /// Serialize this object to a binary data stream
61  virtual void serialize(Stream *stream, InstanceManager *manager) const;
62 
63  /// Return the identifier associated with this instance (or "unnamed")
64  inline const std::string &getID() const { return m_properties.getID(); }
65 
66  /// Set the identifier associated with this instance
67  inline void setID(const std::string &name) { m_properties.setID(name); }
68 
69  /**
70  * \brief Return the properties object that was originally used to
71  * create this instance
72  *
73  * This feature mainly of use for editors and other graphical
74  * user interfaces, which present the properties of an object
75  * in some form.
76  */
77  inline const Properties &getProperties() const { return m_properties; }
78 
80 protected:
81  /// Virtual destructor
82  virtual ~ConfigurableObject() { }
83 
84  /// Construct a configurable object
85  inline ConfigurableObject(const Properties &props)
86  : SerializableObject(), m_properties(props) { }
87 
88  /// Unserialize a configurable object
89  ConfigurableObject(Stream *stream, InstanceManager *manager);
90 protected:
92 };
93 
94 /** \brief This macro creates the binary interface, which Mitsuba
95  * requires to load a plugin.
96  *
97  * \ingroup libcore
98  */
99 #define MTS_EXPORT_PLUGIN(name, descr) \
100  extern "C" { \
101  void MTS_EXPORT *CreateInstance(const Properties &props) { \
102  return new name(props); \
103  } \
104  const char MTS_EXPORT *GetDescription() { \
105  return descr; \
106  } \
107  }
108 
110 
111 #endif /* __MITSUBA_CORE_COBJECT_H_ */
const Properties & getProperties() const
Return the properties object that was originally used to create this instance.
Definition: cobject.h:77
Generic serializable object, which supports construction from a Properties instance.
Definition: cobject.h:40
ConfigurableObject(const Properties &props)
Construct a configurable object.
Definition: cobject.h:85
Base class of all reference-counted objects with serialization support.
Definition: serialization.h:35
Properties m_properties
Definition: cobject.h:91
virtual void serialize(Stream *stream, InstanceManager *manager) const =0
Serialize this object to a stream.
#define MTS_EXPORT_CORE
Definition: getopt.h:29
const std::string & getID() const
Return the identifier associated with this instance (or &quot;unnamed&quot;)
Definition: cobject.h:64
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
void addChild(ConfigurableObject *child)
Add an unnamed child.
Definition: cobject.h:54
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
void setID(const std::string &name)
Set the identifier associated with this instance.
Definition: cobject.h:67
Associative parameter map for constructing subclasses of ConfigurableObject.
Definition: properties.h:46
Coordinates the serialization and unserialization of object graphs.
Definition: serialization.h:65
#define MTS_NAMESPACE_END
Definition: platform.h:138