[Bf-blender-cvs] [86de8ba] depsgraph_refactor: New utility class IDPtr/ConstIDPtr for handling ID subtypes.

Lukas Tönne noreply at git.blender.org
Mon Apr 7 18:29:53 CEST 2014


Commit: 86de8baa658c0a21b9726cb3a84f3c84c0875275
Author: Lukas Tönne
Date:   Mon Apr 7 17:43:01 2014 +0200
https://developer.blender.org/rB86de8baa658c0a21b9726cb3a84f3c84c0875275

New utility class IDPtr/ConstIDPtr for handling ID subtypes.

This supports implicit casting from ID C subtypes (e.g. Scene, Object)
to plain ID without having to access &xxx->id or do explicit casts every
time. Also could provide upcast facilities later and possibly assert
based on the ID name prefix.

===================================================================

M	source/blender/depsgraph/CMakeLists.txt
A	source/blender/depsgraph/util/depsgraph_util_id.h

===================================================================

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index f86a868..2fa624c 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -66,6 +66,7 @@ set(SRC
 	intern/depsgraph_types.h
 	intern/stubs.h
 	util/depsgraph_util_hash.h
+	util/depsgraph_util_id.h
 	util/depsgraph_util_map.h
 	util/depsgraph_util_set.h
 	util/depsgraph_util_string.h
diff --git a/source/blender/depsgraph/util/depsgraph_util_id.h b/source/blender/depsgraph/util/depsgraph_util_id.h
new file mode 100644
index 0000000..63c67fb
--- /dev/null
+++ b/source/blender/depsgraph/util/depsgraph_util_id.h
@@ -0,0 +1,68 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Lukas Toenne
+ * Contributor(s): None yet
+ */
+
+#ifndef __DEPSGRAPH_UTIL_ID_H__
+#define __DEPSGRAPH_UTIL_ID_H__
+
+/* Helper types for handling ID subtypes in C
+ * 
+ * These can be casted implicitly from/to ID*
+ * without the need to access nested members (like &scene->id)
+ */
+
+struct IDPtr {
+	IDPtr(ID *id) : m_ptr(id) {}
+	template <typename IDType>
+	IDPtr(IDType *id) : m_ptr(&id->id) {}
+	
+	const IDPtr &operator=(ID *id) { m_ptr = id; return *this; }
+	template <typename IDType>
+	const IDPtr &operator=(IDType *id) { m_ptr = &id->id; return *this; }
+	
+	operator ID *() const { return m_ptr; }
+	ID &operator *() const { return *m_ptr; }
+	ID *operator ->() const { return m_ptr; }
+	
+private:
+	ID *m_ptr;
+};
+
+struct ConstIDPtr {
+	ConstIDPtr(const ID *id) : m_ptr(id) {}
+	template <typename IDType>
+	ConstIDPtr(const IDType *id) : m_ptr(&id->id) {}
+	
+	const ConstIDPtr &operator=(const ID *id) { m_ptr = id; return *this; }
+	template <typename IDType>
+	const ConstIDPtr &operator=(const IDType *id) { m_ptr = &id->id; return *this; }
+	
+	operator const ID *() const { return m_ptr; }
+	const ID &operator *() const { return *m_ptr; }
+	const ID *operator ->() const { return m_ptr; }
+	
+private:
+	const ID *m_ptr;
+};
+
+#endif /* __DEPSGRAPH_UTIL_ID_H__ */




More information about the Bf-blender-cvs mailing list