Rumba C++ SDK
Node.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include <optional>
18 
19 #include "Impl.h"
20 #include "Plug.h"
21 
22  namespace maquina
23  {
25 
38  {
39  public:
41 
42  Node(const char* type,
43  const char* name,
44  Node* parent = nullptr,
45  bool undo_stack=false
46  );
47 
50  Node* parent = nullptr,
51  bool undo_stack = false
52  ) const;
53 
55 
56  void delete_node(
57  bool undo_stack=false
58  );
59 
61  void rename(
62  const char* new_name,
63  bool undo_stack = false
64  );
65 
67  const char* name() const;
68 
70  std::string full_name() const;
71 
73  std::string full_document_name() const;
74 
76  std::shared_ptr<AttributeDescriptor> description() const;
77 
79  void set_description(const std::string& description, bool undo_stack = false);
80 
82  const char* type_name() const;
83 
85  bool is_deleted() const;
86 
88  bool is_instance( const char* node_type_name ) const;
89 
91 
92  bool is_referenced() const;
93 
95 
96  bool is_mutable() const;
97 
99 
100  bool is_reference_root() const;
101 
103  bool is_reference_loaded() const;
104 
106  bool is_serializable() const;
107 
108  bool is_singleton() const;
109  void set_singleton(bool singleton);
110 
112 
113  bool is_document_node() const;
114 
117  void set_serializable( bool serialize );
118 
120 
121  std::wstring reference_filename() const;
122 
124 
126  void unload_reference();
127 
129 
132  void load_reference();
133 
135 
137  void replace_reference(const std::wstring& new_reference);
138 
140 
143  void flatten_reference();
144 
146 
147  void write(const std::wstring& filename) const;
148 
150 
152  {
153  public:
156  {
157  public:
158  using iterator_category = std::forward_iterator_tag;
159  using value_type = Node;
160  using difference_type = std::ptrdiff_t;
161  using pointer = Node;
162  using reference = Node;
163 
164  reference operator*() const;
165  bool operator==(const Iterator &other) const;
166  bool operator!=(const Iterator &other) const;
167  Iterator& operator++();
168  Iterator(void *iterator);
169  Iterator( const Iterator &other );
170  ~Iterator();
171  private:
172  void *_internal;
173  };
174 
175  Children( void *node )
176  : _node{ node }
177  {}
178  Iterator begin() const;
179  Iterator end() const;
180 
182  size_t size() const;
183  private:
184  void* _node;
185  };
186 
188  Children children() const;
189 
191  bool has_parent() const;
192 
194 
195  Node parent() const;
196 
198 
199  void set_parent(Node& parent, bool undo_stack);
200 
202 
203  std::optional<Node> document() const;
204 
206  bool has_child(const char* child_name) const;
207 
209 
210  Node child(const char* name) const;
211 
213  bool is_child_of(const Node& parent) const;
214 
216 
217  Node find_first(const char* name) const;
218 
220 
222  {
223  public:
226  {
227  public:
228  using iterator_category = std::forward_iterator_tag;
229  using value_type = Plug;
230  using difference_type = std::ptrdiff_t;
231  using pointer = Plug;
232  using reference = Plug;
233 
234  reference operator*() const;
235  bool operator==(const Iterator &other) const;
236  bool operator!=(const Iterator &other) const;
237  Iterator& operator++();
238  Iterator( const std::shared_ptr< Impl > &node, void *iterator );
239  Iterator( const Iterator &other );
240  ~Iterator();
241  private:
242  std::shared_ptr< Impl > _node;
243  void *_internal;
244  };
245 
246  Plugs( void *node )
247  : _node{ node }
248  {}
249  Iterator begin();
250  Iterator end();
251  private:
252  void* _node;
253  };
254 
256  Plugs plugs() const;
257 
259  bool has_plug(const char* plug_name) const;
260 
262 
270  Plug add_plug( const char* name, const Value& default_value, int flags = Flags::serial, bool undo_stack = false, const std::string & description = "" );
271 
278  void rename_plug( const Plug& plug, const char* new_name, bool undo_stack = false );
279 
288  void remove_plug( const char* name, bool undo_stack = false );
289 
298  void remove_plug( const Plug& plug, bool undo_stack = false );
299 
301 
313  Plug plug(const char* plug_name) const;
314 
315  [[deprecated]]
316  std::vector<Plug> channel_plugs() const;
317 
319  std::vector<Channel> channels() const;
320 
322  std::shared_ptr<Channel> channel(ChannelType channel_type) const;
323 
325 
327  std::vector<Node> relationship();
328 
330  const std::vector<std::string>& bases() const;
331 
333  Node random_child();
334 
336  std::shared_ptr<NodePlugin> plugin() const;
337 
339 
340  std::vector<Node> search(
341  const std::string& key
342  ) const;
343 
345 
346  std::shared_ptr<class NodeDelegate> node_delegate();
347 
349 
352  void notify_first_init(bool undo_stack);
353 
355 
358  void set_graph_properties(const class GraphProperties& gp);
359 
361  bool is_selected() const;
362 
364  std::optional<Plug> channel_switch_sub_channel(const std::string_view& sub_channel) const;
365 
366  bool operator==(const Node& o) const { return _impl == o._impl; }
367  bool operator!=(const Node& o) const { return _impl != o._impl; }
368 
370  std::shared_ptr<Impl> _impl;
371 
373  Node(const std::shared_ptr<Impl>& impl)
374  : _impl{ impl }
375  {}
376  };
377 
379  // This is can't be done in Plug:: because of a cyclic class definition issue
380  MAQUINA_EXPORT Node plug_node(const Plug& plug);
381  }
std::forward_iterator_tag iterator_category
Definition: Node.h:158
bool operator==(const Node &o) const
Definition: Node.h:366
The graph properties of a node, its graph position, its radius, its graph flags.
Definition: GraphProperties.h:23
ChannelType
Predefined channel types.
Definition: ChannelType.h:23
Buffer< T > duplicate(const BufferConst< T > &a)
Definition: Buffer.h:169
bool operator!=(const Node &o) const
Definition: Node.h:367
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
std::forward_iterator_tag iterator_category
Definition: Node.h:228
MAQUINA_EXPORT Value default_value(const maquina::StringView &type_name)
Return the default value of a type.
A Plug accessor.
Definition: Node.h:221
Definition: Plug.h:62
Plugs(void *node)
Definition: Node.h:246
#define MAQUINA_EXPORT
Definition: Export.h:31
A node plug.
Definition: Plug.h:59
std::ptrdiff_t difference_type
Definition: Node.h:160
A Node children iterator.
Definition: Node.h:155
MAQUINA_EXPORT Node plug_node(const Plug &plug)
Get a plug node.
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:306
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:274
std::ptrdiff_t difference_type
Definition: Node.h:230
A Plug iterator.
Definition: Node.h:225
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
A Node children accessor.
Definition: Node.h:151
MAQUINA_EXPORT std::optional< Node > document(const std::string &path, bool comparable=false)
Return the document node associated to that file path.
Children(void *node)
Definition: Node.h:175
Base class of all Rumba nodes.
Definition: Node.h:37
Base class of all Rumba values.
Definition: Value.h:34