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.
120 class CH_API CH_EvalContext::Scope : UT_NonCopyable
121 {
122 public:
123  Scope(int thread);
124  Scope(int thread, bool push_access_manager);
125  ~Scope();
126 
127  inline fpreal time() const
128  { return myContext.time(); }
129  inline const CH_Collection* collection() const
130  { return myContext.myCollection; }
131  inline const CH_Channel* channel() const
132  { return myContext.myChannel; }
133  inline const CH_Segment* segment() const
134  { return myContext.mySegment; }
135  inline const char* channelName() const
136  { return myContext.myChannelName; }
137 
138  inline void
140  {
141  myContext.setTime(t);
142  }
143  inline void
145  {
146  myContext.setFlicks(fl);
147  }
148 
149  inline void
151  {
152  myContext.myCollection = collection;
153  }
154 
155  // Sets myChannel to channel, myChannelName to myChannel->getName(), and
156  // mySegment to seg. (not inline to avoid #including CH_Channel.h)
157  void setChannel(CH_Channel* channel, CH_Segment* seg);
158 
159  // Sets myChannel/mySegment to NULL and myChannelName to channel_name.
160  void setChannelName(const char* channel_name)
161  {
162  myContext.myChannel = NULL;
163  myContext.mySegment = NULL;
164  myContext.myChannelName = channel_name;
165  }
166 
167 
168  inline void
170  {
171  myContext.mySegment = segment;
172  }
173 
174  inline void
176  const DEP_ContextOptionsReadHandle &options,
177  const DEP_ContextOptionsStack *options_stack)
178  {
179  myContext.myContextOptions = options;
180  myContext.myContextOptionsStack = options_stack;
181  }
182 
183  // Common combinations
184  inline void
185  set(fpreal t, CH_Collection* collection, CH_Channel* chp, CH_Segment* seg)
186  {
187  myContext.setTime(t);
188  myContext.myCollection = collection;
189  setChannel(chp, seg);
190  }
191  inline void
192  set(fpreal t, CH_Collection* collection)
193  {
194  myContext.setTime(t);
195  myContext.myCollection = collection;
196  setChannel(NULL, NULL);
197  }
198  inline void
199  set(SYS_Flicks t, CH_Collection* collection, CH_Channel* chp, CH_Segment* seg)
200  {
201  myContext.setFlicks(t);
202  myContext.myCollection = collection;
203  setChannel(chp, seg);
204  }
205  inline void
207  {
208  myContext.setFlicks(t);
209  myContext.myCollection = collection;
210  setChannel(NULL, NULL);
211  }
212  inline void
213  set(CH_Collection* collection, CH_Channel* channel)
214  {
215  myContext.myCollection = collection;
216  setChannel(channel, NULL);
217  }
218  inline void
219  set(CH_Collection* collection, const char* channel_name)
220  {
221  myContext.myCollection = collection;
222  setChannelName(channel_name);
223  }
224 
225 private:
226  CH_EvalContext& myContext;
227  CH_ScriptAccessManager* myAccessMgr;
228  CH_EvalContext myPrevContext;
229 };
230 
231 #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()
GLuint segment
Definition: glew.h:12701
GT_API const UT_StringHolder time
const CH_Segment * segment() const
void setFlicks(SYS_Flicks fl)
SYS_Flicks flicks() const
GLdouble GLdouble t
Definition: glew.h:1403
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)
const CH_Collection * collection() const
void set(fpreal t, CH_Collection *collection)
void setTime(fpreal t)
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:1620
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)
fpreal time() const
void set(SYS_Flicks t, CH_Collection *collection)
const CH_Channel * channel() const