HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_NodePorts.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_NODE_PORTS_H__
10 #define __PDG_NODE_PORTS_H__
11 
12 #include "PDG_API.h"
13 #include "PDG_Port.h"
14 #include "PDG_Types.h"
15 
16 #include <UT/UT_ArrayStringMap.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_UniquePtr.h>
19 
20 /*
21  * Helper class that contains a table of PDG_Ports for a node.
22  */
24 {
25 public:
26  /// Returns the total memory usage of this instance
27  int64 getMemoryUsage(bool inclusive) const;
28 
29  /// Sorts the ports stored in this instance by there isOrdered flag, for
30  /// the specified type.
31  void sort(PDG_PortType port_type);
32 
33 
34  /// Returns the total number of ports of the specified type
35  int count(PDG_PortType port_type) const
36  { return myPortArrays[(int)port_type].size(); }
37 
38  /// Returns the array of ports for the specified type
39  const PDG_PortArray& ports(PDG_PortType port_type) const
40  { return myPortArrays[(int)port_type]; }
41 
42 
43  /// Returns the first port that matches the specified name, regardless of
44  /// port type. Returns nullptr if no port is found.
45  PDG_Port* port(const UT_StringHolder& name) const;
46 
47  /// Returns the port at the specified index and type, or nullptr if no
48  /// port is found at that index
49  PDG_Port* port(PDG_PortType port_type, int index) const;
50 
51  /// Returns the port with the specified name and type, or nullptr if no
52  /// port exists with that name
53  PDG_Port* port(
54  PDG_PortType port_type,
55  const UT_StringHolder& name) const;
56 
57  /// Adds a new port to the table
58  template <typename... Args>
59  PDG_Port* add(Args&&... args)
60  {
61  PortPtr port_ptr = UTmakeUnique<PDG_Port>(
62  std::forward<Args>(args)...);
63 
64  PDG_PortType type = port_ptr->portType();
65  const UT_StringHolder& name =
66  port_ptr->name();
67  PDG_Port* port = port_ptr.get();
68 
69  myPortArrays[(int)type].append(port);
70  myPortMaps[(int)type][name] =
71  std::move(port_ptr);
72 
73  return port;
74  }
75 
76  /// Removes a port with the specified name and type
77  bool remove(
78  PDG_PortType port_type,
79  const UT_StringHolder& name);
80 
81  /// Clears all ports of the specified type
82  void clear(PDG_PortType port_type);
83 
84 private:
85  using PortPtr = UT_UniquePtr<PDG_Port>;
86  using PortMap = UT_ArrayStringMap<PortPtr>;
87 
88 private:
89  PDG_PortArray myPortArrays[(int)PDG_PortType::eCount];
90  PortMap myPortMaps[(int)PDG_PortType::eCount];
91 };
92 
93 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
#define PDG_API
Definition: PDG_API.h:23
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
PDG_Port * add(Args &&...args)
Adds a new port to the table.
Definition: PDG_NodePorts.h:59
PDG_PortType
Enumeration of node port types.
Definition: PDG_Types.h:347
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLsizeiptr size
Definition: glcorearb.h:664
Port type guard/count.
GLuint index
Definition: glcorearb.h:786
const PDG_PortArray & ports(PDG_PortType port_type) const
Returns the array of ports for the specified type.
Definition: PDG_NodePorts.h:39
**If you just want to fire and args
Definition: thread.h:609
type
Definition: core.h:1059
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334
int count(PDG_PortType port_type) const
Returns the total number of ports of the specified type.
Definition: PDG_NodePorts.h:35