Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
object.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_OBJECT_H_)
21 #define __MITSUBA_CORE_OBJECT_H_
22 
23 #include <mitsuba/core/class.h>
24 
26 
27 /**
28  * \headerfile mitsuba/core/object.h mitsuba/mitsuba.h
29  * \brief Parent of all Mitsuba classes.
30  *
31  * Contains functions relevant to every object such as reference counting,
32  * limited type introspection and lifetime management.
33  *
34  * \sa ref, Class
35  * \ingroup libcore
36  * \ingroup libpython
37  */
39 public:
40  /// Construct a new object
41  Object();
42 
43  /// Return the current reference count
44  inline int getRefCount() const;
45 
46  /** \brief Increase the reference count of the
47  * object by one.
48  */
49  void incRef() const;
50 
51  /** \brief Decrease the reference count of
52  * the object and possibly deallocate it.
53  *
54  * The object will automatically be deallocated once
55  * the reference count reaches zero.
56  */
57  void decRef(bool autoDeallocate = true) const;
58 
59  /// Retrieve this object's class
60  virtual const Class *getClass() const;
61 
62  /**
63  * \brief Return a human-readable string representation
64  * of the object's contents.
65  *
66  * This function is mainly useful for debugging purposes
67  * and should ideally be implemented by all subclasses.
68  * The default implementation simply returns <tt>MyObject[unknown]</tt>,
69  * where <tt>MyObject</tt> is the name of the subclass.
70  */
71  virtual std::string toString() const;
72 
73  /** \brief Initializes the built-in reference count
74  * debugger (if enabled)
75  */
76  static void staticInitialization();
77 
78  /// Free the memory taken by staticInitialization()
79  static void staticShutdown();
80 protected:
81  /** \brief Virtual private deconstructor.
82  * (Will only be called by \ref ref)
83  */
84  virtual ~Object();
85 public:
86  static Class *m_theClass; ///< Pointer to the object's class descriptor
87 private:
88 #if !defined(_MSC_VER)
89  volatile mutable int m_refCount;
90 #else
91  volatile mutable long m_refCount;
92 #endif
93 };
94 
95 inline int Object::getRefCount() const {
96  return m_refCount;
97 }
98 
100 
101 #endif /* __MITSUBA_CORE_OBJECT_H_ */
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
static Class * m_theClass
Pointer to the object&#39;s class descriptor.
Definition: object.h:86
Stores meta-information about Object instances.
Definition: class.h:43
Parent of all Mitsuba classes.
Definition: object.h:38
int getRefCount() const
Return the current reference count.
Definition: object.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138