00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGFIELDCONTAINERPTRIMPL_H_
00040 #define _OSGFIELDCONTAINERPTRIMPL_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #ifdef OSG_DOC_FILES_IN_MODULE
00046
00049 #endif
00050
00051 #include <OSGConceptPropertyChecks.h>
00052 #include <OSGFieldContainerProperties.h>
00053 #include <OSGSystemDef.h>
00054 #include <OSGBaseTypes.h>
00055
00056 #include <OSGThread.h>
00057 #include <OSGLock.h>
00058 #include <OSGThreadManager.h>
00059
00060 #include <utility>
00061 #include <iostream>
00062
00063 OSG_BEGIN_NAMESPACE
00064
00065 class FieldContainer;
00066 class LockPool;
00067 class NullFieldContainerPtr;
00068
00069
00070
00071
00072
00076 #ifdef __sgi
00077 #pragma set woff 1424
00078 #endif
00079
00080 #ifdef OSG_LINUX_ICC
00081 #pragma warning( disable : 444 )
00082 #endif
00083
00084
00085
00086
00087
00088 #ifdef __sgi
00089 #pragma set woff 1375
00090 #endif
00091
00092 class OSG_SYSTEMLIB_DLLMAPPING FieldContainerPtrBase
00093 {
00094
00095
00096 public:
00097
00098 static const UInt16 InvalidParentEPos;
00099 typedef UInt8 * FieldContainerPtrBase::*unspecified_bool_type;
00100
00101
00105 FieldContainerPtrBase( void );
00106 FieldContainerPtrBase(const NullFieldContainerPtr & );
00107 FieldContainerPtrBase(const FieldContainerPtrBase &source);
00108
00110
00114 ~FieldContainerPtrBase(void);
00115
00117
00121 void setParentFieldPos(UInt16 uiParentEPos);
00122 UInt16 getParentFieldPos(void ) const;
00123
00125
00129 Int32 getRefCount (void) const;
00130 UInt32 getFieldContainerId(void) const;
00131 UInt16 getContainerSize (void) const;
00132
00134
00136
00139 FieldContainer *getBaseCPtr (void ) const;
00140 FieldContainer *getAspectCPtr(UInt32 uiAspectId) const;
00141
00143
00147 void operator =(const NullFieldContainerPtr &);
00148 void operator =(const FieldContainerPtrBase &source);
00149
00151
00155 bool operator < (const NullFieldContainerPtr & ) const;
00156
00157 bool operator == (const NullFieldContainerPtr &other) const;
00158 bool operator != (const NullFieldContainerPtr &other) const;
00159
00160
00161 bool operator < (const FieldContainerPtrBase &) const;
00162
00163 bool operator == (const FieldContainerPtrBase &other) const;
00164 bool operator != (const FieldContainerPtrBase &other) const;
00165
00166 bool operator ! (void ) const;
00167
00168 operator unspecified_bool_type() const;
00169
00171
00175 void dump( UInt32 uiIndent = 0,
00176 const BitVector bvFlags = 0) const;
00177
00179
00180
00181 protected:
00182
00183
00187 static bool initialize(void);
00188 static bool terminate (void);
00189
00191
00195 UInt16 _containerSize;
00196 UInt16 _uiParentEPos;
00197 UInt8 *_storeP;
00198 #ifdef OSG_DEBUG_FCPTR
00199 FieldContainer *_typedStoreP;
00200 #endif
00201
00203
00207 explicit FieldContainerPtrBase(const FieldContainer &source );
00208 explicit FieldContainerPtrBase(const FieldContainer *source );
00209
00210 FieldContainerPtrBase(const FieldContainer *source,
00211 const UInt16 uiSize,
00212 const UInt16 uiParentEPos);
00213
00215
00219 void executeSync(UInt32 uiFromAspect,
00220 UInt32 uiToAspect,
00221 BitVector whichField);
00222
00224
00228 Int32 *getRefCountP (void );
00229 Int32 *getRefCountP (void ) const;
00230
00231 UInt32 *getIdP (void );
00232 UInt32 *getIdP (void ) const;
00233
00234 UInt8 *getFirstElemP(void );
00235 UInt8 *getFirstElemP(void ) const;
00236
00237 UInt8 *getElemP (UInt32 uiElemNum);
00238 UInt8 *getElemP (UInt32 uiElemNum) const;
00239
00241
00245 Int32 getRefCountOff (void ) const;
00246 Int32 getIdOff (void ) const;
00247 Int32 getFirstElemOff(void ) const;
00248 Int32 getElemOff (UInt32 uiElemNum) const;
00249
00251
00255 void addRef (void) const;
00256 void subRef (void) const;
00257
00258 #if defined(OSG_FIXED_MFIELDSYNC)
00259 void doSubRef (void) const;
00260 #endif
00261
00262 void deleteContainers(void) const;
00263
00265
00269 void setNull(void);
00270
00272
00273
00274 private:
00275
00276 friend class FieldContainer;
00277 friend class FieldContainerFactory;
00278 friend class ChangeList;
00279
00280 #ifndef OSG_INVALID_PTR_CHECK
00281
00282 friend OSG_SYSTEMLIB_DLLMAPPING
00283 void addRefCP (const FieldContainerPtrBase &objectP);
00284
00285 friend OSG_SYSTEMLIB_DLLMAPPING
00286 void subRefCP (const FieldContainerPtrBase &objectP);
00287
00288 friend OSG_SYSTEMLIB_DLLMAPPING
00289 void setRefdCP ( FieldContainerPtrBase &objectP,
00290 const FieldContainerPtrBase &newObjectP);
00291
00292 friend OSG_SYSTEMLIB_DLLMAPPING
00293 void clearRefCP ( FieldContainerPtrBase &objectP);
00294
00295 #else
00296
00297 friend OSG_SYSTEMLIB_DLLMAPPING
00298 bool safeAddRefCP (const FieldContainerPtrBase &objectP);
00299
00300 friend OSG_SYSTEMLIB_DLLMAPPING
00301 bool safeSubRefCP (const FieldContainerPtrBase &objectP);
00302
00303 friend OSG_SYSTEMLIB_DLLMAPPING
00304 bool safeSetRefdCP ( FieldContainerPtrBase &objectP,
00305 const FieldContainerPtrBase &newObjectP);
00306
00307 friend OSG_SYSTEMLIB_DLLMAPPING
00308 bool safeClearRefCP ( FieldContainerPtrBase &objectP);
00309
00310 #endif
00311
00312 friend OSG_SYSTEMLIB_DLLMAPPING
00313 class FieldContainerType;
00314
00315 static LockPool *_pRefCountLock;
00316 };
00317
00318 #ifdef __sgi
00319 #pragma reset woff 1375
00320 #endif
00321
00322
00323
00324
00325
00326
00327
00331 #ifdef __sgi
00332 #pragma set woff 1375
00333 #endif
00334
00335 class OSG_SYSTEMLIB_DLLMAPPING FieldContainerPtr : public FieldContainerPtrBase
00336 {
00337
00338
00339 public:
00340
00341 OSG_PROPERTY_DECL(Pointer);
00342
00343 typedef FieldContainer StoredObjectType;
00344 typedef FieldContainerPtr ObjectType;
00345
00346 typedef FieldContainerPtrBase Inherited;
00347
00348
00352 FieldContainerPtr( void );
00353 FieldContainerPtr(const NullFieldContainerPtr & );
00354 FieldContainerPtr(const FieldContainerPtr &source);
00355
00357
00361 ~FieldContainerPtr(void);
00362
00364
00368 FieldContainer *operator->(void);
00369 FieldContainer *operator->(void) const;
00370
00371 FieldContainer &operator *(void);
00372 FieldContainer &operator *(void) const;
00373
00374 FieldContainer *getCPtr (void);
00375 FieldContainer *getCPtr (void) const;
00376
00378
00382 void operator =(const NullFieldContainerPtr & );
00383 void operator =(const FieldContainerPtr &source);
00384
00386
00387
00388 protected:
00389
00390
00394 void beginEdit (BitVector whichField, UInt32 origin) const;
00395 void endEdit (BitVector whichField, UInt32 origin) const;
00396 void changed (BitVector whichField, UInt32 origin) const;
00397 void endEditNotChanged(BitVector whichField, UInt32 origin) const;
00398
00400
00404 explicit FieldContainerPtr(const FieldContainer &source);
00405 explicit FieldContainerPtr(const FieldContainer *source);
00406
00407 FieldContainerPtr(const FieldContainer *source,
00408 const UInt16 uiSize,
00409 const UInt16 uiParentEPos);
00410
00412
00413
00414 private:
00415
00416 friend class FieldContainer;
00417
00418 friend OSG_SYSTEMLIB_DLLMAPPING
00419 void beginEditCP (const FieldContainerPtr &objectP,
00420 BitVector whichField,
00421 UInt32 origin );
00422
00423 friend OSG_SYSTEMLIB_DLLMAPPING
00424 void endEditCP (const FieldContainerPtr &objectP,
00425 BitVector whichField,
00426 UInt32 origin );
00427
00428 friend OSG_SYSTEMLIB_DLLMAPPING
00429 void changedCP (const FieldContainerPtr &objectP,
00430 BitVector whichField,
00431 UInt32 origin );
00432
00433 friend OSG_SYSTEMLIB_DLLMAPPING
00434 void endEditNotChangedCP(const FieldContainerPtr &objectP,
00435 BitVector whichField,
00436 UInt32 origin );
00437 };
00438
00439
00440
00444 class OSG_SYSTEMLIB_DLLMAPPING NullFieldContainerPtr :
00445 public FieldContainerPtr
00446 {
00447
00448
00449 public:
00450
00451 typedef FieldContainerPtr Inherited;
00452
00453
00457 NullFieldContainerPtr(void);
00458
00460
00464 ~NullFieldContainerPtr(void);
00465
00467
00468 };
00469
00470
00471
00472
00473
00474
00480 class OSG_SYSTEMLIB_DLLMAPPING ConstFieldContainerPtr :
00481 public FieldContainerPtrBase
00482 {
00483
00484
00485 public:
00486
00487 OSG_PROPERTY_DECL(ConstPointer);
00488
00489 typedef FieldContainer StoredObjectType;
00490 typedef FieldContainerPtr ObjectType;
00491
00492 typedef FieldContainerPtrBase Inherited;
00493
00494
00498 ConstFieldContainerPtr( void );
00499 ConstFieldContainerPtr(const NullFieldContainerPtr & );
00500 ConstFieldContainerPtr(const FieldContainerPtr &source);
00501 ConstFieldContainerPtr(const ConstFieldContainerPtr &source);
00502
00504
00508 ~ConstFieldContainerPtr(void);
00509
00511
00515 const FieldContainer *operator->(void);
00516 const FieldContainer *operator->(void) const;
00517
00518 const FieldContainer &operator *(void);
00519 const FieldContainer &operator *(void) const;
00520
00521 const FieldContainer *getCPtr (void);
00522 const FieldContainer *getCPtr (void) const;
00523
00525
00529 void operator =(const NullFieldContainerPtr & );
00530 void operator =(const FieldContainerPtr &source);
00531 void operator =(const ConstFieldContainerPtr &source);
00532
00534
00535
00536 protected:
00537
00538
00542 explicit ConstFieldContainerPtr(const FieldContainer &source);
00543 explicit ConstFieldContainerPtr(const FieldContainer *source);
00544
00545 ConstFieldContainerPtr(const FieldContainer *source,
00546 const UInt16 uiSize,
00547 const UInt16 uiParentEPos);
00548
00550
00551
00552 private:
00553 };
00554
00555
00556
00557
00558
00559
00560
00561
00566 template <class BasePtrTypeT, class FieldContainerTypeT>
00567 class FCPtr : public BasePtrTypeT
00568 {
00569
00570
00571 public:
00572
00573 OSG_PROPERTY_REQUIREMENT(BasePtrTypeT, Pointer);
00574
00575 typedef FieldContainerTypeT StoredObjectType;
00576 typedef FCPtr ObjectType;
00577
00578 typedef BasePtrTypeT Inherited;
00579
00580 typedef FCPtr<BasePtrTypeT,
00581 FieldContainerTypeT> Self;
00582
00583
00587 template <class InTypeT> inline
00588 static FCPtr dcast(const InTypeT oIn)
00589 {
00590 return FCPtr(
00591 (dynamic_cast<const typename FCPtr::StoredObjectType *>(
00592 oIn.getCPtr())),
00593 oIn.getContainerSize(),
00594 oIn.getParentFieldPos());
00595 }
00596
00598
00602 FCPtr( void );
00603 FCPtr(const NullFieldContainerPtr & );
00604 FCPtr(const FCPtr &source);
00605
00607
00611 ~FCPtr(void);
00612
00614
00618 FieldContainerTypeT *operator->(void);
00619 FieldContainerTypeT *operator->(void) const;
00620
00621 FieldContainerTypeT &operator *(void);
00622 FieldContainerTypeT &operator *(void) const;
00623
00624 FieldContainerTypeT *getCPtr (void);
00625 FieldContainerTypeT *getCPtr (void) const;
00626
00628
00632 void operator =(const FCPtr &source);
00633 void operator =(const NullFieldContainerPtr & );
00634
00636
00642 explicit FCPtr(const FieldContainerTypeT &source);
00643 explicit FCPtr(const FieldContainerTypeT *source);
00644
00646
00647
00648 protected:
00649
00650
00654 FCPtr(const FieldContainerTypeT *source,
00655 const UInt16 uiSize,
00656 const UInt16 uiParentPos);
00657
00659
00660
00661 private:
00662
00663 friend class FieldContainer;
00664 };
00665
00666
00667
00668
00669
00670
00671
00672
00677 template <class BasePtrTypeT, class FieldContainerTypeT>
00678 class ConstFCPtr : public BasePtrTypeT
00679 {
00680
00681
00682 public:
00683
00684 OSG_PROPERTY_REQUIREMENT(BasePtrTypeT, ConstPointer);
00685
00686 typedef FieldContainerTypeT StoredObjectType;
00687 typedef ConstFCPtr ObjectType;
00688
00689 typedef BasePtrTypeT Inherited;
00690
00691 typedef FCPtr<typename FieldContainerTypeT::Ptr::Inherited,
00692 FieldContainerTypeT > NCFCPtr;
00693
00694 typedef ConstFCPtr<BasePtrTypeT,
00695 FieldContainerTypeT> Self;
00696
00697
00701 ConstFCPtr( void );
00702 ConstFCPtr(const NullFieldContainerPtr & );
00703 ConstFCPtr(const NCFCPtr &source);
00704 ConstFCPtr(const ConstFCPtr &source);
00705
00707
00711 ~ConstFCPtr(void);
00712
00714
00718 const FieldContainerTypeT *operator->(void);
00719 const FieldContainerTypeT *operator->(void) const;
00720
00721 const FieldContainerTypeT &operator *(void);
00722 const FieldContainerTypeT &operator *(void) const;
00723
00724 const FieldContainerTypeT *getCPtr (void);
00725 const FieldContainerTypeT *getCPtr (void) const;
00726
00728
00732 void operator =(const NCFCPtr & );
00733 void operator =(const ConstFCPtr &source);
00734 void operator =(const NullFieldContainerPtr &source);
00735
00737
00743 explicit ConstFCPtr(const FieldContainerTypeT &source);
00744 explicit ConstFCPtr(const FieldContainerTypeT *source);
00745
00747
00748
00749 protected:
00750
00751
00755 ConstFCPtr(const FieldContainerTypeT *source,
00756 const UInt16 uiSize,
00757 const UInt16 uiParentPos);
00758
00760
00761
00762 private:
00763
00764 friend class FieldContainer;
00765 };
00766
00767
00772 class OSG_SYSTEMLIB_DLLMAPPING CPEditor
00773 {
00774
00775
00776 public:
00777
00778
00782 inline CPEditor(void);
00783
00784 inline CPEditor(const FieldContainerPtr fc,
00785 const BitVector mask = FieldBits::AllFields);
00786
00788
00792 inline ~CPEditor();
00793
00795
00796
00797 private:
00798
00799 FieldContainerPtr _fc;
00800 BitVector _mask;
00801 };
00802
00807 #define CPEdit(fc, mask) \
00808 ::OSG::CPEditor CPEdit_##fc((fc),(mask))
00809
00810 #define CPEditAll(fc) \
00811 ::OSG::CPEditor CPEdit_##fc((fc))
00812
00813 #ifdef __sgi
00814 #pragma reset woff 1375
00815 #endif
00816
00817 #ifdef OSG_LINUX_ICC
00818 #pragma warning( default : 444 )
00819 #endif
00820
00821 #ifdef __sgi
00822 #pragma reset woff 1424
00823 #endif
00824
00828 OSG_SYSTEMLIB_DLLMAPPING
00829 std::ostream &operator <<( std::ostream &os,
00830 const FieldContainerPtr &fc);
00831
00832 extern OSG_SYSTEMLIB_DLLMAPPING const NullFieldContainerPtr NullFC;
00833
00834 #define OSGNullFC OSG::NullFC
00835
00836 OSG_END_NAMESPACE
00837
00838 #define OSGFIELDCONTAINERPTR_HEADER_CVSID "@(#)$Id: $"
00839
00840 #endif