fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Base / testProtoAndFieldSettings.cpp
blobbb9f05d642fe31a66dd6ca9ca8bcd39429dd6f7b
2 #include "OSGBaseFunctions.h"
3 #include "OSGMatrixCamera.h"
4 #include "OSGNodeCore.h"
5 #include "OSGGroup.h"
6 #include "OSGComponentTransform.h"
8 void testClassType(void)
10 fprintf(stderr, "====================================================\n");
11 fprintf(stderr, "create marking class type\n");
12 fprintf(stderr, "====================================================\n");
14 OSG::MatrixCamera::getClassType().dumpFieldInfo();
16 OSG::MatrixCamera::getClassType().setFieldsUnmarkedOnCreate(
17 OSG::MatrixCamera::BeaconFieldMask |
18 OSG::MatrixCamera::ProjectionMatrixFieldMask);
20 OSG::MatrixCamera::getClassType().dumpFieldInfo();
22 OSG::MatrixCamera::getClassType().clearFieldsUnmarkedOnCreate(
23 OSG::MatrixCamera::NearFieldMask |
24 OSG::MatrixCamera::ProjectionMatrixFieldMask);
26 OSG::MatrixCamera::getClassType().dumpFieldInfo();
28 OSG::MatrixCamera::getClassType().clearFieldsUnmarkedOnCreate(
29 OSG::MatrixCamera::BeaconFieldMask);
31 OSG::MatrixCamera::getClassType().dumpFieldInfo();
33 fprintf(stderr, "====================================================\n");
34 fprintf(stderr, "cluster local class type\n");
35 fprintf(stderr, "====================================================\n");
37 OSG::MatrixCamera::getClassType().markFieldsClusterLocal(
38 OSG::MatrixCamera::BeaconFieldMask |
39 OSG::MatrixCamera::ProjectionMatrixFieldMask);
41 OSG::MatrixCamera::getClassType().dumpFieldInfo();
43 OSG::MatrixCamera::getClassType().unmarkFieldsClusterLocal(
44 OSG::MatrixCamera::NearFieldMask |
45 OSG::MatrixCamera::ProjectionMatrixFieldMask);
47 OSG::MatrixCamera::getClassType().dumpFieldInfo();
49 OSG::MatrixCamera::getClassType().unmarkFieldsClusterLocal(
50 OSG::MatrixCamera::BeaconFieldMask);
52 OSG::MatrixCamera::getClassType().dumpFieldInfo();
55 fprintf(stderr, "====================================================\n");
56 fprintf(stderr, "thread local class type\n");
57 fprintf(stderr, "====================================================\n");
59 OSG::MatrixCamera::getClassType().markFieldsThreadLocal(
60 OSG::MatrixCamera::BeaconFieldMask |
61 OSG::MatrixCamera::ProjectionMatrixFieldMask);
63 OSG::MatrixCamera::getClassType().dumpFieldInfo();
65 OSG::MatrixCamera::getClassType().unmarkFieldsThreadLocal(
66 OSG::MatrixCamera::NearFieldMask |
67 OSG::MatrixCamera::ProjectionMatrixFieldMask);
69 OSG::MatrixCamera::getClassType().dumpFieldInfo();
71 OSG::MatrixCamera::getClassType().unmarkFieldsThreadLocal(
72 OSG::MatrixCamera::BeaconFieldMask);
74 OSG::MatrixCamera::getClassType().dumpFieldInfo();
76 fprintf(stderr, "\n\n");
79 void testCreateMarking(void)
81 fprintf(stderr, "====================================================\n");
82 fprintf(stderr, "create marking container\n");
83 fprintf(stderr, "====================================================\n");
85 OSG::MatrixCameraUnrecPtr pCam1 = OSG::MatrixCamera::create();
87 pCam1->dumpFieldInfo();
89 OSG::MatrixCamera::getClassType().setFieldsUnmarkedOnCreate(
90 OSG::MatrixCamera::NearFieldMask |
91 OSG::MatrixCamera::ProjectionMatrixFieldMask);
93 OSG::MatrixCamera::getClassType().dumpFieldInfo();
95 pCam1 = NULL;
97 pCam1 = OSG::MatrixCamera::create();
99 pCam1->dumpFieldInfo();
101 pCam1 = NULL;
103 OSG::MatrixCamera::getClassType().clearFieldsUnmarkedOnCreate(
104 OSG::MatrixCamera::NearFieldMask |
105 OSG::MatrixCamera::ProjectionMatrixFieldMask);
107 OSG::MatrixCamera::getClassType().dumpFieldInfo();
109 fprintf(stderr, "\n\n");
112 void testClusterLocalType(void)
114 fprintf(stderr, "====================================================\n");
115 fprintf(stderr, "cluster local container/type\n");
116 fprintf(stderr, "====================================================\n");
118 OSG::MatrixCameraUnrecPtr pCam1 = OSG::MatrixCamera::create();
120 pCam1->dumpFieldInfo();
122 OSG::MatrixCamera::getClassType().markFieldsClusterLocal(
123 OSG::MatrixCamera::NearFieldMask |
124 OSG::MatrixCamera::ProjectionMatrixFieldMask);
126 OSG::MatrixCamera::getClassType().dumpFieldInfo();
128 pCam1->dumpFieldInfo();
130 pCam1 = NULL;
132 pCam1 = OSG::MatrixCamera::create();
134 pCam1->dumpFieldInfo();
136 pCam1 = NULL;
138 OSG::MatrixCamera::getClassType().unmarkFieldsClusterLocal(
139 OSG::MatrixCamera::NearFieldMask |
140 OSG::MatrixCamera::ProjectionMatrixFieldMask);
142 OSG::MatrixCamera::getClassType().dumpFieldInfo();
144 pCam1 = OSG::MatrixCamera::create();
146 pCam1->dumpFieldInfo();
148 pCam1 = NULL;
150 fprintf(stderr, "\n\n");
153 void testThreadLocalType(void)
155 fprintf(stderr, "====================================================\n");
156 fprintf(stderr, "thread local container/type\n");
157 fprintf(stderr, "====================================================\n");
159 OSG::MatrixCameraUnrecPtr pCam1 = OSG::MatrixCamera::create();
161 pCam1->dumpFieldInfo();
163 OSG::MatrixCamera::getClassType().markFieldsThreadLocal(
164 OSG::MatrixCamera::NearFieldMask |
165 OSG::MatrixCamera::ProjectionMatrixFieldMask);
167 OSG::MatrixCamera::getClassType().dumpFieldInfo();
169 pCam1->dumpFieldInfo();
171 pCam1 = NULL;
173 pCam1 = OSG::MatrixCamera::create();
175 pCam1->dumpFieldInfo();
177 pCam1 = NULL;
179 OSG::MatrixCamera::getClassType().unmarkFieldsThreadLocal(
180 OSG::MatrixCamera::NearFieldMask |
181 OSG::MatrixCamera::ProjectionMatrixFieldMask);
183 OSG::MatrixCamera::getClassType().dumpFieldInfo();
185 pCam1 = OSG::MatrixCamera::create();
187 pCam1->dumpFieldInfo();
189 pCam1 = NULL;
191 fprintf(stderr, "\n\n");
194 void testClusterLocalContainer(void)
196 fprintf(stderr, "====================================================\n");
197 fprintf(stderr, "cluster local container/container\n");
198 fprintf(stderr, "====================================================\n");
201 fprintf(stderr, "====================================================\n");
202 fprintf(stderr, "A|\n");
203 fprintf(stderr, "====================================================\n");
205 OSG::MatrixCamera::getClassType().dumpFieldInfo();
207 OSG::MatrixCameraUnrecPtr pCam1 = OSG::MatrixCamera::create();
209 pCam1->dumpFieldInfo();
211 pCam1->markFieldsClusterLocal(
212 OSG::MatrixCamera::NearFieldMask |
213 OSG::MatrixCamera::ProjectionMatrixFieldMask);
215 pCam1->dumpFieldInfo();
217 pCam1 = NULL;
219 fprintf(stderr, "====================================================\n");
220 fprintf(stderr, "B|\n");
221 fprintf(stderr, "====================================================\n");
223 pCam1 = OSG::MatrixCamera::create();
225 pCam1->dumpFieldInfo();
227 pCam1->markFieldsClusterLocal(
228 OSG::MatrixCamera::NearFieldMask |
229 OSG::MatrixCamera::ProjectionMatrixFieldMask);
231 pCam1->dumpFieldInfo();
233 pCam1->unmarkFieldsClusterLocal(
234 OSG::MatrixCamera::NearFieldMask |
235 OSG::MatrixCamera::ProjectionMatrixFieldMask);
237 pCam1->dumpFieldInfo();
239 pCam1 = NULL;
241 fprintf(stderr, "====================================================\n");
242 fprintf(stderr, "C|\n");
243 fprintf(stderr, "====================================================\n");
246 pCam1 = OSG::MatrixCamera::create();
248 pCam1->dumpFieldInfo();
250 pCam1 = NULL;
252 OSG::MatrixCamera::getClassType().dumpFieldInfo();
254 fprintf(stderr, "\n\n");
257 void testThreadLocalContainer(void)
259 fprintf(stderr, "====================================================\n");
260 fprintf(stderr, "thread local container/container\n");
261 fprintf(stderr, "====================================================\n");
264 fprintf(stderr, "====================================================\n");
265 fprintf(stderr, "A|\n");
266 fprintf(stderr, "====================================================\n");
268 OSG::MatrixCamera::getClassType().dumpFieldInfo();
270 OSG::MatrixCameraUnrecPtr pCam1 = OSG::MatrixCamera::create();
272 pCam1->dumpFieldInfo();
274 pCam1->markFieldsThreadLocal(
275 OSG::MatrixCamera::NearFieldMask |
276 OSG::MatrixCamera::ProjectionMatrixFieldMask);
278 pCam1->dumpFieldInfo();
280 pCam1 = NULL;
282 fprintf(stderr, "====================================================\n");
283 fprintf(stderr, "B|\n");
284 fprintf(stderr, "====================================================\n");
286 pCam1 = OSG::MatrixCamera::create();
288 pCam1->dumpFieldInfo();
290 pCam1->markFieldsThreadLocal(
291 OSG::MatrixCamera::NearFieldMask |
292 OSG::MatrixCamera::ProjectionMatrixFieldMask);
294 pCam1->dumpFieldInfo();
296 pCam1->unmarkFieldsThreadLocal(
297 OSG::MatrixCamera::NearFieldMask |
298 OSG::MatrixCamera::ProjectionMatrixFieldMask);
300 pCam1->dumpFieldInfo();
302 pCam1 = NULL;
304 fprintf(stderr, "====================================================\n");
305 fprintf(stderr, "C|\n");
306 fprintf(stderr, "====================================================\n");
309 pCam1 = OSG::MatrixCamera::create();
311 pCam1->dumpFieldInfo();
313 pCam1 = NULL;
315 OSG::MatrixCamera::getClassType().dumpFieldInfo();
317 fprintf(stderr, "\n\n");
320 void testPrototypeReplacement(void)
322 fprintf(stderr, "====================================================\n");
323 fprintf(stderr, "replace proto\n");
324 fprintf(stderr, "====================================================\n");
326 OSG::FieldContainer *pNCProto =
327 OSG::NodeCore::getClassType().getPrototype();
329 fprintf(stderr, "node core proto %p\n", static_cast<void *>(pNCProto));
331 OSG::FieldContainer *pMCProto =
332 OSG::MatrixCamera::getClassType().getPrototype();
334 fprintf(stderr, "matrix cam proto %p\n", static_cast<void *>(pMCProto));
337 OSG::GroupUnrecPtr pGroup = OSG::Group ::create();
338 OSG::MatrixCameraUnrecPtr pMatrixCam = OSG::MatrixCamera::create();
340 fprintf(stderr, "tmp group ptr %p | tmp matrix cam ptr %p\n",
341 static_cast<void *>(pGroup.get()),
342 static_cast<void *>(pMatrixCam.get()));
345 fprintf(stderr, "====================================================\n");
346 fprintf(stderr, "replace abstract proto\n");
347 fprintf(stderr, "====================================================\n");
349 bool rc = OSG::NodeCore::getClassType().setPrototype(pGroup);
351 fprintf(stderr, "set proto result %d\n", rc);
353 fprintf(stderr, "====================================================\n");
354 fprintf(stderr, "remove proto\n");
355 fprintf(stderr, "====================================================\n");
357 rc = OSG::MatrixCamera::getClassType().setPrototype(NULL);
359 fprintf(stderr, "set proto result %d\n", rc);
361 fprintf(stderr, "====================================================\n");
362 fprintf(stderr, "set incompatible proto\n");
363 fprintf(stderr, "====================================================\n");
365 rc = OSG::MatrixCamera::getClassType().setPrototype(pGroup);
367 fprintf(stderr, "set proto result %d\n", rc);
370 fprintf(stderr, "====================================================\n");
371 fprintf(stderr, "check\n");
372 fprintf(stderr, "====================================================\n");
374 pMCProto = OSG::MatrixCamera::getClassType().getPrototype();
376 fprintf(stderr, "matrix cam proto %p\n", static_cast<void *>(pMCProto));
378 OSG::MatrixCameraUnrecPtr pNewMatrixCam = OSG::MatrixCamera::create();
380 fprintf(stderr, "new matrix cam ptr %p\n",
381 static_cast<void *>(pNewMatrixCam.get()));
383 fprintf(stderr, "====================================================\n");
384 fprintf(stderr, "set same type proto\n");
385 fprintf(stderr, "====================================================\n");
387 rc = OSG::MatrixCamera::getClassType().setPrototype(pMatrixCam);
389 fprintf(stderr, "set proto result %d\n", rc);
391 pMCProto = OSG::MatrixCamera::getClassType().getPrototype();
393 fprintf(stderr, "matrix cam proto %p\n", static_cast<void *>(pMCProto));
395 pNewMatrixCam = OSG::MatrixCamera::create();
397 fprintf(stderr, "new matrix cam ptr %p\n",
398 static_cast<void *>(pNewMatrixCam.get()));
400 fprintf(stderr, "====================================================\n");
401 fprintf(stderr, "set derived type proto\n");
402 fprintf(stderr, "====================================================\n");
404 OSG::ComponentTransformUnrecPtr pCTr = OSG::ComponentTransform::create();
406 fprintf(stderr, "comp tr ptr %p\n", static_cast<void *>(pCTr.get()));
408 rc = OSG::Transform::getClassType().setPrototype(pCTr);
410 fprintf(stderr, "set proto result %d\n", rc);
412 pMCProto = OSG::Transform::getClassType().getPrototype();
414 fprintf(stderr, "transform proto %p\n", static_cast<void *>(pMCProto));
416 OSG::TransformUnrecPtr pTr = OSG::Transform::create();
418 fprintf(stderr, "new tr ptr %p", static_cast<void *>(pTr.get()));
420 if(pTr != NULL)
422 fprintf(stderr, "new tr type %s\n", pTr->getType().getCName());
425 pGroup = NULL;
426 pMatrixCam = NULL;
427 pNewMatrixCam = NULL;
428 pCTr = NULL;
429 pTr = NULL;
433 void testPrototypeReplacementWithFlags(void)
435 fprintf(stderr, "====================================================\n");
436 fprintf(stderr, "replace proto with flags\n");
437 fprintf(stderr, "====================================================\n");
439 OSG::FieldContainer *pMCProto =
440 OSG::MatrixCamera::getClassType().getPrototype();
442 fprintf(stderr, "matrix cam proto %p\n", static_cast<void *>(pMCProto));
445 OSG::MatrixCameraUnrecPtr pMatrixCam = OSG::MatrixCamera::create();
446 OSG::UInt32 rc = 0;
448 fprintf(stderr, "tmp matrix cam ptr %p\n",
449 static_cast<void *>(pMatrixCam.get()));
452 OSG::MatrixCamera::getClassType().dumpFieldInfo();
454 pMatrixCam->dumpFieldInfo();
456 fprintf(stderr, "====================================================\n");
457 fprintf(stderr, "A|\n");
458 fprintf(stderr, "====================================================\n");
460 OSG::MatrixCameraUnrecPtr pNewMatrixCam = OSG::MatrixCamera::create();
462 fprintf(stderr, "new matrix cam ptr %p\n",
463 static_cast<void *>(pNewMatrixCam.get()));
465 pNewMatrixCam->markFieldsThreadLocal(
466 OSG::MatrixCamera::NearFieldMask |
467 OSG::MatrixCamera::ProjectionMatrixFieldMask);
469 pNewMatrixCam->markFieldsClusterLocal(
470 OSG::MatrixCamera::NearFieldMask |
471 OSG::MatrixCamera::ProjectionMatrixFieldMask);
473 OSG::MatrixCamera::getClassType().dumpFieldInfo();
475 pNewMatrixCam->dumpFieldInfo();
477 fprintf(stderr, "====================================================\n");
478 fprintf(stderr, "set same type proto\n");
479 fprintf(stderr, "====================================================\n");
481 rc = OSG::MatrixCamera::getClassType().setPrototype(pNewMatrixCam);
483 fprintf(stderr, "set proto result %d\n", rc);
485 pMCProto = OSG::MatrixCamera::getClassType().getPrototype();
487 fprintf(stderr, "matrix cam proto %p\n", static_cast<void *>(pMCProto));
489 OSG::MatrixCamera::getClassType().dumpFieldInfo();
491 pNewMatrixCam->dumpFieldInfo();
492 pMCProto->dumpFieldInfo();
495 fprintf(stderr, "====================================================\n");
496 fprintf(stderr, "B|\n");
497 fprintf(stderr, "====================================================\n");
499 pNewMatrixCam = OSG::MatrixCamera::create();
501 fprintf(stderr, "new matrix cam ptr %p\n",
502 static_cast<void *>(pNewMatrixCam.get()));
504 OSG::MatrixCamera::getClassType().dumpFieldInfo();
506 pNewMatrixCam->dumpFieldInfo();
508 pMatrixCam = NULL;
509 pNewMatrixCam = NULL;
512 int main (int argc, char **argv)
514 OSG::osgInit(argc, argv);
516 // testClassType();
517 // testCreateMarking();
518 // testClusterLocalType();
519 // testThreadLocalType();
520 // testClusterLocalContainer();
521 // testThreadLocalContainer();
522 // testPrototypeReplacement();
523 testPrototypeReplacementWithFlags();
525 OSG::osgExit();
527 return 0;