HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OP_SpareParms.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_SpareParms.h ( OP Library, C++)
7  *
8  * COMMENTS: Cache of spare parameter dialog scripts. Each cache entry has:
9  * - The PRM_ScriptPage
10  * - The PRM_ScriptImports
11  * - The PRM_Template list
12  *
13  * This class is kept in a per-operator cache, allowing multiple nodes to
14  * share templates etc. if they have the same spare parameters.
15  */
16 
17 #ifndef __OP_SpareParms__
18 #define __OP_SpareParms__
19 
20 #include "OP_API.h"
21 #include <SYS/SYS_Types.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_StringMap.h>
24 #include <UT/UT_Array.h>
25 #include <PRM/PRM_Default.h>
26 
27 class UT_IStream;
28 class OP_SpareParmCache;
29 class OP_Operator;
30 class PRM_ScriptPage;
31 class PRM_ScriptImports;
32 class PRM_Template;
33 
35 {
36 public:
38  UT_IStream &is,
39  OP_Operator *op,
40  const char *key);
41 
42  bool isValid() const { return myPage != 0; }
43  int bumpRef(int dir);
44  PRM_ScriptPage *getScriptPage() { return myPage; }
45  PRM_Template *getSpareTemplates() { return mySpareTemplates; }
47  PRM_Template *getLayoutTemplates() { return myLayoutTemplates; }
48  PRM_ScriptImports *getLayoutImports() { return myLayoutImports; }
49  const char *getKey() { return myKey; }
50 
51  // The Id for this class is a unique integer value >= 0 that allows us
52  // to safely and uniquely identify an instance of this class without
53  // worrying about pointer reuse.
54  int getId() const { return myId; }
55 
56  // We track the number of expression inputs present to avoid expensive
57  // searches in the usual case of nodes lacking any.
58  int numSpareInputs() const { return myNumSpareInputs; }
59 
60 private:
61  // These should only be deleted through bumpRef calls.
62  ~OP_SpareParms();
63 
64  // Turn our parsed script into spare and layout template arrays. We use
65  // the operator to supply the base parameter information.
66  void createTemplates(OP_Operator *op);
67  // Use the base templates to fix up the layout templates, and possibly
68  // fill in a spare templates array. Works for top level or multiparm
69  // templates. Returns true if the layout templates and base templates
70  // are exactly the same.
71  bool createTemplates(PRM_Template *basetplate,
72  PRM_Template *laytplate,
73  PRM_Template *sparetplate,
74  bool doingmultiparm);
75  // Clears the key value, for when we stash this spare parms.
76  void clearKey();
77 
78  OP_SpareParmCache *myCache;
79  PRM_ScriptPage *myPage;
80  PRM_ScriptImports *myLayoutImports;
81  PRM_Template *mySpareTemplates;
82  PRM_Template *myLayoutTemplates;
83  PRM_Default myStandardFolderDefaults[2];
84  PRM_Default myEmptyFolderDefaults[2];
85  UT_String myKey;
86  int myRefCount;
87  int myId;
88  int myNumSpareInputs;
89 
90  friend class OP_SpareParmCache;
91 };
92 
94 {
95 public:
97 
98  OP_SpareParms *createSpareParms(UT_IStream &is, OP_Operator *op);
99 
100  // Called only by bumpRef()
101  void removeSpareParms(OP_SpareParms *parms);
102 
103  // Increment or decrement the ref count on this cache.
104  int bumpRef(int dir);
105 
106  // Move all our spare parms from myCache into myStash.
107  void stashSpareParms();
108 
109  // Recreate the parm templates for all OP_SpareParms in this cache.
110  void recreateStashedSpareParms(OP_Operator *op);
111 
112 private:
113  // These should only be deleted through bumpRef calls.
115 
118  int myRefCount;
119 };
120 
121 #endif
122 
int getId() const
Definition: OP_SpareParms.h:54
PRM_Template * getSpareTemplates()
Definition: OP_SpareParms.h:45
int numSpareInputs() const
Definition: OP_SpareParms.h:58
PRM_ScriptImports * getSpareImports()
Definition: OP_SpareParms.h:46
PRM_ScriptPage * getScriptPage()
Definition: OP_SpareParms.h:44
#define OP_API
Definition: OP_API.h:10
PRM_ScriptImports * getLayoutImports()
Definition: OP_SpareParms.h:48
bool isValid() const
Definition: OP_SpareParms.h:42
const char * getKey()
Definition: OP_SpareParms.h:49
PRM_Template * getLayoutTemplates()
Definition: OP_SpareParms.h:47