[Bf-blender-cvs] [49804947e94] functions: separate declaration and implementation of methods of type
Jacques Lucke
noreply at git.blender.org
Tue Jul 2 18:39:01 CEST 2019
Commit: 49804947e94ece45143317475b80e404769ed75d
Author: Jacques Lucke
Date: Tue Jul 2 16:42:20 2019 +0200
Branches: functions
https://developer.blender.org/rB49804947e94ece45143317475b80e404769ed75d
separate declaration and implementation of methods of type
===================================================================
M source/blender/functions/CMakeLists.txt
A source/blender/functions/core/type.cpp
M source/blender/functions/core/type.hpp
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 0d62e6ffbe4..efca4734456 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
initialize.cpp
core/type.hpp
+ core/type.cpp
core/function.hpp
core/function.cpp
core/data_flow_graph.hpp
diff --git a/source/blender/functions/core/type.cpp b/source/blender/functions/core/type.cpp
new file mode 100644
index 00000000000..17712afcbec
--- /dev/null
+++ b/source/blender/functions/core/type.cpp
@@ -0,0 +1,9 @@
+#include "type.hpp"
+
+namespace FN {
+
+TypeExtension::~TypeExtension()
+{
+}
+
+} // namespace FN
diff --git a/source/blender/functions/core/type.hpp b/source/blender/functions/core/type.hpp
index 1e74b2b6279..9a2d2fce14e 100644
--- a/source/blender/functions/core/type.hpp
+++ b/source/blender/functions/core/type.hpp
@@ -17,71 +17,24 @@ class TypeExtension {
Type *m_owner = nullptr;
friend Type;
- void set_owner(Type *owner)
- {
- m_owner = owner;
- }
+ void set_owner(Type *owner);
public:
- virtual ~TypeExtension()
- {
- }
+ virtual ~TypeExtension();
- Type *owner() const
- {
- return m_owner;
- }
+ Type *owner() const;
};
class Type final : public RefCountedBase {
public:
Type() = delete;
- Type(StringRef name) : m_name(name.to_std_string())
- {
- }
+ Type(StringRef name);
- const StringRefNull name() const
- {
- return m_name;
- }
+ const StringRefNull name() const;
- template<typename T> bool has_extension() const
- {
- std::lock_guard<std::mutex> lock(m_extension_mutex);
- static_assert(std::is_base_of<TypeExtension, T>::value, "");
- return m_extensions.has<T>();
- }
-
- template<typename T> T *extension() const
- {
- /* TODO: Check if we really need a lock here.
- * Since extensions can't be removed, it might be
- * to access existing extensions without a lock. */
- std::lock_guard<std::mutex> lock(m_extension_mutex);
- static_assert(std::is_base_of<TypeExtension, T>::value, "");
- return m_extensions.get<T>();
- }
-
- template<typename T, typename... Args> bool add_extension(Args &&... args)
- {
- std::lock_guard<std::mutex> lock(m_extension_mutex);
- static_assert(std::is_base_of<TypeExtension, T>::value, "");
-
- if (m_extensions.has<T>()) {
- return false;
- }
- else {
- T *new_extension = new T(std::forward<Args>(args)...);
- new_extension->set_owner(this);
- m_extensions.add(new_extension);
- return true;
- }
- }
-
- friend bool operator==(const Type &a, const Type &b)
- {
- return &a == &b;
- }
+ template<typename T> bool has_extension() const;
+ template<typename T> T *extension() const;
+ template<typename T, typename... Args> bool add_extension(Args &&... args);
private:
std::string m_name;
@@ -91,8 +44,74 @@ class Type final : public RefCountedBase {
using SharedType = AutoRefCount<Type>;
+/* Type inline functions
+ ****************************************/
+
+inline Type::Type(StringRef name) : m_name(name.to_std_string())
+{
+}
+
+inline const StringRefNull Type::name() const
+{
+ return m_name;
+}
+
+template<typename T> inline bool Type::has_extension() const
+{
+ std::lock_guard<std::mutex> lock(m_extension_mutex);
+ static_assert(std::is_base_of<TypeExtension, T>::value, "");
+ return m_extensions.has<T>();
+}
+
+template<typename T> inline T *Type::extension() const
+{
+ /* TODO: Check if we really need a lock here.
+ * Since extensions can't be removed, it might be
+ * to access existing extensions without a lock. */
+ std::lock_guard<std::mutex> lock(m_extension_mutex);
+ static_assert(std::is_base_of<TypeExtension, T>::value, "");
+ return m_extensions.get<T>();
+}
+
+template<typename T, typename... Args> inline bool Type::add_extension(Args &&... args)
+{
+ std::lock_guard<std::mutex> lock(m_extension_mutex);
+ static_assert(std::is_base_of<TypeExtension, T>::value, "");
+
+ if (m_extensions.has<T>()) {
+ return false;
+ }
+ else {
+ T *new_extension = new T(std::forward<Args>(args)...);
+ new_extension->set_owner(this);
+ m_extensions.add(new_extension);
+ return true;
+ }
+}
+
+inline bool operator==(const Type &a, const Type &b)
+{
+ return &a == &b;
+}
+
+/* Type Extension inline functions
+ ****************************************/
+
+inline void TypeExtension::set_owner(Type *owner)
+{
+ m_owner = owner;
+}
+
+inline Type *TypeExtension::owner() const
+{
+ return m_owner;
+}
+
} /* namespace FN */
+/* Make Type hashable using std::hash.
+ ****************************************/
+
namespace std {
template<> struct hash<FN::Type> {
typedef FN::Type argument_type;
More information about the Bf-blender-cvs
mailing list