[Bf-blender-cvs] [19d2f7d9cf1] temp-socket-decl-refactor: separate declaration from buildrs

Jacques Lucke noreply at git.blender.org
Wed Sep 15 14:30:00 CEST 2021


Commit: 19d2f7d9cf10e904ca4f554e5e40532eb2b27768
Author: Jacques Lucke
Date:   Wed Sep 15 12:43:49 2021 +0200
Branches: temp-socket-decl-refactor
https://developer.blender.org/rB19d2f7d9cf10e904ca4f554e5e40532eb2b27768

separate declaration from buildrs

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

M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/NOD_socket_declarations.hh
M	source/blender/nodes/intern/node_socket_declarations.cc

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

diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index 7ba4ac52b86..12791c78ea9 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -31,8 +31,12 @@ class SocketDeclaration {
  protected:
   std::string name_;
   std::string identifier_;
+  bool hide_label = false;
+  bool hide_value_ = false;
+  bool is_multi_input_ = false;
 
   friend NodeDeclarationBuilder;
+  template<typename SocketDecl> friend class SocketDeclarationBuilder;
 
  public:
   virtual ~SocketDeclaration() = default;
@@ -45,6 +49,40 @@ class SocketDeclaration {
   StringRefNull identifier() const;
 };
 
+class BaseSocketDeclarationBuilder {
+ public:
+  virtual ~BaseSocketDeclarationBuilder() = default;
+};
+
+template<typename SocketDecl>
+class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
+ protected:
+  using Self = typename SocketDecl::Builder;
+  static_assert(std::is_base_of_v<SocketDeclaration, SocketDecl>);
+  SocketDecl *decl_;
+
+  friend class NodeDeclarationBuilder;
+
+ public:
+  Self &hide_label(bool value)
+  {
+    decl_->hide_label = value;
+    return *(Self *)this;
+  }
+
+  Self &hide_value(bool value)
+  {
+    decl_->hide_value_ = value;
+    return *(Self *)this;
+  }
+
+  Self &multi_input(bool value)
+  {
+    decl_->is_multi_input = value;
+    return *(Self *)this;
+  }
+};
+
 using SocketDeclarationPtr = std::unique_ptr<SocketDeclaration>;
 
 class NodeDeclaration {
@@ -67,12 +105,15 @@ class NodeDeclaration {
 class NodeDeclarationBuilder {
  private:
   NodeDeclaration &declaration_;
+  Vector<std::unique_ptr<BaseSocketDeclarationBuilder>> builders_;
 
  public:
   NodeDeclarationBuilder(NodeDeclaration &declaration);
 
-  template<typename DeclType> DeclType &add_input(StringRef name, StringRef identifier = "");
-  template<typename DeclType> DeclType &add_output(StringRef name, StringRef identifier = "");
+  template<typename DeclType>
+  typename DeclType::Builder &add_input(StringRef name, StringRef identifier = "");
+  template<typename DeclType>
+  typename DeclType::Builder &add_output(StringRef name, StringRef identifier = "");
 };
 
 /* --------------------------------------------------------------------
@@ -99,27 +140,37 @@ inline NodeDeclarationBuilder::NodeDeclarationBuilder(NodeDeclaration &declarati
 }
 
 template<typename DeclType>
-inline DeclType &NodeDeclarationBuilder::add_input(StringRef name, StringRef identifier)
+inline typename DeclType::Builder &NodeDeclarationBuilder::add_input(StringRef name,
+                                                                     StringRef identifier)
 {
   static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
+  using Builder = typename DeclType::Builder;
   std::unique_ptr<DeclType> socket_decl = std::make_unique<DeclType>();
-  DeclType &ref = *socket_decl;
-  ref.name_ = name;
-  ref.identifier_ = identifier.is_empty() ? name : identifier;
+  std::unique_ptr<Builder> socket_decl_builder = std::make_unique<Builder>();
+  socket_decl_builder->decl_ = &*socket_decl;
+  socket_decl->name_ = name;
+  socket_decl->identifier_ = identifier.is_empty() ? name : identifier;
   declaration_.inputs_.append(std::move(socket_decl));
-  return ref;
+  Builder &socket_decl_builder_ref = *socket_decl_builder;
+  builders_.append(std::move(socket_decl_builder));
+  return socket_decl_builder_ref;
 }
 
 template<typename DeclType>
-inline DeclType &NodeDeclarationBuilder::add_output(StringRef name, StringRef identifier)
+inline typename DeclType::Builder &NodeDeclarationBuilder::add_output(StringRef name,
+                                                                      StringRef identifier)
 {
   static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
+  using Builder = typename DeclType::Builder;
   std::unique_ptr<DeclType> socket_decl = std::make_unique<DeclType>();
-  DeclType &ref = *socket_decl;
-  ref.name_ = name;
-  ref.identifier_ = identifier.is_empty() ? name : identifier;
+  std::unique_ptr<Builder> socket_decl_builder = std::make_unique<Builder>();
+  socket_decl_builder->decl_ = &*socket_decl;
+  socket_decl->name_ = name;
+  socket_decl->identifier_ = identifier.is_empty() ? name : identifier;
   declaration_.outputs_.append(std::move(socket_decl));
-  return ref;
+  Builder &socket_decl_builder_ref = *socket_decl_builder;
+  builders_.append(std::move(socket_decl_builder));
+  return socket_decl_builder_ref;
 }
 
 /* --------------------------------------------------------------------
diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh
index 11352111356..0524fd87a37 100644
--- a/source/blender/nodes/NOD_socket_declarations.hh
+++ b/source/blender/nodes/NOD_socket_declarations.hh
@@ -32,34 +32,41 @@ class Float : public SocketDeclaration {
   float soft_max_value_ = FLT_MAX;
   PropertySubType subtype_ = PROP_NONE;
 
+  friend class FloatBuilder;
+
+ public:
+  using Builder = class FloatBuilder;
+
+  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+  bool matches(const bNodeSocket &socket) const override;
+  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class FloatBuilder : public SocketDeclarationBuilder<Float> {
  public:
-  Float &min(const float value)
+  FloatBuilder &min(const float value)
   {
-    soft_min_value_ = value;
+    decl_->soft_min_value_ = value;
     return *this;
   }
 
-  Float &max(const float value)
+  FloatBuilder &max(const float value)
   {
-    soft_max_value_ = value;
+    decl_->soft_max_value_ = value;
     return *this;
   }
 
-  Float &default_value(const float value)
+  FloatBuilder &default_value(const float value)
   {
-    default_value_ = value;
+    decl_->default_value_ = value;
     return *this;
   }
 
-  Float &subtype(PropertySubType subtype)
+  FloatBuilder &subtype(PropertySubType subtype)
   {
-    subtype_ = subtype;
+    decl_->subtype_ = subtype;
     return *this;
   }
-
-  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
-  bool matches(const bNodeSocket &socket) const override;
-  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
 };
 
 class Int : public SocketDeclaration {
@@ -69,34 +76,41 @@ class Int : public SocketDeclaration {
   int soft_max_value_ = INT32_MAX;
   PropertySubType subtype_ = PROP_NONE;
 
+  friend class IntBuilder;
+
+ public:
+  using Builder = class IntBuilder;
+
+  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+  bool matches(const bNodeSocket &socket) const override;
+  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class IntBuilder : public SocketDeclarationBuilder<Int> {
  public:
-  Int &min(const int value)
+  IntBuilder &min(const int value)
   {
-    soft_min_value_ = value;
+    decl_->soft_min_value_ = value;
     return *this;
   }
 
-  Int &max(const int value)
+  IntBuilder &max(const int value)
   {
-    soft_max_value_ = value;
+    decl_->soft_max_value_ = value;
     return *this;
   }
 
-  Int &default_value(const int value)
+  IntBuilder &default_value(const int value)
   {
-    default_value_ = value;
+    decl_->default_value_ = value;
     return *this;
   }
 
-  Int &subtype(PropertySubType subtype)
+  IntBuilder &subtype(PropertySubType subtype)
   {
-    subtype_ = subtype;
+    decl_->subtype_ = subtype;
     return *this;
   }
-
-  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
-  bool matches(const bNodeSocket &socket) const override;
-  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
 };
 
 class Vector : public SocketDeclaration {
@@ -106,76 +120,100 @@ class Vector : public SocketDeclaration {
   float soft_max_value_ = FLT_MAX;
   PropertySubType subtype_ = PROP_NONE;
 
+  friend class VectorBuilder;
+
  public:
-  Vector &default_value(const float3 value)
+  using Builder = class VectorBuilder;
+
+  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+  bool matches(const bNodeSocket &socket) const override;
+  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class VectorBuilder : public SocketDeclarationBuilder<Vector> {
+ public:
+  VectorBuilder &default_value(const float3 value)
   {
-    default_value_ = value;
+    decl_->default_value_ = value;
     return *this;
   }
 
-  Vector &subtype(PropertySubType subtype)
+  VectorBuilder &subtype(PropertySubType subtype)
   {
-    subtype_ = subtype;
+    decl_->subtype_ = subtype;
     return *this;
   }
 
-  Vector &min(const float min)
+  VectorBuilder &min(const float min)
   {
-    soft_min_value_ = min;
+    decl_->soft_min_value_ = min;
     return *this;
   }
 
-  Vector &max(const float max)
+  VectorBuilder &max(const float max)
   {
-    soft_max_value_ = max;
+    decl_->soft_max_value_ = max;
     return *this;
   }
-
-  bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
-  bool matches(const bNodeSocket &socket) const override;
-  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
 };
 
 class Bool : public SocketDeclaration {
  private:
   bool default_value_ = false;
+  friend class BoolBuilder;
 
  public:
-  Bool &default_value(const bool value)
-  {
-    default_value_ = value;
-    return *this;
-  }
+  using Builder = class BoolBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
   bool matches(const bNodeSocket &socket) const override;
 };
 
+class BoolBuilder : public SocketDeclarationBuilder<Bool> {
+ public:
+  BoolBuilder &default_value(const bool value)
+  {
+    decl_->default_value_ = value;
+    return *this;
+  }
+};
+
 class Color : public SocketDeclaration {
  private:
   ColorGeometry4f default_value_;
 
+  friend class ColorBuilder;
+
  public:
-  Color &default_value(const C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list