HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_EvalContextFwd.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: CH_EvalContextFwd.h (CH Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __CH_EVALCONTEXTFWD_H_INLUDED__
12 #define __CH_EVALCONTEXTFWD_H_INLUDED__
13 
14 #include "CH_API.h"
16 #include <UT/UT_COW.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <SYS/SYS_Inline.h>
19 #include <SYS/SYS_Types.h>
20 #include <SYS/SYS_Flicks.h>
21 
24 class CH_Channel;
25 class CH_Collection;
26 class CH_Manager;
27 class CH_ScriptAccessManager;
28 class CH_Segment;
29 
30 // Uncomment to switch to store flicks
31 //#define CH_USE_FLICKS
32 
33 /// @file CH_EvalContextFwd.h
34 ///
35 /// Define CH_EvalContext enough to be used as data members.
36 /// Include CH_EvalContext.h which has additional includes to be able to call
37 /// all methods on it.
38 
39 /// Information regarding the current evaluation.
40 ///
41 /// NOTES:
42 /// - All of the pointers may be NULL in general.
43 /// - If channel() is non-NULL, it must belong to the non-NULL collection()
44 /// - If channel() is non-NULL, then channelName() and segment() is non-NULL
45 /// - If segment() is non-NULL <==> collection()/channel() are non-NULL
46 /// - If segment() is non-NULL it must belong to the non-NULL channel()
47 ///
49 {
50 public:
51  class Scope;
52 
53 #if defined(CH_USE_FLICKS)
54  inline SYS_Flicks flicks() const { return myFlicks; }
55  inline fpreal64 time() const
56  { return SYStoSeconds(myFlicks); }
57 #else
58  inline SYS_Flicks flicks() const
59  { return SYStoFlicks(mySeconds); }
60  inline fpreal64 time() const
61  { return mySeconds; }
62 #endif
63  inline const CH_Collection* collection() const
64  { return myCollection; }
66  { return myCollection; }
68  { return myContextOptionsStack; }
70  { return myContextOptions; }
71  inline const CH_Channel* channel() const
72  { return myChannel; }
73  inline CH_Channel* channel()
74  { return myChannel; }
75  inline const CH_Segment* segment() const
76  { return mySegment; }
77  inline CH_Segment* segment()
78  { return mySegment; }
79  inline const char* channelName() const
80  { return myChannelName; }
82  { return myParentContext; }
83 
84 private:
85 #if defined(CH_USE_FLICKS)
86  inline void setFlicks(SYS_Flicks fl) { myFlicks = fl; }
87  inline void setTime(fpreal t) { myFlicks = SYStoFlicks(t); }
88  SYS_Flicks myFlicks;
89 #else
90  inline void setFlicks(SYS_Flicks fl)
91  { mySeconds = SYStoSeconds(fl); }
92  inline void setTime(fpreal t) { mySeconds = t; }
93  fpreal64 mySeconds;
94 #endif
95 
96  CH_Collection *myCollection;
97  const DEP_ContextOptionsStack *myContextOptionsStack;
98  DEP_ContextOptionsReadHandle myContextOptions;
99  CH_Channel *myChannel;
100  CH_Segment *mySegment;
101 
102  // Note that because hscript expression string parms can add
103  // dependencies even though they don't have a channel, we have to store
104  // both the evaluating channel and the evaluating channel name.
105  const char *myChannelName;
106  CH_EvalContext *myParentContext;
107 
108  friend class CH_Manager;
109  friend class CH_EvalContext::Scope;
110  friend class CH_AutoEvaluateTime;
111  friend class CH_AutoEvalCollection;
112 };
113 
114 // Make CH_EvalContext a POD type for UT_ThreadSpecificValue for zero init.
115 template <> constexpr SYS_STATIC_INLINE bool
116 SYSisPOD<CH_EvalContext>() { return true; }
117 
118 /// Object to save the current CH_EvalContext and then restore it when it goes
119 /// out of scope.
121 {
122 public:
123  Scope(int thread);
124  Scope(int thread, bool push_access_manager);
125  ~Scope();
127 
128  inline fpreal time() const
129  { return myContext.time(); }
130  inline const CH_Collection* collection() const
131  { return myContext.myCollection; }
132  inline const CH_Channel* channel() const
133  { return myContext.myChannel; }
134  inline const CH_Segment* segment() const
135  { return myContext.mySegment; }
136  inline const char* channelName() const
137  { return myContext.myChannelName; }
138 
139  inline void
141  {
142  myContext.setTime(t);
143  }
144  inline void
146  {
147  myContext.setFlicks(fl);
148  }
149 
150  inline void
152  {
153  myContext.myCollection = collection;
154  }
155 
156  // Sets myChannel to channel, myChannelName to myChannel->getName(), and
157  // mySegment to seg. (not inline to avoid #including CH_Channel.h)
158  void setChannel(CH_Channel* channel, CH_Segment* seg);
159 
160  // Sets myChannel/mySegment to NULL and myChannelName to channel_name.
161  void setChannelName(const char* channel_name)
162  {
163  myContext.myChannel = NULL;
164  myContext.mySegment = NULL;
165  myContext.myChannelName = channel_name;
166  }
167 
168 
169  inline void
171  {
172  myContext.mySegment = segment;
173  }
174 
175  inline void
177  const DEP_ContextOptionsReadHandle &options,
178  const DEP_ContextOptionsStack *options_stack)
179  {
180  myContext.myContextOptions = options;
181  myContext.myContextOptionsStack = options_stack;
182  }
183 
184  // Common combinations
185  inline void
186  set(fpreal t, CH_Collection* collection, CH_Channel* chp, CH_Segment* seg)
187  {
188  myContext.setTime(t);
189  myContext.myCollection = collection;
190  setChannel(chp, seg);
191  }
192  inline void
193  set(fpreal t, CH_Collection* collection)
194  {
195  myContext.setTime(t);
196  myContext.myCollection = collection;
197  setChannel(NULL, NULL);
198  }
199  inline void
200  set(SYS_Flicks t, CH_Collection* collection, CH_Channel* chp, CH_Segment* seg)
201  {
202  myContext.setFlicks(t);
203  myContext.myCollection = collection;
204  setChannel(chp, seg);
205  }
206  inline void
208  {
209  myContext.setFlicks(t);
210  myContext.myCollection = collection;
211  setChannel(NULL, NULL);
212  }
213  inline void
214  set(CH_Collection* collection, CH_Channel* channel)
215  {
216  myContext.myCollection = collection;
217  setChannel(channel, NULL);
218  }
219  inline void
220  set(CH_Collection* collection, const char* channel_name)
221  {
222  myContext.myCollection = collection;
223  setChannelName(channel_name);
224  }
225 
226 private:
227  CH_EvalContext& myContext;
228  CH_ScriptAccessManager* myAccessMgr;
229  CH_EvalContext myPrevContext;
230 };
231 
232 #endif // __CH_EVALCONTEXTFWD_H_INLUDED__
CH_Collection * collection()
void setChannelName(const char *channel_name)
void set(SYS_Flicks t, CH_Collection *collection, CH_Channel *chp, CH_Segment *seg)
constexpr SYS_Flicks SYStoFlicks(double seconds)
Definition: SYS_Flicks.h:39
CH_Segment * segment()
GT_API const UT_StringHolder time
const CH_Segment * segment() const
void setFlicks(SYS_Flicks fl)
SYS_Flicks flicks() const
constexpr double SYStoSeconds(const SYS_Flicks f)
Definition: SYS_Flicks.h:35
constexpr SYS_STATIC_INLINE bool SYSisPOD< CH_EvalContext >()
fpreal64 time() const
double fpreal64
Definition: SYS_Types.h:201
std::chrono::duration< std::chrono::nanoseconds::rep, std::ratio< 1, 705600000 >> flicks
Definition: flicks.h:85
void setSegment(CH_Segment *segment)
CH_EvalContext * parentContext()
void set(fpreal t, CH_Collection *collection, CH_Channel *chp, CH_Segment *seg)
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
const CH_Collection * collection() const
void set(fpreal t, CH_Collection *collection)
void setTime(fpreal t)
GLdouble t
Definition: glad.h:2397
util::flicks SYS_Flicks
Definition: SYS_Flicks.h:17
void setContextOptions(const DEP_ContextOptionsReadHandle &options, const DEP_ContextOptionsStack *options_stack)
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
Push & restore the evaluation time (and optionally a channel collection)
Definition: CH_Manager.h:1908
CH_Channel * channel()
fpreal64 fpreal
Definition: SYS_Types.h:277
#define CH_API
Definition: CH_API.h:10
void set(CH_Collection *collection, CH_Channel *channel)
const char * channelName() const
const DEP_ContextOptionsStack * contextOptionsStack() const
Scope(int thread)
DEP_ContextOptionsReadHandle contextOptions() const
void setCollection(CH_Collection *collection)
void set(CH_Collection *collection, const char *channel_name)
void set(SYS_Flicks t, CH_Collection *collection)
const CH_Channel * channel() const