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