HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_NodeVerb.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: OP_NodeVerb.h ( OP Library, C++)
7  *
8  * COMMENTS:
9  * Verb-based API for OP cooking mechanisms. OPs can return
10  * one of these objects to describe how they cook, allowing the
11  * cook engine to perform additional optimizations.
12  *
13  * Because how to actually cook is rather bespoke, this is mostly
14  * a category specific registration class.
15  */
16 
17 #ifndef __OP_NodeVerb_h__
18 #define __OP_NodeVerb_h__
19 
20 #include "OP_API.h"
21 #include "OP_NodeParms.h"
22 #include "OP_OpTypeId.h"
23 #include <UT/UT_StringHolder.h>
24 
25 class UT_StringArray;
26 
27 ///
28 /// OP_NodeVerb
29 ///
30 /// This should be a singleton class. Build it with the Register
31 /// template to allow it to be discoverable by name.
32 ///
34 {
35 public:
37  virtual ~OP_NodeVerb() {}
38 
39  OP_NodeVerb(const OP_NodeVerb &) = delete;
40  OP_NodeVerb &operator=(const OP_NodeVerb &) = delete;
41 
42  template <typename T>
43  class Register
44  {
45  public:
47  {
48  myVerb = new T();
50  }
52  {
54  delete myVerb;
55  }
56 
57  const T *get() const { return myVerb; }
58  const T *operator &() const { return myVerb; }
59  operator const T &() const { return *myVerb; }
60 
61  private:
62  T *myVerb;
63 
64  };
65 
66  /// When working with a specific category one will use allocCache
67  /// and allocParms, which these should chain to in the category baseclass.
68  virtual OP_NodeCache *baseAllocCache() const
69  { return new OP_NodeCache; }
70 
71  virtual OP_NodeParms *baseAllocParms() const = 0;
72 
73  virtual UT_StringHolder name() const = 0;
74  virtual OP_OpTypeId category() const = 0;
75 
76  /// Finds a verb which matches the given name
77  static const OP_NodeVerb *lookupCategoryVerb(OP_OpTypeId cat, const UT_StringRef &name);
78  static void listCategoryVerbs(OP_OpTypeId cat, UT_StringArray &verbnames);
79 
80  // Note: The category is present in the verb so not required.
81  static void registerVerb(OP_NodeVerb *verb);
82  static void unregisterVerb(OP_NodeVerb *verb);
83 
84 protected:
85 };
86 
87 #endif
virtual ~OP_NodeVerb()
Definition: OP_NodeVerb.h:37
static void unregisterVerb(OP_NodeVerb *verb)
virtual OP_NodeCache * baseAllocCache() const
Definition: OP_NodeVerb.h:68
OP_OpTypeId
Definition: OP_OpTypeId.h:18
GLuint const GLchar * name
Definition: glcorearb.h:786
LeafData & operator=(const LeafData &)=delete
#define OP_API
Definition: OP_API.h:10
static void registerVerb(OP_NodeVerb *verb)