[Bf-blender-cvs] [66a5b1f6e50] cycles-x: Cycles X: Allow use enum class for node socket

Sergey Sharybin noreply at git.blender.org
Wed Sep 8 18:32:00 CEST 2021


Commit: 66a5b1f6e50dbc84916712dc28d02843bd113965
Author: Sergey Sharybin
Date:   Wed Sep 8 18:15:06 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB66a5b1f6e50dbc84916712dc28d02843bd113965

Cycles X: Allow use enum class for node socket

Some C++ SFINAE magic to implicitly cast enum classes to integer.

Differential Revision: https://developer.blender.org/D12430

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

M	intern/cycles/graph/node.h

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

diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h
index b2c5129b440..8f27a82d37b 100644
--- a/intern/cycles/graph/node.h
+++ b/intern/cycles/graph/node.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <type_traits>
+
 #include "graph/node_type.h"
 
 #include "util/util_array.h"
@@ -114,6 +116,15 @@ struct Node {
   void set(const SocketType &input, const Transform &value);
   void set(const SocketType &input, Node *value);
 
+  /* Implicitly cast enums and enum classes to integer, which matches an internal way of how
+   * enumerator values are stored and accessed in a generic API. */
+  template<class ValueType, typename std::enable_if_t<std::is_enum_v<ValueType>> * = nullptr>
+  void set(const SocketType &input, const ValueType &value)
+  {
+    static_assert(sizeof(ValueType) <= sizeof(int), "Enumerator type should fit int");
+    set(input, static_cast<int>(value));
+  }
+
   /* set array values. the memory from the input array will taken over
    * by the node and the input array will be empty after return */
   void set(const SocketType &input, array<bool> &value);



More information about the Bf-blender-cvs mailing list