HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Graph.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UN_Graph.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Graph_h__
13 #define __UN_Graph_h__
14 
15 #include "UN_API.h"
16 #include "UN_Node.h"
17 #include <UT/UT_StringHolder.h>
18 
19 class UN_GraphData;
20 
21 
22 // ============================================================================
23 /// A light-weight handle/pointer for the graph data.
24 ///
25 /// The actual graph data and logic is implemented in UN_GraphData
26 /// owned by UN_Context.
27 ///
28 /// UN_Graph serves as a handle/pointer for clients to refer to that graph data.
29 
31 {
32 public:
33  /// Default constructor that creates an invalid UN_Graph handle.
34  UN_Graph();
35 
36  /// Constructor that creates a valid UN_Graph handle (if parm is not null).
37  /// Takes a pointer to the graph data owned by the graph owner.
38  UN_Graph( UN_GraphData *graph_data );
39 
40  /// @{ Default destructor, constructors and assignment operators.
41  ~UN_Graph();
42  UN_Graph(const UN_Graph&);
43  UN_Graph(UN_Graph&&);
44  UN_Graph& operator=(const UN_Graph&);
46  /// @}
47 
48  /// @{ Returns true if this is a valid graph; false otherwise.
49  bool isValid() const
50  { return myGraphData; }
51  explicit operator bool() const
52  { return isValid(); }
53  /// @}
54 
55  /// @{ Comparison operators
56  bool operator==( const UN_Graph &other ) const
57  { return myGraphData == other.myGraphData; }
58  bool operator!=( const UN_Graph &other ) const
59  { return !( *this == other ); }
60  /// @}
61 
62  /// Returns the root node of the graph's node parental hierarchy.
63  /// The root is a special node that holds graph's top-level nodes.
64  /// It cannot be deleted or renamed.
65  UN_Node rootNode() const;
66 
67  // TODO: FIXME: consider having UN_GraphConfig object that would
68  // indicate whether to ensureValidNodeNames(), then automatically
69  // call this method to validate name of any created node
70  // This would propagate to UN_Node::createChild() too.
71  // Then adjust calls to findUniqueNodeNames() in testun.
72  /// Returns a name that is not used by any of the top level nodes.
73  UT_StringHolder findUniqueNodeName(
74  const UT_StringRef &name = UT_StringRef()
75  ) const;
76 
77  /// Creates a new top-level node in the graph.
78  UN_Node createNode(
79  const UT_StringRef &name = UT_StringRef(),
80  const UT_StringRef &type = UT_StringRef(),
81  const UT_StringRef &category =UT_StringRef()
82  ) const;
83 
84  /// Returns a top-level node by the given name.
85  /// Note, the return object may be invalid if no such node was found.
86  UN_Node findNode( const UT_StringRef &node_name ) const;
87 
88  /// Removes and deletes the top-level node from this graph.
89  void deleteNode( const UT_StringRef &node_name ) const;
90 
91  /// Returns the names of the graph's top-level nodes.
92  UT_Array< UT_StringHolder > nodeNames() const;
93 
94 
95  /// Iterarates over the top-level nodes of the graph.
98 
99  /// Returns a range for iterating over graph's top-level nodes.
100  NodeRange nodeRange() const;
101 
102 
103  /// Iterarates over all the nodes in the graph; the top-level nodes
104  /// and their descendants too.
107 
108  /// Returns a range for iterating over graph's top-level nodes.
109  AllNodeRange allNodeRange() const;
110 
111 
112  /// An iterator and a range for the top-level wires inside this graph.
115 
116  /// Returns a range for iterating over graph's top-level connection wires.
117  WireRange wireRange() const;
118 
119 
120  /// An iterator and a range for all the connection wires in this graph.
123 
124  /// Returns a range for iterating over graph's top-level connection wires.
125  AllWireRange allWireRange() const;
126 
127 
128  /// Returns the options object representing this graph.
129  /// This can be then used for serialization to JSON, etc.
130  UT_Options asOptions() const;
131 
132  /// Configure the graph based on the given options.
133  void setFromOptions( const UT_Options &graph_opts )const;
134 
135 
136 private:
137  /// Graph data structures, containing details about the graph as a whole,
138  /// such as its nodes and connections between them.
139  UN_GraphData * myGraphData;
140 };
141 
142 #endif
143 
bool operator!=(const UN_Graph &other) const
Comparison operators.
Definition: UN_Graph.h:58
bool operator==(const UN_Graph &other) const
Comparison operators.
Definition: UN_Graph.h:56
#define UN_API
Definition: UN_API.h:11
bool isValid() const
Returns true if this is a valid graph; false otherwise.
Definition: UN_Graph.h:49
UN_DataArrayIterator< UN_Node, UN_NodeIDList > ChildIterator
An iterator and a range for the children of this parent node.
Definition: UN_Node.h:244
GLuint const GLchar * name
Definition: glcorearb.h:786
A map of string to various well defined value types.
Definition: UT_Options.h:84
UN_NodeDescendantIterator DescendantIterator
Definition: UN_Node.h:252
LeafData & operator=(const LeafData &)=delete
UN_NodeWireIterator< false > DescendantWireIterator
Definition: UN_Node.h:275
UN_NodeWireIterator< true > ChildWireIterator
Definition: UN_Node.h:263
type
Definition: core.h:1059