HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_NodeCallbackType.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_CALLBACK_TYPE_H__
10 #define __PDG_NODE_CALLBACK_TYPE_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_NodeCallback.h"
15 #include "PDG_NodeInterface.h"
16 #include "PDG_NodeTemplate.h"
17 #include "PDG_Types.h"
18 
19 class PDG_Node;
20 
22  PDG_NodeCallback,
23  PDG_NodeCallbackPtr,
24  PDG_RegistrationType::eNode,
25  PDG_Node*>
26 {
27 public:
30  const UT_StringHolder& type_label,
31  const UT_StringHolder& type_category,
32  bool is_static_generator,
33  PDG_BaseType::Language language,
34  const PDG_NodeInterface& interface,
35  PDG_NodeType node_type,
36  PDG_NodeSubtype sub_type)
37  : PDGT_RegisteredType(type_name, type_label, language, true)
38  , myNodeType(node_type)
39  , myNodeSubtype(sub_type)
40  , myNodeCategory(type_category)
41  , myIsStaticGenerator(is_static_generator)
42  , myCallbackBits(0xFFFFFFFF)
43  {
44  myNodeInterface.cloneFrom(interface);
45  myNodeInterface.addBuiltinPorts(myNodeType, myNodeSubtype);
46 
47  if (type_category.isEmpty())
48  {
49  if (node_type == PDG_NodeType::eProcessor)
50  myNodeCategory = "Processor";
51  else if (node_type == PDG_NodeType::ePartitioner)
52  myNodeCategory = "Partitioner";
53  else if (node_type == PDG_NodeType::eMapper)
54  myNodeCategory = "Mapper";
55  }
56  }
57 
60  const UT_StringHolder& type_label,
61  const UT_StringHolder& type_category,
62  bool is_static_generator,
63  PDG_BaseType::Language language,
64  const UT_StringHolder& template_name,
65  const UT_StringHolder& template_path,
66  const UT_StringHolder& template_body,
67  PDG_NodeType node_type,
68  PDG_NodeSubtype sub_type)
69  : PDGT_RegisteredType(type_name, type_label, language, true)
70  , myNodeType(node_type)
71  , myNodeSubtype(sub_type)
72  , myNodeCategory(type_category)
73  , myIsStaticGenerator(is_static_generator)
74  , myTemplateName(template_name)
75  , myTemplatePath(template_path)
76  , myTemplateBody(template_body)
77  , myCallbackBits(0xFFFFFFFF)
78  {
79  if (type_category.isEmpty())
80  {
81  if (node_type == PDG_NodeType::eProcessor)
82  myNodeCategory = "Processor";
83  else if (node_type == PDG_NodeType::ePartitioner)
84  myNodeCategory = "Partitioner";
85  else if (node_type == PDG_NodeType::eMapper)
86  myNodeCategory = "Mapper";
87  }
88  }
89 
91  { return myNodeInterface; }
92 
94  { return myNodeType; }
96  { return myNodeSubtype; }
97 
99  { return myNodeCategory; }
100 
101  bool isStaticGenerator() const
102  { return myIsStaticGenerator; }
103  void setStaticGenerator(bool static_generator)
104  { myIsStaticGenerator = static_generator; }
105 
106  int callbackBits() const
107  { return myCallbackBits; }
108  void setCallbackBits(int callback_bits)
109  { myCallbackBits = callback_bits; }
110  void addCallbackBits(int callback_bits)
111  { myCallbackBits |= callback_bits; }
112 
113  bool initialize(UT_WorkBuffer& errors) override
114  {
115  if (myNodeInterface.isValid())
116  return true;
117 
118  if (!myTemplateName.isEmpty() ||
119  !myTemplatePath.isEmpty() ||
120  !myTemplateBody.isEmpty())
121  {
123  myNodeInterface,
124  myTemplateName,
125  myTemplatePath,
126  myTemplateBody,
127  errors))
128  {
129  return false;
130  }
131  }
132 
133  myNodeInterface.addBuiltinPorts(
134  myNodeType, myNodeSubtype);
135  return true;
136  }
137 
138 private:
139  PDG_NodeInterface myNodeInterface;
140  PDG_NodeType myNodeType;
141  PDG_NodeSubtype myNodeSubtype;
142  UT_StringHolder myNodeCategory;
143 
144  UT_StringHolder myTemplateName;
145  UT_StringHolder myTemplatePath;
146  UT_StringHolder myTemplateBody;
147 
148  int myCallbackBits;
149  bool myIsStaticGenerator;
150 };
151 
152 #endif
const UT_StringHolder & nodeCategory() const
PDG_NodeSubtype
Enumeration of node subtypes.
Definition: PDG_Types.h:302
PDG_NodeType
Enumeration of node types in a PDG graph.
Definition: PDG_Types.h:279
PDG_NodeCallbackType(const UT_StringHolder &type_name, const UT_StringHolder &type_label, const UT_StringHolder &type_category, bool is_static_generator, PDG_BaseType::Language language, const PDG_NodeInterface &interface, PDG_NodeType node_type, PDG_NodeSubtype sub_type)
#define PDG_API
Definition: PDG_API.h:23
bool isEmpty() const
Same as !isstring()
void setCallbackBits(int callback_bits)
bool initialize(UT_WorkBuffer &errors) override
PDG_NodeType nodeType() const
const PDG_NodeInterface & nodeInterface() const
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
void addCallbackBits(int callback_bits)
static bool parseTemplate(PDG_NodeInterface &interface, const UT_StringHolder &template_name, const UT_StringHolder &template_path, const UT_StringHolder &template_body, UT_WorkBuffer &errors)
void setStaticGenerator(bool static_generator)
PDG_NodeSubtype subtype() const
PDG_NodeCallbackType(const UT_StringHolder &type_name, const UT_StringHolder &type_label, const UT_StringHolder &type_category, bool is_static_generator, PDG_BaseType::Language language, const UT_StringHolder &template_name, const UT_StringHolder &template_path, const UT_StringHolder &template_body, PDG_NodeType node_type, PDG_NodeSubtype sub_type)