HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_ParmData.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_ParmData.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_ParmData_h__
13 #define __UN_ParmData_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 parameters 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_ParmData : public UN_Data
31 {
32 public:
33  /// Constructors and destructors.
35  ~UN_ParmData() = 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_ParmData(const UN_ParmData &) = default;
46  UN_ParmData & operator=(const UN_ParmData &) = 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 parm's custom data container, if one was provided.
56  {
58  }
59 
61  {
62  return UTverify_cast<const UN_CustomParmData*>( customData() );
63  }
64  /// @}
65 
66  /// Merges another parameter data container into this one.
67  /// Returns a mapping between the data IDs in the merge source
68  /// and destination (this) data buffers.
69  UN_ParmIDRemap merge( const UN_ParmData &src_parm_data );
70 
71  /// @{ Sets and configures the parameter based on the given options.
72  void merge( UN_ParmID parm_id,
73  const UT_OptionEntry &parm_entry );
74  void merge( UN_ParmID parm_id,
75  const UN_Options &parm_opts );
76  /// @}
77 
78  /// Returns the options object representing this parameter data,
79  /// such as name, type and value.
80  /// This can be then used for serialization to JSON, etc.
81  /// @param include_name If true, the result will contain the entry for
82  /// the node name; otherwise, the name will be skipped.
83  UN_OptionsPtr asOptionsClassic( UN_ParmID parm_id,
84  bool include_name = true ) const;
85 
86 
87 
88  /// Adds a slot for a new parameter in this container.
89  /// Returns an ID that should be used to refer to this new parameter
90  /// for accessing its data (eg, name, value, etc).
91  UN_ParmID addParm();
92 
93  /// Clears the data for the given parameter to the default state.
94  void clearParm( UN_ParmID parm_id );
95 
96  /// Removes the parameter from this container and frees the
97  /// data slot it occupied. After calling this method the container will
98  /// have no knowledge of the parameter by this ID.
99  /// Returns true on successs; false if the parameter was not found.
100  bool removeParm( UN_ParmID parm_id );
101 
102  /// Frees the data slots occupied by all the parameters.
103  /// @param 'reset_next_id' If true, the node ID generator is reset to zero.
104  void removeAllParms( bool reset_next_id );
105 
106  /// Returns true if the given ID refers to a valid parm entry
107  /// in the data buffers. Ie, such a parm exists and is valid.
108  bool isValid( UN_ParmID parm_id ) const
109  { return UN_Data::isValid( parm_id ); }
110 
111 
112  /// Iterator for traversing valid parm IDs.
114  {
115  public:
116  using value_type = UN_ParmID;
117 
119  : UN_DataIndexMap::IDIterator( id_iterator )
120  {}
121 
123  { return UN_ParmID( UN_DataIndexMap::IDIterator::operator*() ); }
124  };
125 
126  /// Iterator for traversing valid parm IDs in an ascending order.
128  {
129  public:
130  using value_type = UN_ParmID;
131 
133  : UN_DataIndexMap::OrderedIDIterator( id_iterator )
134  {}
135 
137  { return UN_ParmID( UN_DataIndexMap::OrderedIDIterator::operator*() ); }
138  };
139 
140 
141  /// Returns a range for iterating valid parm IDs.
143  IDRange idRange() const
144  {
145  auto id_range( UN_Data::idRange() );
146  return IDRange( id_range.begin(), id_range.end() );
147  }
148 
149  /// Returns a range for iterating valid parm IDs.
152  {
153  auto id_range( UN_Data::orderedIDRange() );
154  return OrderedIDRange( id_range.begin(), id_range.end() );
155  }
156 
157  /// Returns a list of all the valid parm IDs in the graph.
158  UN_ParmIDList parmIDs() const
159  {
160  SYS_STATIC_ASSERT( sizeof(UN_ParmID) == sizeof(UN_DataID) );
161  return reinterpret_cast<UN_ParmIDList&&>( std::move( dataIDs() ));
162  }
163 
164  /// Returns a list of all the valid parm IDs in the graph.
165  UN_ParmIDList sortedParmIDs() const
166  {
167  SYS_STATIC_ASSERT( sizeof(UN_ParmID) == sizeof(UN_DataID) );
168  return reinterpret_cast<UN_ParmIDList&&>( std::move(sortedDataIDs() ));
169  }
170 
171 
172 public:
173  /// @{ The name of the parameter.
174  void setName( UN_ParmID parm_id,
175  const UT_StringRef &name );
176  const UT_StringHolder & name( UN_ParmID parm_id ) const;
177  /// @}
178 
179  /// @{ The name of the parameter.
180  void setTypeName( UN_ParmID parm_id,
181  const UT_StringRef &type_name );
182  const UT_StringHolder & typeName( UN_ParmID parm_id ) const;
183  /// @}
184 
185  /// @{ The parameter value.
186  void setValue( UN_ParmID parm_id,
187  const UT_OptionEntry &opt );
188  void setValue( UN_ParmID parm_id,
189  UT_OptionEntryPtr &&opt );
190  const UT_OptionEntryPtr & value( UN_ParmID parm_id ) const;
191  /// @}
192 
193 
194 protected:
195  /// Returns the parm's data index into the data buffer arrays.
196  UN_ParmIndex parmIndex( UN_ParmID id ) const
197  {
198  return UN_ParmIndex(
199  UN_Data::dataIndex( id ));
200  }
201 
202 private:
203  /// Returns the current size of the internals data buffers.
204  /// The number of valid entries (slots) in data buffers is less than
205  /// or equal to that number, since some data slots may be free.
206  UN_DataSize coreDataBufferSize() const
207  {
208  UN_DataSize size( myName.size() );
209  UT_ASSERT( isCoreDataSizeConsistent(
210  size ));
211  return size;
212  }
213 
214  /// Handles merging of another node data container into this one.
215  void mergeCoreData( const UN_ParmData &src,
216  const UN_DataMergeInfo &merge_info );
217 
218  /// Adds a new data slot to accommodate a new data piece at the given index.
219  void addCoreData( UN_ParmIndex parm_index );
220 
221  /// Clears the data for the given parm to the default state.
222  void clearCoreData( UN_ParmIndex parm_index );
223 
224  /// Frees the data slot occupied by the given parm,
225  /// clearing it if necessary.
226  void removeCoreData() //, index)
227  // Nothing urgent to free; will clear lazily
228  { UT_ASSERT( isDataSizeConsistent() ); }
229 
230  /// Frees all the data slots.
231  void removeAllCoreData();
232 
233  /// Sets the capacity of core data buffers if needed.
234  void setCoreDataCapacityIfNeeded(
235  UN_DataSize min_capacity );
236 
237  /// @{ Returns true if the sizes of all core data buffers are equal.
238  bool isCoreDataSizeConsistent(
239  UN_DataSize expected_size ) const;
240  bool isCoreDataSizeConsistent() const
241  { return isCoreDataSizeConsistent(
242  myName.size() ); }
243  /// @}
244 
245  /// Returns true if the sizes of data buffers and index map are equal.
246  bool isDataSizeConsistent() const;
247 
248 private:
249  /// The name of the prameter.
250  UN_StringDataBuffer myName;
251 
252  /// The type of the parameter
253  UN_StringDataBuffer myTypeName;
254 
255  /// The value of the parameter
256  UN_ValueDataBuffer myValue;
257 };
258 
259 
260 #endif
IDRange idRange() const
Definition: UN_Data.h:55
Iterator for traversing valid parm IDs in an ascending order.
Definition: UN_ParmData.h:127
Iterator for traversing valid parm IDs.
Definition: UN_ParmData.h:113
#define SYS_STATIC_ASSERT(expr)
bool isValid(UN_ParmID parm_id) const
Definition: UN_ParmData.h:108
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UN_ParmIndex parmIndex(UN_ParmID id) const
Returns the parm's data index into the data buffer arrays.
Definition: UN_ParmData.h:196
bool isValid(UN_DataID data_id) const
Definition: UN_Data.h:140
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:242
UN_ParmIDList parmIDs() const
Returns a list of all the valid parm IDs in the graph.
Definition: UN_ParmData.h:158
Iterator for traversing valid data IDs in the map.
#define UN_API
Definition: UN_API.h:11
UN_Data & operator=(UN_Data &&)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UN_DataIndex dataIndex(UN_DataID id) const
Definition: UN_Data.h:147
OrderedIDIterator(const UN_DataIndexMap::OrderedIDIterator &id_iterator)
Definition: UN_ParmData.h:132
UT_UniquePtr< UN_CustomParmData > UN_CustomParmDataPtr
Definition: UN_ParmData.h:22
UN_CustomData * customData()
Returns the custom data container, if one was provided.
Definition: UN_Data.h:47
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: CLI11.h:1729
UN_DataIDList dataIDs() const
Returns a list of all the valid IDs in this container.
Definition: UN_Data.h:64
const UN_CustomParmData * customParmData() const
Returns parm's custom data container, if one was provided.
Definition: UN_ParmData.h:60
GLuint const GLchar * name
Definition: glcorearb.h:786
IDIterator(const UN_DataIndexMap::IDIterator &id_iterator)
Definition: UN_ParmData.h:118
UN_DataIndexMap::IDRange IDRange
Returns a range for iterating valid IDs.
Definition: UN_Data.h:54
UN_CustomParmData * customParmData()
Returns parm's custom data container, if one was provided.
Definition: UN_ParmData.h:55
Maintains a mapping from data ID to data index in the data buffer.
UN_ParmIDList sortedParmIDs() const
Returns a list of all the valid parm IDs in the graph.
Definition: UN_ParmData.h:165
GLsizeiptr size
Definition: glcorearb.h:664
A map of string to various well defined value types.
Definition: UT_Options.h:87
Iterator for traversing valid data IDs in the map in an ordered fashion.
IDRange idRange() const
Definition: UN_ParmData.h:143
value_type operator*() const
Definition: UN_ParmData.h:122
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
OutGridT XformOp bool bool MergePolicy merge
UN_DataSize size() const
Returns the number of valid data items in the buffer.
Definition: UN_Data.h:72
UN_DataIDList sortedDataIDs() const
Returns a sorted list of all the valid IDs in this container.
Definition: UN_Data.h:68
friend UN_GraphData
Definition: UN_ParmData.h:44
UN_DataIndexMap::OrderedIDRange OrderedIDRange
Returns a range for iterating valid IDs in an ascending order.
Definition: UN_Data.h:59
OrderedIDRange orderedIDRange() const
Definition: UN_ParmData.h:151
Definition: UNI_ID.h:25
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
OrderedIDRange orderedIDRange() const
Definition: UN_Data.h:60
UT_UniquePtr< UN_Options > UN_OptionsPtr
Definition: UN_Include.h:640
value_type operator*() const
Definition: UN_ParmData.h:136
GLenum src
Definition: glcorearb.h:1793