[Bf-blender-cvs] [d7dad425c0d] master: Nodes: Make socket declaration member variables public

Hans Goudey noreply at git.blender.org
Tue Dec 27 17:50:29 CET 2022


Commit: d7dad425c0d0c95ac35b4bf705b2ea6e8dc69eb2
Author: Hans Goudey
Date:   Tue Dec 27 11:50:17 2022 -0500
Branches: master
https://developer.blender.org/rBd7dad425c0d0c95ac35b4bf705b2ea6e8dc69eb2

Nodes: Make socket declaration member variables public

This is the best way I found to make building socket declarations without
the builder helper class work. Besides a vague hope for non-leaky
abstractions, I don't think there's any reason for these fields not to be
accessible directly.

Ref D16850

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

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

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

diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh
index 503327ac4da..f3a9ba25ca1 100644
--- a/source/blender/nodes/NOD_socket_declarations.hh
+++ b/source/blender/nodes/NOD_socket_declarations.hh
@@ -14,15 +14,14 @@ namespace blender::nodes::decl {
 class FloatBuilder;
 
 class Float : public SocketDeclaration {
- private:
-  float default_value_ = 0.0f;
-  float soft_min_value_ = -FLT_MAX;
-  float soft_max_value_ = FLT_MAX;
-  PropertySubType subtype_ = PROP_NONE;
+ public:
+  float default_value = 0.0f;
+  float soft_min_value = -FLT_MAX;
+  float soft_max_value = FLT_MAX;
+  PropertySubType subtype = PROP_NONE;
 
   friend FloatBuilder;
 
- public:
   using Builder = FloatBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -42,15 +41,14 @@ class FloatBuilder : public SocketDeclarationBuilder<Float> {
 class IntBuilder;
 
 class Int : public SocketDeclaration {
- private:
-  int default_value_ = 0;
-  int soft_min_value_ = INT32_MIN;
-  int soft_max_value_ = INT32_MAX;
-  PropertySubType subtype_ = PROP_NONE;
+ public:
+  int default_value = 0;
+  int soft_min_value = INT32_MIN;
+  int soft_max_value = INT32_MAX;
+  PropertySubType subtype = PROP_NONE;
 
   friend IntBuilder;
 
- public:
   using Builder = IntBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -70,15 +68,14 @@ class IntBuilder : public SocketDeclarationBuilder<Int> {
 class VectorBuilder;
 
 class Vector : public SocketDeclaration {
- private:
-  float3 default_value_ = {0, 0, 0};
-  float soft_min_value_ = -FLT_MAX;
-  float soft_max_value_ = FLT_MAX;
-  PropertySubType subtype_ = PROP_NONE;
+ public:
+  float3 default_value = {0, 0, 0};
+  float soft_min_value = -FLT_MAX;
+  float soft_max_value = FLT_MAX;
+  PropertySubType subtype = PROP_NONE;
 
   friend VectorBuilder;
 
- public:
   using Builder = VectorBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -99,11 +96,10 @@ class VectorBuilder : public SocketDeclarationBuilder<Vector> {
 class BoolBuilder;
 
 class Bool : public SocketDeclaration {
- private:
-  bool default_value_ = false;
+ public:
+  bool default_value = false;
   friend BoolBuilder;
 
- public:
   using Builder = BoolBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -119,12 +115,11 @@ class BoolBuilder : public SocketDeclarationBuilder<Bool> {
 class ColorBuilder;
 
 class Color : public SocketDeclaration {
- private:
-  ColorGeometry4f default_value_;
+ public:
+  ColorGeometry4f default_value;
 
   friend ColorBuilder;
 
- public:
   using Builder = ColorBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -140,12 +135,11 @@ class ColorBuilder : public SocketDeclarationBuilder<Color> {
 class StringBuilder;
 
 class String : public SocketDeclaration {
- private:
-  std::string default_value_;
+ public:
+  std::string default_value;
 
   friend StringBuilder;
 
- public:
   using Builder = StringBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -159,8 +153,8 @@ class StringBuilder : public SocketDeclarationBuilder<String> {
 };
 
 class IDSocketDeclaration : public SocketDeclaration {
- private:
-  const char *idname_;
+ public:
+  const char *idname;
 
  public:
   IDSocketDeclaration(const char *idname);
@@ -209,10 +203,9 @@ class Image : public IDSocketDeclaration {
 class ShaderBuilder;
 
 class Shader : public SocketDeclaration {
- private:
+ public:
   friend ShaderBuilder;
 
- public:
   using Builder = ShaderBuilder;
 
   bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@@ -229,25 +222,25 @@ class ShaderBuilder : public SocketDeclarationBuilder<Shader> {
 
 inline FloatBuilder &FloatBuilder::min(const float value)
 {
-  decl_->soft_min_value_ = value;
+  decl_->soft_min_value = value;
   return *this;
 }
 
 inline FloatBuilder &FloatBuilder::max(const float value)
 {
-  decl_->soft_max_value_ = value;
+  decl_->soft_max_value = value;
   return *this;
 }
 
 inline FloatBuilder &FloatBuilder::default_value(const float value)
 {
-  decl_->default_value_ = value;
+  decl_->default_value = value;
   return *this;
 }
 
 inline FloatBuilder &FloatBuilder::subtype(PropertySubType subtype)
 {
-  decl_->subtype_ = subtype;
+  decl_->subtype = subtype;
   return *this;
 }
 
@@ -259,25 +252,25 @@ inline FloatBuilder &FloatBuilder::subtype(PropertySubType subtype)
 
 inline IntBuilder &IntBuilder::min(const int value)
 {
-  decl_->soft_min_value_ = value;
+  decl_->soft_min_value = value;
   return *this;
 }
 
 inline IntBuilder &IntBuilder::max(const int value)
 {
-  decl_->soft_max_value_ = value;
+  decl_->soft_max_value = value;
   return *this;
 }
 
 inline IntBuilder &IntBuilder::default_value(const int value)
 {
-  decl_->default_value_ = value;
+  decl_->default_value = value;
   return *this;
 }
 
 inline IntBuilder &IntBuilder::subtype(PropertySubType subtype)
 {
-  decl_->subtype_ = subtype;
+  decl_->subtype = subtype;
   return *this;
 }
 
@@ -289,25 +282,25 @@ inline IntBuilder &IntBuilder::subtype(PropertySubType subtype)
 
 inline VectorBuilder &VectorBuilder::default_value(const float3 value)
 {
-  decl_->default_value_ = value;
+  decl_->default_value = value;
   return *this;
 }
 
 inline VectorBuilder &VectorBuilder::subtype(PropertySubType subtype)
 {
-  decl_->subtype_ = subtype;
+  decl_->subtype = subtype;
   return *this;
 }
 
 inline VectorBuilder &VectorBuilder::min(const float min)
 {
-  decl_->soft_min_value_ = min;
+  decl_->soft_min_value = min;
   return *this;
 }
 
 inline VectorBuilder &VectorBuilder::max(const float max)
 {
-  decl_->soft_max_value_ = max;
+  decl_->soft_max_value = max;
   return *this;
 }
 
@@ -325,7 +318,7 @@ inline VectorBuilder &VectorBuilder::compact()
 
 inline BoolBuilder &BoolBuilder::default_value(const bool value)
 {
-  decl_->default_value_ = value;
+  decl_->default_value = value;
   return *this;
 }
 
@@ -337,7 +330,7 @@ inline BoolBuilder &BoolBuilder::default_value(const bool value)
 
 inline ColorBuilder &ColorBuilder::default_value(const ColorGeometry4f value)
 {
-  decl_->default_value_ = value;
+  decl_->default_value = value;
   return *this;
 }
 
@@ -349,7 +342,7 @@ inline ColorBuilder &ColorBuilder::default_value(const ColorGeometry4f value)
 
 inline StringBuilder &StringBuilder::default_value(std::string value)
 {
-  decl_->default_value_ = std::move(value);
+  decl_->default_value = std::move(value);
   return *this;
 }
 
@@ -359,7 +352,7 @@ inline StringBuilder &StringBuilder::default_value(std::string value)
 /** \name #IDSocketDeclaration and Children Inline Methods
  * \{ */
 
-inline IDSocketDeclaration::IDSocketDeclaration(const char *idname) : idname_(idname)
+inline IDSocketDeclaration::IDSocketDeclaration(const char *idname) : idname(idname)
 {
 }
 
diff --git a/source/blender/nodes/intern/node_socket_declarations.cc b/source/blender/nodes/intern/node_socket_declarations.cc
index a7d281bcf52..44f02822ee1 100644
--- a/source/blender/nodes/intern/node_socket_declarations.cc
+++ b/source/blender/nodes/intern/node_socket_declarations.cc
@@ -71,12 +71,12 @@ static void modify_subtype_except_for_storage(bNodeSocket &socket, int new_subty
 bNodeSocket &Float::build(bNodeTree &ntree, bNode &node) const
 {
   bNodeSocket &socket = *nodeAddStaticSocket(
-      &ntree, &node, in_out_, SOCK_FLOAT, subtype_, identifier_.c_str(), name_.c_str());
+      &ntree, &node, in_out_, SOCK_FLOAT, this->subtype, identifier_.c_str(), name_.c_str());
   this->set_common_flags(socket);
   bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
-  value.min = soft_min_value_;
-  value.max = soft_max_value_;
-  value.value = default_value_;
+  value.min = this->soft_min_value;
+  value.max = this->soft_max_value;
+  value.value = this->default_value;
   return socket;
 }
 
@@ -88,14 +88,14 @@ bool Float::matches(const bNodeSocket &socket) const
   if (socket.type != SOCK_FLOAT) {
     return false;
   }
-  if (socket.typeinfo->subtype != subtype_) {
+  if (socket.typeinfo->subtype != this->subtype) {
     return false;
   }
   bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
-  if (value.min != soft_min_value_) {
+  if (value.min != this->soft_min_value) {
     return false;
   }
-  if (value.max != soft_max_value_) {
+  if (value.max != this->soft_max_value) {
     return false;
   }
   return true;
@@ -115,14 +115,14 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
     BLI_assert(socket.in_out == in_out_);
     return this->build(ntree, node);
   }
-  if (socket.typeinfo->subtype != subtype_) {
-    modify_subtype_except_for_storage(socket, subtype_);
+  if (socket.typeinfo->subtype != this->subtype) {
+    modify_subtype_except_for_storage(socket, this->subtype);
   }
   this->set_common_flags(socket);
   bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
-  value.min = soft_min_value_;
-  value.max = soft_max_value_;
-  value.subtype = subtype_;
+  value.min = this->soft_min_value;
+  value.max = this->soft_max_value;
+  value.subtype = this->subtype;
   return socket;
 }
 
@@ -135,12 +135,12 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
 bNodeSocket &Int::build(bNodeTree &ntree, bNode &node) const
 {
   bNodeSocket &socket = *nodeAddStaticSocket(
-      &ntree, &node, in_out_, SOCK_INT, subtype_, identifier_.c_str(), name_.c_str());
+      &ntree, &node, in_out_, SOCK_INT, this->subtype, identifier_.c_str(), name_.c_str());
   this->set_common_flags(socket);
   bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
-  value.min = soft_min_value_;
-  value.max = soft_max_value_;
-  value.value = default_value_;
+  value.min = this->soft_min_value;
+  value.max = this->soft_max_value;
+  value.value = this->default_value;
   return socket;
 }
 
@@ -152,14 +152,14 @@ bool Int::matches(const bNodeSocket &socket) const
   if (socket.type != SOCK_INT) {
     return false;
   }
-  if (socket.typeinfo->subtype != subtype_) {
+  if (socket.typeinfo->subtype != this->

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list