fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Test / SystemLib / testFieldContainer.cpp
blob2043d7c90a65f5bce04690a2a2c26d7b2f350092
2 #include "OSGBaseInitFunctions.h"
3 #include "OSGNode.h"
4 #include "OSGNodeCore.h"
5 #include "OSGTestFC.h"
7 #if 0
8 static void dumpAspect(OSG::TestFC *pFC, OSG::UInt32 uiAspect)
10 OSG::UInt32 uiCurrAspect= OSG::Thread::getCurrentAspect();
12 OSG::Thread::setAspectTo(uiAspect);
14 #ifdef OSG_MT_CPTR_ASPECT
15 OSG::TestFC *pAFC = OSG::convertToCurrentAspect(pFC);
16 #else
17 OSG::TestFC *pAFC = getCPtr(pFC);
18 #endif
20 if(pAFC != NULL)
22 pAFC->dump();
24 else
26 fprintf(stderr, "No Aspect Ptr\n");
29 OSG::Thread::setAspectTo(uiCurrAspect);
32 void applyToAspect(OSG::UInt32 uiAspect, bool bClear = true)
34 OSG::UInt32 uiCurrAspect= OSG::Thread::getCurrentAspect();
36 OSG::Thread::setAspectTo(uiAspect);
38 OSG::Thread::getCurrentChangeList()->applyNoClear();
40 if(bClear == true)
42 OSG::Thread::getCurrentChangeList()->clear();
45 OSG::Thread::setAspectTo(uiCurrAspect);
48 void applyToAspectAndClear(OSG::UInt32 uiAspect)
50 OSG::UInt32 uiCurrAspect= OSG::Thread::getCurrentAspect();
52 OSG::Thread::setAspectTo(uiAspect);
54 OSG::Thread::getCurrentChangeList()->applyAndClear();
56 OSG::Thread::setAspectTo(uiCurrAspect);
59 void testSharing(void)
61 fprintf(stderr, "sharing\n");
62 fprintf(stderr, "%" PRIUSize "\n", sizeof(OSG::TestFC));
64 OSG::TestFCUnrecPtr pTestFC = OSG::TestFC::create();
66 fprintf(stderr, "sharing | created\n");
68 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
70 fprintf(stderr, "Aspect %d\n", i);
72 dumpAspect(pTestFC, i);
75 OSG::Thread::getCurrentChangeList()->dump();
78 pTestFC->editMFField1()->reserve (32);
79 pTestFC->editMFField1()->push_back( 0);
80 pTestFC->editMFField1()->push_back( 1);
81 pTestFC->editMFField1()->push_back( 2);
82 pTestFC->editMFField1()->push_back( 3);
85 OSG::Thread::getCurrentChangeList()->dump();
88 pTestFC->editSFField2()->setValue(4);
91 OSG::Thread::getCurrentChangeList()->dump();
93 OSG::Thread::getCurrentChangeList()->commitChanges();
95 OSG::Thread::getCurrentChangeList()->dump();
97 fprintf(stderr, "sharing | filled\n");
99 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
101 fprintf(stderr, "Aspect %d\n", i);
102 dumpAspect(pTestFC, i);
105 fprintf(stderr, "sharing | apply\n");
107 applyToAspect(1, false);
108 applyToAspect(2);
110 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
112 fprintf(stderr, "Aspect %d\n", i);
114 dumpAspect(pTestFC, i);
117 pTestFC->editMFField1()->clear();
118 pTestFC->editMFField1()->push_back( 10);
119 pTestFC->editMFField1()->push_back( 11);
120 pTestFC->editMFField1()->push_back( 12);
121 pTestFC->editMFField1()->push_back( 13);
123 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
125 fprintf(stderr, "Aspect %d\n", i);
127 dumpAspect(pTestFC, i);
130 applyToAspect(1, false);
131 applyToAspect(2);
133 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
135 fprintf(stderr, "Aspect %d\n", i);
137 dumpAspect(pTestFC, i);
140 pTestFC = NULL;
143 void testSharing1(void)
145 fprintf(stderr, "sharing\n");
146 fprintf(stderr, "%" PRIUSize "\n", sizeof(OSG::TestFC));
148 OSG::TestFCUnrecPtr pTestFC = OSG::TestFC::create();
150 fprintf(stderr, "sharing | created\n");
152 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
154 fprintf(stderr, "Aspect %d\n", i);
156 dumpAspect(pTestFC, i);
159 OSG::Thread::getCurrentChangeList()->dump();
161 pTestFC->editMFField1()->reserve (1024);
163 for(OSG::UInt32 i = 0; i < 1024; ++i)
165 pTestFC->editMFField1()->push_back(i);
168 OSG::Thread::getCurrentChangeList()->dump();
170 OSG::Thread::getCurrentChangeList()->commitChanges();
172 OSG::Thread::getCurrentChangeList()->dump();
174 fprintf(stderr, "sharing | filled\n");
176 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
178 fprintf(stderr, "Aspect %d\n", i);
179 dumpAspect(pTestFC, i);
182 fprintf(stderr, "sharing | apply\n");
184 applyToAspect(1);
187 while(1)
189 pTestFC->editMFField1();
190 OSG::Thread::getCurrentChangeList()->commitChanges();
191 applyToAspect(1);
195 pTestFC = NULL;
198 void testSharing2(void)
200 fprintf(stderr, "sharing\n");
201 fprintf(stderr, "%" PRIUSize "\n", sizeof(OSG::TestFC));
203 OSG::TestFCUnrecPtr pTestFC = OSG::TestFC::create();
205 fprintf(stderr, "sharing | created\n");
207 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
209 fprintf(stderr, "Aspect %d\n", i);
211 dumpAspect(pTestFC, i);
214 OSG::Thread::getCurrentChangeList()->dump();
216 pTestFC->editMFField1()->reserve (1024);
218 for(OSG::UInt32 i = 0; i < 1024; ++i)
220 pTestFC->editMFField1()->push_back(i);
223 OSG::Thread::getCurrentChangeList()->dump();
225 OSG::Thread::getCurrentChangeList()->commitChanges();
227 OSG::Thread::getCurrentChangeList()->dump();
229 fprintf(stderr, "sharing | filled\n");
231 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
233 fprintf(stderr, "Aspect %d\n", i);
234 dumpAspect(pTestFC, i);
237 fprintf(stderr, "sharing | apply\n");
239 applyToAspect(1);
243 pTestFC = NULL;
245 applyToAspect(1);
248 void testNode(void)
250 #if 0
251 OSG::SFNodePtr sfNode;
252 OSG::MFNodePtr mfNode;
254 OSG::NodePtr pNode = OSG::Node::create();
256 sfNode.setValue(pNode);
257 mfNode.push_back(pNode);
260 fprintf(stderr, "%p %p %p | %d %d\n",
261 pNode,
262 sfNode.getValue(),
263 mfNode[0],
264 OSG::Node::VolumeFieldId,
265 OSG::Node::TravMaskFieldId);
268 OSG::NodePtr pNode1 = OSG::Node::create();
270 sfNode.setValue(pNode1);
271 mfNode.resize(2);
272 mfNode.replace(1, pNode1);
274 const OSG::Field *pF1 = pNode->getSFVolume();
275 OSG::Field *pF2 = pNode->editSFVolume();
277 OSG::GetFieldHandlePtr pRF1 = pNode->getField("volume");
278 OSG::EditFieldHandlePtr pRF2 = pNode->editField("volume");
280 fprintf(stderr, "#### Field %p %p | %p %p\n",
281 pF1,
282 pF2,
283 pRF1.get(),
284 pRF2.get());
286 // fprintf(stderr, "%p %p %p\n", pNode1, sfNode.getValue(), mfNode[1]);
288 const OSG::SFNodePtr constSFNode;
290 // fprintf(stderr, "%p %p\n", pNode1, constSFNode.getValue());
292 OSG::FieldContainerPtr pNodeClone = deepClone(pNode);
294 OSG::FieldContainerPtr pFC =
295 OSG::FieldContainerFactory::the()->createContainer("Billboard");
297 fprintf(stderr, "### FOO %p\n", getCPtr(pFC));
299 #endif
303 void testRefCount(void)
305 #if 0
306 OSG::NodePtr pNode = OSG::Node::create();
308 OSG::NodePtr pNode1 = OSG::Node::create();
310 fprintf(stderr, "1\n");
312 //XX
313 #if 0
314 pNode.dump();
315 pNode1.dump();
316 #endif
318 pNode->addChild(pNode1);
320 fprintf(stderr, "2\n");
322 //XX
323 #if 0
324 pNode.dump();
325 pNode1.dump();
326 #endif
328 fprintf(stderr, "3\n");
330 //XX
331 #if 0
332 pNode.dump();
333 pNode1.dump();
334 #endif
336 applyToAspect(1, false);
337 applyToAspect(2);
339 fprintf(stderr, "4\n");
341 //XX
342 #if 0
343 pNode.dump();
344 pNode1.dump();
345 #endif
347 fprintf(stderr, "5\n");
349 //XX
350 #if 0
351 pNode.dump();
352 pNode1.dump();
353 #endif
355 applyToAspect(1, false);
357 fprintf(stderr, "6\n");
359 //XX
360 #if 0
361 pNode.dump();
362 pNode1.dump();
363 #endif
365 applyToAspect(2);
367 fprintf(stderr, "7\n");
368 #endif
371 void testChangeList(void)
373 fprintf(stderr, "testChangeList\n");
374 fprintf(stderr, "%" PRIUSize "\n", sizeof(OSG::TestFC));
376 OSG::TestFCUnrecPtr pTestFC = OSG::TestFC::create();
378 fprintf(stderr, "sharing | created\n");
380 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
382 fprintf(stderr, "Aspect %d\n", i);
384 dumpAspect(pTestFC, i);
387 OSG::Thread::getCurrentChangeList()->dump();
389 fprintf(stderr, "=================================================\n");
391 pTestFC->editSFField2()->setValue(4);
393 fprintf(stderr, "Changed\n");
394 OSG::Thread::getCurrentChangeList()->dump();
396 OSG::Thread::getCurrentChangeList()->commitChanges();
398 fprintf(stderr, "Commited\n");
399 OSG::Thread::getCurrentChangeList()->dump();
401 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
403 fprintf(stderr, "Aspect %d\n", i);
405 dumpAspect(pTestFC, i);
408 fprintf(stderr, "=================================================\n");
410 pTestFC->editSFField2()->setValue(4);
412 fprintf(stderr, "Changed\n");
413 OSG::Thread::getCurrentChangeList()->dump();
415 OSG::Thread::getCurrentChangeList()->commitChangesAndClear();
417 fprintf(stderr, "CommitAndCleared\n");
418 OSG::Thread::getCurrentChangeList()->dump();
420 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
422 fprintf(stderr, "Aspect %d\n", i);
424 dumpAspect(pTestFC, i);
427 fprintf(stderr, "=================================================\n");
429 pTestFC->editSFField2()->setValue(4);
431 fprintf(stderr, "Changed\n");
432 OSG::Thread::getCurrentChangeList()->dump();
434 // OSG::Thread::getCurrentChangeList()->commitChanges();
436 applyToAspectAndClear(1);
438 fprintf(stderr, "Changed\n");
439 OSG::Thread::getCurrentChangeList()->dump();
441 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
443 fprintf(stderr, "Aspect %d\n", i);
445 dumpAspect(pTestFC, i);
448 fprintf(stderr, "=================================================\n");
450 pTestFC->editSFField2()->setValue(4);
452 fprintf(stderr, "Changed\n");
453 OSG::Thread::getCurrentChangeList()->dump();
455 // OSG::Thread::getCurrentChangeList()->commitChanges();
457 applyToAspect(1, false);
459 fprintf(stderr, "Changed\n");
460 OSG::Thread::getCurrentChangeList()->dump();
462 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
464 fprintf(stderr, "Aspect %d\n", i);
466 dumpAspect(pTestFC, i);
469 fprintf(stderr, "=================================================\n");
471 pTestFC->editSFField2()->setValue(4);
473 fprintf(stderr, "Changed\n");
474 OSG::Thread::getCurrentChangeList()->dump();
476 // OSG::Thread::getCurrentChangeList()->commitChanges();
478 applyToAspect(1, true);
480 fprintf(stderr, "Changed\n");
481 OSG::Thread::getCurrentChangeList()->dump();
483 for(OSG::UInt32 i = 0; i < OSG::ThreadManager::getNumAspects(); ++i)
485 fprintf(stderr, "Aspect %d\n", i);
487 dumpAspect(pTestFC, i);
490 pTestFC = NULL;
492 #endif
494 int main (int argc, char **argv)
496 #if 0
497 OSG::ThreadManager::setNumAspects(3);
498 OSG::osgInit(argc, argv);
500 OSG::Thread::getCurrentChangeList()->dump ();
501 OSG::Thread::getCurrentChangeList()->clear();
503 OSG::Node ::getClassType().dump();
504 OSG::NodeCore::getClassType().dump();
506 // testRefCount();
507 // testNode();
509 testSharing();
511 // testChangeList();
513 fprintf(stderr, "exit\n");
515 OSG::osgExit();
516 #endif
518 return 0;