HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_WireData.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_WireData.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_WireData_h__
13 #define __UN_WireData_h__
14 
15 #include "UN_API.h"
16 #include "UN_Data.h"
17 class UN_GraphData;
18 
19 
20 // ============================================================================
23 
24 // ============================================================================
25 /// Container of data for all the wires in the graph.
26 ///
27 /// NOTE: This class is generally not trivially relocatable, because
28 /// its base class (UN_Data) is not trivially relocatable (see comment there).
29 
30 class UN_API UN_WireData : public UN_Data
31 {
32 public:
33  /// Constructors and destructors.
35  ~UN_WireData() = default;
36 
39 
40 protected:
41  /// This container can have large data, so generally, forbid
42  /// the costly copy operations to the public.
43  /// Knowledgable friends and derived classes can still use them.
44  friend UN_GraphData;
45  UN_WireData(const UN_WireData &) = default;
46  UN_WireData & operator=(const UN_WireData &) = default;
47 
48 public:
49  /// Increases the capacity of the data buffer arrays to the given minimum,
50  /// unless the capacity is already greater or equal to that minimum,
51  /// in which case the capacity remains unchanged.
52  void setCapacityIfNeeded( UN_DataSize min_capacity );
53 
54  /// @{ Returns wire's custom data container, if one was provided to c-tor.
56  {
58  }
59 
61  {
62  return UTverify_cast<const UN_CustomWireData*>( customData() );
63  }
64  /// @}
65 
66  /// Merges another wire data container into this one.
67  /// Returns a mapping between the wire IDs in the merge source
68  /// and destination (this) data buffers.
69  UN_WireIDRemap merge( const UN_WireData &src_wire_data );
70 
71  /// Adds a slot for a new wire in this container.
72  /// Returns an ID that should be used to refer to this new wire
73  /// for accessing its data (eg, source port, destination port, etc).
74  UN_WireID addWire();
75 
76  /// Clears the data for the given wire to the default state.
77  void clearWire(UN_WireID wire_id );
78 
79  /// Removes the wire from this container and frees the
80  /// data slot it occupied. After calling this method,
81  /// the container will have no knowledge of the wire by this ID.
82  /// Returns true on successs; false if the wire was not found.
83  bool removeWire( UN_WireID wire_id );
84 
85  /// Frees the data slots occupied by all the wires.
86  /// @param 'reset_next_id' If true, the wire ID generator is reset to zero.
87  void removeAllWires( bool reset_next_id );
88 
89  /// Returns true if the given ID refers to a valid wire entry
90  /// in the data buffers. Ie, such a wire exists and is valid.
91  bool isValid( UN_WireID wire_id ) const
92  { return UN_Data::isValid( wire_id ); }
93 
94 
95  /// Iterator for traversing valid wire IDs.
97  {
98  public:
99  using value_type = UN_WireID;
100 
102  : UN_DataIndexMap::IDIterator( id_iterator )
103  {}
104 
106  { return UN_WireID( UN_DataIndexMap::IDIterator::operator*() ); }
107  };
108 
109  /// Iterator for traversing valid wire IDs in an ascending order.
111  {
112  public:
113  using value_type = UN_WireID;
114 
116  : UN_DataIndexMap::OrderedIDIterator( id_iterator )
117  {}
118 
120  { return UN_WireID( UN_DataIndexMap::OrderedIDIterator::operator*() ); }
121  };
122 
123 
124  /// Returns a range for iterating valid wire IDs.
126  IDRange idRange() const
127  {
128  auto id_range( UN_Data::idRange() );
129  return IDRange( id_range.begin(), id_range.end() );
130  }
131 
132  /// Returns a range for iterating valid wire IDs.
135  {
136  auto id_range( UN_Data::orderedIDRange() );
137  return OrderedIDRange( id_range.begin(), id_range.end() );
138  }
139 
140  /// Returns a list of all the valid wire IDs in the graph.
141  UN_WireIDList wireIDs() const
142  {
143  SYS_STATIC_ASSERT( sizeof(UN_WireID) == sizeof(UN_DataID) );
144  return reinterpret_cast<UN_WireIDList&&>( std::move( dataIDs() ));
145  }
146 
147  /// Returns a list of all the valid wire IDs in the graph.
148  UN_WireIDList sortedWireIDs() const
149  {
150  SYS_STATIC_ASSERT( sizeof(UN_WireID) == sizeof(UN_DataID) );
151  return reinterpret_cast<UN_WireIDList&&>( std::move(sortedDataIDs() ));
152  }
153 
154 
155 
156  /// Sets the data value in a generic buffer for a given wire.
157  template<typename T>
158  void setGenericData( UN_GenericBufferID buf_id, UN_WireID wire_id,
159  const T &value )
160  { UN_Data::setGenericData( buf_id, wire_id, value ); }
161 
162  /// Sets the data value in a generic buffer via move.
163  template<typename T>
164  void setGenericData( UN_GenericBufferID buf_id, UN_WireID wire_id,
165  T &&value )
166  { UN_Data::setGenericData( buf_id, wire_id, std::forward<T>(value) ); }
167 
168  /// Returns a const ref to the data value in a generic buffer.
169  template<typename T>
171  UN_WireID wire_id ) const
172  { return UN_Data::genericDataRef<T>( buf_id, wire_id ); }
173 
174  /// Returns a copy of a data value from a generic buffer.
175  template<typename T>
176  T genericDataVal( UN_GenericBufferID buf_id, UN_WireID wire_id ) const
177  { return UN_Data::genericDataVal<T>( buf_id, wire_id ); }
178 
179 
180  /// Moves the data value out of a generic buffer.
181  template<typename T>
182  T stealGenericData( UN_GenericBufferID buf_id, UN_WireID wire_id )
183  { return UN_Data::stealGenericData<T>( buf_id, wire_id ); }
184 
185  /// Updates the data value in a generic buffer in-place via a callable.
186  template<typename T, typename OP>
187  void updateGenericData( UN_GenericBufferID buf_id, UN_WireID wire_id,
188  const OP &op )
189  { UN_Data::updateGenericData<T>( buf_id, wire_id, op ); }
190 
191 
192 protected:
193  /// Returns the wire's data index into the data buffer arrays.
194  UN_WireIndex wireIndex( UN_WireID id ) const
195  {
196  return UN_WireIndex(
197  UN_Data::dataIndex( id ));
198  }
199 
200 private:
201  /// Returns the current size of the internals data buffers.
202  /// The number of valid entries (slots) in data buffers is less than
203  /// or equal to that number, since some data slots may be free.
204  UN_DataSize coreDataBufferSize() const
205  {
206  UT_ASSERT( isCoreDataSizeConsistent() );
207  return dataBufferSize();
208  }
209 
210 
211  /// Handles merging of another wire data container into this one.
212  void mergeCoreData( const UN_WireData &src,
213  const UN_DataMergeInfo &merge_info );
214 
215  /// Adds a new data slot to accommodate a new data piece at the given index.
216  void addCoreData( UN_WireIndex wire_index );
217 
218  /// Clears the data for the given wire to the default state.
219  void clearCoreData( UN_WireIndex wire_index );
220 
221  /// Frees the data slot occupied by the given wire,
222  /// clearing it if necessary.
223  void removeCoreData() //, index)
224  // Nothing urgent to free; will clear lazily
225  { UT_ASSERT( isDataSizeConsistent() ); }
226 
227  /// Frees all the data slots.
228  void removeAllCoreData();
229 
230  /// Sets the capacity of core data buffers if needed.
231  void setCoreDataCapacityIfNeeded(
232  UN_DataSize min_capacity );
233 
234  /// Returns true if the sizes of all core data buffers are equal.
235  bool isCoreDataSizeConsistent() const;
236 
237  /// Returns true if the sizes of data buffers and index map are equal.
238  bool isDataSizeConsistent() const;
239 
240 private:
241 };
242 
243 
244 #endif
IDRange idRange() const
Definition: UN_Data.h:55
#define SYS_STATIC_ASSERT(expr)
void setGenericData(UN_GenericBufferID buf_id, UN_WireID wire_id, const T &value)
Sets the data value in a generic buffer for a given wire.
Definition: UN_WireData.h:158
void setGenericData(UN_GenericBufferID buf_id, UN_WireID wire_id, T &&value)
Sets the data value in a generic buffer via move.
Definition: UN_WireData.h:164
const T & genericDataRef(UN_GenericBufferID buf_id, UN_WireID wire_id) const
Returns a const ref to the data value in a generic buffer.
Definition: UN_WireData.h:170
GLsizei const GLfloat * value
Definition: glcorearb.h:824
Iterator for traversing valid wire IDs in an ascending order.
Definition: UN_WireData.h:110
bool isValid(UN_DataID data_id) const
Definition: UN_Data.h:140
friend UN_GraphData
Definition: UN_WireData.h:44
T stealGenericData(UN_GenericBufferID buf_id, UN_WireID wire_id)
Moves the data value out of a generic buffer.
Definition: UN_WireData.h:182
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:242
Iterator for traversing valid data IDs in the map.
#define UN_API
Definition: UN_API.h:11
UN_Data & operator=(UN_Data &&)
Iterator for traversing valid wire IDs.
Definition: UN_WireData.h:96
IDIterator(const UN_DataIndexMap::IDIterator &id_iterator)
Definition: UN_WireData.h:101
UN_WireIDList sortedWireIDs() const
Returns a list of all the valid wire IDs in the graph.
Definition: UN_WireData.h:148
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
OrderedIDRange orderedIDRange() const
Definition: UN_WireData.h:134
UN_DataIndex dataIndex(UN_DataID id) const
Definition: UN_Data.h:147
UN_DataSize dataBufferSize() const
Definition: UN_Data.h:154
void updateGenericData(UN_GenericBufferID buf_id, UN_WireID wire_id, const OP &op)
Updates the data value in a generic buffer in-place via a callable.
Definition: UN_WireData.h:187
UN_CustomData * customData()
Returns the custom data container, if one was provided.
Definition: UN_Data.h:47
void setGenericData(UN_GenericBufferID buf_id, UN_DataID id, const T &value)
Sets the data value in a generic buffer for a given data ID.
Definition: UN_Data.h:275
UN_CustomWireData * customWireData()
Returns wire's custom data container, if one was provided to c-tor.
Definition: UN_WireData.h:55
value_type operator*() const
Definition: UN_WireData.h:105
const UN_CustomWireData * customWireData() const
Returns wire's custom data container, if one was provided to c-tor.
Definition: UN_WireData.h:60
UT_UniquePtr< UN_CustomWireData > UN_CustomWireDataPtr
Definition: UN_WireData.h:22
UN_DataIDList dataIDs() const
Returns a list of all the valid IDs in this container.
Definition: UN_Data.h:64
UN_DataIndexMap::IDRange IDRange
Returns a range for iterating valid IDs.
Definition: UN_Data.h:54
bool isValid(UN_WireID wire_id) const
Definition: UN_WireData.h:91
Maintains a mapping from data ID to data index in the data buffer.
Iterator for traversing valid data IDs in the map in an ordered fashion.
IDRange idRange() const
Definition: UN_WireData.h:126
OrderedIDIterator(const UN_DataIndexMap::OrderedIDIterator &id_iterator)
Definition: UN_WireData.h:115
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
T genericDataVal(UN_GenericBufferID buf_id, UN_WireID wire_id) const
Returns a copy of a data value from a generic buffer.
Definition: UN_WireData.h:176
OutGridT XformOp bool bool MergePolicy merge
UN_DataIDList sortedDataIDs() const
Returns a sorted list of all the valid IDs in this container.
Definition: UN_Data.h:68
UN_DataIndexMap::OrderedIDRange OrderedIDRange
Returns a range for iterating valid IDs in an ascending order.
Definition: UN_Data.h:59
value_type operator*() const
Definition: UN_WireData.h:119
Definition: UNI_ID.h:25
UN_WireIDList wireIDs() const
Returns a list of all the valid wire IDs in the graph.
Definition: UN_WireData.h:141
OrderedIDRange orderedIDRange() const
Definition: UN_Data.h:60
UN_WireIndex wireIndex(UN_WireID id) const
Returns the wire's data index into the data buffer arrays.
Definition: UN_WireData.h:194
GLenum src
Definition: glcorearb.h:1793