-
Notifications
You must be signed in to change notification settings - Fork 1
/
OSGAction.h
executable file
·352 lines (250 loc) · 13.1 KB
/
OSGAction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*---------------------------------------------------------------------------*\
* OpenSG *
* *
* *
* Copyright (C) 2000-2002 by the OpenSG Forum *
* *
* www.opensg.org *
* *
* *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
* License *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Library General Public License as published *
* by the Free Software Foundation, version 2. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
* Changes *
* *
* *
* *
* *
* *
* *
\*---------------------------------------------------------------------------*/
#ifndef _OSGACTION_H_
#define _OSGACTION_H_
#ifdef __sgi
#pragma once
#endif
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include <vector>
#include <OSGSystemDef.h>
#include <OSGBaseTypes.h>
#include <OSGFieldContainerType.h>
#include <OSGNodePtr.h>
#include <OSGTypedFunctors.h>
OSG_BEGIN_NAMESPACE
//---------------------------------------------------------------------------
// Forward References
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Types
//---------------------------------------------------------------------------
class Node;
class Action;
//---------------------------------------------------------------------------
// Class
//---------------------------------------------------------------------------
/*! \brief Action base class
*/
class OSG_SYSTEMLIB_DLLMAPPING Action {
public:
//-----------------------------------------------------------------------
// enums
//-----------------------------------------------------------------------
enum ResultE {
Continue, // continue with my children
Skip, // skip my children
// really needed? Cancel, // skip my brothers, go one step up
Quit // forget it, you're done
};
typedef ArgsCollector<Action*> FunctorArgs;
typedef TypedFunctor2Base<ResultE, CPtrRefCallArg<CNodePtr>, FunctorArgs> Functor;
//-----------------------------------------------------------------------
// types
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class functions
//-----------------------------------------------------------------------
static const char* getClassname(void) {
return "Action";
}
// create a new action by cloning the prototype
static Action* create(void);
// prototype access
// after setting the prototype all new actions are clones of it
static void setPrototype(Action* proto);
static Action* getPrototype(void);
//-----------------------------------------------------------------------
// instance functions
//-----------------------------------------------------------------------
virtual ~Action(void);
/*------------------------- your_category -------------------------------*/
// default registration. static, so it can be called during static init
static void registerEnterDefault(const FieldContainerType& type, const Functor& func);
static void registerLeaveDefault(const FieldContainerType& type, const Functor& func);
// instance registration
void registerEnterFunction(const FieldContainerType& type, const Functor& func);
void registerLeaveFunction(const FieldContainerType& type, const Functor& func);
// application
virtual ResultE apply(std::vector<NodePtr>::iterator begin, std::vector<NodePtr>::iterator end);
virtual ResultE apply(NodePtr node);
// the node being traversed. Might be needed by the traversed core
inline NodePtr getActNode(void);
// Node access:
// the number of active nodes
UInt32 getNNodes(void) const;
// you can access a single node by getNode
const NodePtr getNode(int index);
// per default all child nodes are traversed. If addNode is called, only the
// added nodes will be traversed.
void addNode(NodePtr node);
// Common case: going through the children list and picking up some of them,
// but it's not clear if any at all. Call useNodeList() and then
// addNode() for every node to traverse, or not at all.
void useNodeList(void);
/*------------------------- your_operators ------------------------------*/
/*------------------------- assignment ----------------------------------*/
inline UInt32 getTravMask(void) const;
inline void setTravMask(UInt32 val);
/*------------------------- comparison ----------------------------------*/
bool operator<(const Action& other);
bool operator==(const Action& other);
bool operator!=(const Action& other);
protected:
//-----------------------------------------------------------------------
// enums
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// types
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class variables
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class functions
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// instance variables
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// instance functions
//-----------------------------------------------------------------------
// protected to allow derived access
Action(void);
Action(const Action& source);
// call the single node. used for cascading actions
inline ResultE callEnter(NodePtr node);
inline ResultE callLeave(NodePtr node);
// start/stop functions for the action.
// called at the very beginning/end, can return a list of nodes
// via addNode() which is traversed before/after the traversal is done
// main use: collecting actions use stop() to emit their collection
virtual ResultE start(void);
virtual ResultE stop(ResultE res); // res is the exit code of the action
// recurse through the node
ResultE recurse(NodePtr node);
// call the _newList list of nodes
ResultE callNewList(void);
// access default functors
virtual std::vector<Functor>* getDefaultEnterFunctors(void);
virtual std::vector<Functor>* getDefaultLeaveFunctors(void);
// default function
static ResultE _defaultEnterFunction(CNodePtr& node, Action* action);
static ResultE _defaultLeaveFunction(CNodePtr& node, Action* action);
// functors
// just protected, so that derived actions can access them
std::vector<Functor> _enterFunctors;
std::vector<Functor> _leaveFunctors;
// the node being traversed. Might be needed by the traversed core
// needs to be set by the RenderAction, as the draw tree is traversed
// after the graph traversal
inline void setActNode(NodePtr node);
private:
//-----------------------------------------------------------------------
// enums
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// types
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// friend classes
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// friend functions
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class variables
//-----------------------------------------------------------------------
static char cvsid[];
// the prototype which is copied to create new actions
static Action* _prototype;
// default functors for instantiation
static std::vector<Functor>* _defaultEnterFunctors;
static std::vector<Functor>* _defaultLeaveFunctors;
//-----------------------------------------------------------------------
// class functions
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// instance variables
//-----------------------------------------------------------------------
NodePtr _actNode; // the node being traversed right now
std::vector<NodePtr>* _actList; // list of active objects for this level
// if empty, use the actNode's children
bool _useNewList; // set by clearNodeList
std::vector<NodePtr> _newList; // list of active object for this level
UInt32 _travMask;
//-----------------------------------------------------------------------
// instance functions
//-----------------------------------------------------------------------
// helper functions for start/stop, that also call the results of
// start/stop
ResultE callStart(void);
ResultE callStop(ResultE res);
Action& operator=(const Action& source);
};
//---------------------------------------------------------------------------
// Exported Types
//---------------------------------------------------------------------------
// class pointer
typedef Action* ActionP;
/*---------------------------------------------------------------------*/
/*! \name Traversal Functions */
/*! \{ */
typedef ArgsCollector<Action::ResultE> ArgsT;
typedef TypedFunctor1Base<Action::ResultE, CPtrRefCallArg<NodePtr>> TraverseEnterFunctor;
typedef TypedFunctor2Base<Action::ResultE, CPtrRefCallArg<NodePtr>, ArgsT> TraverseLeaveFunctor;
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(NodePtr root, TraverseEnterFunctor func);
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(std::vector<NodePtr>& nodeList, TraverseEnterFunctor func);
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(NodePtr root, TraverseEnterFunctor enter, TraverseLeaveFunctor leave);
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(
std::vector<NodePtr>& nodeList, TraverseEnterFunctor enter, TraverseLeaveFunctor leave);
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(NodePtr root, TraverseEnterFunctor* enter, TraverseLeaveFunctor* leave);
OSG_SYSTEMLIB_DLLMAPPING
Action::ResultE traverse(
std::vector<NodePtr>& nodeList, TraverseEnterFunctor* enter, TraverseLeaveFunctor* leave);
/*! \} */
OSG_END_NAMESPACE
#include "OSGAction.inl"
#endif /* _OSGACTION_H_ */