node.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2011-2016 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include "graph/node_type.h"
  18. #include "util/util_array.h"
  19. #include "util/util_map.h"
  20. #include "util/util_param.h"
  21. CCL_NAMESPACE_BEGIN
  22. class MD5Hash;
  23. struct Node;
  24. struct NodeType;
  25. struct Transform;
  26. /* Node */
  27. struct Node {
  28. explicit Node(const NodeType *type, ustring name = ustring());
  29. virtual ~Node();
  30. /* set values */
  31. void set(const SocketType &input, bool value);
  32. void set(const SocketType &input, int value);
  33. void set(const SocketType &input, uint value);
  34. void set(const SocketType &input, float value);
  35. void set(const SocketType &input, float2 value);
  36. void set(const SocketType &input, float3 value);
  37. void set(const SocketType &input, const char *value);
  38. void set(const SocketType &input, ustring value);
  39. void set(const SocketType &input, const Transform &value);
  40. void set(const SocketType &input, Node *value);
  41. /* set array values. the memory from the input array will taken over
  42. * by the node and the input array will be empty after return */
  43. void set(const SocketType &input, array<bool> &value);
  44. void set(const SocketType &input, array<int> &value);
  45. void set(const SocketType &input, array<float> &value);
  46. void set(const SocketType &input, array<float2> &value);
  47. void set(const SocketType &input, array<float3> &value);
  48. void set(const SocketType &input, array<ustring> &value);
  49. void set(const SocketType &input, array<Transform> &value);
  50. void set(const SocketType &input, array<Node *> &value);
  51. /* get values */
  52. bool get_bool(const SocketType &input) const;
  53. int get_int(const SocketType &input) const;
  54. uint get_uint(const SocketType &input) const;
  55. float get_float(const SocketType &input) const;
  56. float2 get_float2(const SocketType &input) const;
  57. float3 get_float3(const SocketType &input) const;
  58. ustring get_string(const SocketType &input) const;
  59. Transform get_transform(const SocketType &input) const;
  60. Node *get_node(const SocketType &input) const;
  61. /* get array values */
  62. const array<bool> &get_bool_array(const SocketType &input) const;
  63. const array<int> &get_int_array(const SocketType &input) const;
  64. const array<float> &get_float_array(const SocketType &input) const;
  65. const array<float2> &get_float2_array(const SocketType &input) const;
  66. const array<float3> &get_float3_array(const SocketType &input) const;
  67. const array<ustring> &get_string_array(const SocketType &input) const;
  68. const array<Transform> &get_transform_array(const SocketType &input) const;
  69. const array<Node *> &get_node_array(const SocketType &input) const;
  70. /* generic values operations */
  71. bool has_default_value(const SocketType &input) const;
  72. void set_default_value(const SocketType &input);
  73. bool equals_value(const Node &other, const SocketType &input) const;
  74. void copy_value(const SocketType &input, const Node &other, const SocketType &other_input);
  75. /* equals */
  76. bool equals(const Node &other) const;
  77. /* compute hash of node and its socket values */
  78. void hash(MD5Hash &md5);
  79. /* Get total size of this node. */
  80. size_t get_total_size_in_bytes() const;
  81. ustring name;
  82. const NodeType *type;
  83. };
  84. CCL_NAMESPACE_END