changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / FieldContainer / Mixins / OSGDataSlotMixin.inl
blob2093b44c252feac53cc452ce320067a5ab17542d
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2003 by the OpenSG Forum                          *
6  *                                                                           *
7  *                            www.opensg.org                                 *
8  *                                                                           *
9  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
10  *                                                                           *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13  *                                License                                    *
14  *                                                                           *
15  * This library is free software; you can redistribute it and/or modify it   *
16  * under the terms of the GNU Library General Public License as published    *
17  * by the Free Software Foundation, version 2.                               *
18  *                                                                           *
19  * This library is distributed in the hope that it will be useful, but       *
20  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
22  * Library General Public License for more details.                          *
23  *                                                                           *
24  * You should have received a copy of the GNU Library General Public         *
25  * License along with this library; if not, write to the Free Software       *
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
27  *                                                                           *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30  *                                Changes                                    *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35  *                                                                           *
36  *                                                                           *
37 \*---------------------------------------------------------------------------*/
39 OSG_BEGIN_NAMESPACE
41 template <class ParentT>
42 template <class ValuePtr>  inline
43 ValuePtr DataSlotMixin<ParentT>::getData(Int32 iSlotId) const
45     ValuePtr returnValue = NULL;
47     if(iSlotId >= 0 && static_cast<UInt32>(iSlotId) < _mfData.size())
48     {
49         StoredType pTmp = _mfData[iSlotId];
51         returnValue = dynamic_cast<ValuePtr>(pTmp);
52     }
54     return returnValue;
57 template <class ParentT> inline
58 void DataSlotMixin<ParentT>::setData(StoredType pData, Int32 iSlotId)
60     if(iSlotId < 0)
61         return;
63     if(_mfData.size() <= static_cast<UInt32>(iSlotId))
64     {
65         _mfData.resize(iSlotId + 1, NULL);
66     }
68     _mfData.replace(iSlotId, pData);
71 template <class ParentT> inline
72 void DataSlotMixin<ParentT>::dumpStore(void)
74     for(UInt32 i = 0; i < _mfData.size(); ++i)
75     {
76         fprintf(stderr, "(%d) : ", i);
77         Desc::dumpElement(_mfData[i]);
78         fprintf(stderr, "\n");
79     }
82 template <class ParentT> inline
83 void DataSlotMixin<ParentT>::clearData(FieldContainer    *pContainer, 
84                                        ConstFieldMaskArg  whichField,
85                                        Int32              iSlotId   )
87     fprintf(stderr, "Clear Data %p %d\n",
88             pContainer,
89             iSlotId);
91     if(iSlotId < 0)
92         return;
94     if(_mfData.size() > static_cast<UInt32>(iSlotId))
95     {
96         _mfData.replace(iSlotId, NULL);
97     }
99     typename DestroyFunctorStore::iterator       cfIt = 
100         _mfDestroyedFunctors.begin();
102     typename DestroyFunctorStore::const_iterator cfEnd= 
103         _mfDestroyedFunctors.end();
105     while(cfIt != cfEnd)
106     {
107         if((*cfIt).second == pContainer)
108         {
109             cfIt  = _mfDestroyedFunctors.erase(cfIt);
110             cfEnd = _mfDestroyedFunctors.end();
111         }
112         else
113         {
114             ++cfIt;
115         }
116     }
119 template <class ParentT> inline
120 DataSlotMixin<ParentT>::DataSlotMixin(void) :
121      Inherited          (),
122     _mfData             (),
123     _mfDestroyedFunctors()
127 template <class ParentT> inline
128 DataSlotMixin<ParentT>::DataSlotMixin(const DataSlotMixin &source) :
129      Inherited          (source),
130     _mfData             (      ),
131     _mfDestroyedFunctors(      )
135 template <class ParentT> inline
136 void DataSlotMixin<ParentT>::addDestroyedFunctorFor(      DestroyFunctor  func,
137                                                     const FieldContainer *pCnt)
139     DestroyedFunctorElem tmpElem;
141     tmpElem.first  = func;
142     tmpElem.second = pCnt;
144     _mfDestroyedFunctors.push_back(tmpElem);
147 template <class ParentT> inline
148 DataSlotMixin<ParentT>::~DataSlotMixin(void)
150     for(UInt32 i = 0; i < _mfData.size(); ++i)
151     {
152         _mfData.replace(i, NULL);
153     }
155     for(UInt32 i = 0; i < _mfDestroyedFunctors.size(); ++i)
156     {
157         fprintf(stderr, "DF (%d) (%p)\n",
158                 i, this);
160         (_mfDestroyedFunctors[i].first)(this);
161     }
164 OSG_END_NAMESPACE