1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
41 /*! \class ChildAccessHandler
43 Access handler for child pointer fields.
44 This class handles all reference counting and child/parent linking
45 operations for child pointer fields. The fields only call the respective
46 members when an operation on one of their values is performed.
49 /*-------------------------------------------------------------------------*/
52 template<typename RefCountPolicyT> inline
53 typename ChildAccessHandler<RefCountPolicyT>::SFieldType *
54 ChildAccessHandler<RefCountPolicyT>::dcastSField(
55 SFieldBaseType * const pSField)
57 return static_cast<SFieldType *>(pSField);
60 template<typename RefCountPolicyT> inline
61 typename ChildAccessHandler<RefCountPolicyT>::MFieldType *
62 ChildAccessHandler<RefCountPolicyT>::dcastMField(
63 MFieldBaseType * const pMField)
65 return static_cast<MFieldType *>(pMField);
68 /*-------------------------------------------------------------------------*/
71 template<typename RefCountPolicyT> inline
72 void ChildAccessHandler<RefCountPolicyT>::linkParent(
73 FieldContainer * const pParent,
74 UInt16 const childFieldId,
75 FieldContainer * const pChild,
76 UInt16 const parentFieldId)
78 pChild->linkParent(pParent, childFieldId, parentFieldId);
81 template<typename RefCountPolicyT> inline
82 void ChildAccessHandler<RefCountPolicyT>::unlinkParent(
83 FieldContainer * const pParent,
84 FieldContainer * const pChild,
85 UInt16 const parentFieldId)
87 pChild->unlinkParent(pParent, parentFieldId);
90 /*-------------------------------------------------------------------------*/
93 template<typename RefCountPolicyT> inline
94 void ChildAccessHandler<RefCountPolicyT>::onAdd(
95 SFieldBaseType * const pSField,
96 FieldContainer * const pObj )
100 RefCountPolicyType::addRef(pObj);
102 linkParent(dcastSField(pSField)->getEnclosingObject(),
103 dcastSField(pSField)->getChildFieldId (),
105 dcastSField(pSField)->getParentFieldId () );
109 template<typename RefCountPolicyT> inline
110 void ChildAccessHandler<RefCountPolicyT>::onAdd(
111 MFieldBaseType * const pMField,
112 FieldContainer * const pObj )
116 RefCountPolicyType::addRef(pObj);
118 linkParent(dcastMField(pMField)->getEnclosingObject(),
119 dcastMField(pMField)->getChildFieldId (),
121 dcastMField(pMField)->getParentFieldId () );
125 template<typename RefCountPolicyT> inline
126 void ChildAccessHandler<RefCountPolicyT>::onSub(
127 SFieldBaseType * const pSField,
128 FieldContainer * const pObj )
132 unlinkParent(dcastSField(pSField)->getEnclosingObject(),
134 dcastSField(pSField)->getParentFieldId () );
136 RefCountPolicyType::subRef(pObj);
140 template<typename RefCountPolicyT> inline
141 void ChildAccessHandler<RefCountPolicyT>::onSub(
142 MFieldBaseType * const pMField,
143 FieldContainer * const pObj )
147 unlinkParent(dcastMField(pMField)->getEnclosingObject(),
149 dcastMField(pMField)->getParentFieldId () );
151 RefCountPolicyType::subRef(pObj);
155 template<typename RefCountPolicyT> inline
156 void ChildAccessHandler<RefCountPolicyT>::onReplace(
157 SFieldBaseType * const pSField,
158 FieldContainer * const pOldObj,
159 FieldContainer * const pNewObj)
161 RefCountPolicyType::addRef(pNewObj);
165 unlinkParent(dcastSField(pSField)->getEnclosingObject(),
167 dcastSField(pSField)->getParentFieldId ());
169 RefCountPolicyType::subRef(pOldObj);
174 linkParent(dcastSField(pSField)->getEnclosingObject(),
175 dcastSField(pSField)->getChildFieldId (),
177 dcastSField(pSField)->getParentFieldId ());
181 template<typename RefCountPolicyT> inline
182 void ChildAccessHandler<RefCountPolicyT>::onReplace(
183 MFieldBaseType * const pMField,
184 FieldContainer * const pOldObj,
185 FieldContainer * const pNewObj)
187 RefCountPolicyType::addRef(pNewObj);
191 unlinkParent(dcastMField(pMField)->getEnclosingObject(),
193 dcastMField(pMField)->getParentFieldId() );
195 RefCountPolicyType::subRef(pOldObj);
200 linkParent(dcastMField(pMField)->getEnclosingObject(),
201 dcastMField(pMField)->getChildFieldId (),
203 dcastMField(pMField)->getParentFieldId ());
207 /*-------------------------------------------------------------------------*/
208 /* Sync Access Handling */
210 template<typename RefCountPolicyT> inline
211 void ChildAccessHandler<RefCountPolicyT>::onSyncAdd(
212 SFieldBaseType * const,
213 FieldContainer * const pObj)
215 RefCountPolicyType::addRef(pObj);
218 template<typename RefCountPolicyT> inline
219 void ChildAccessHandler<RefCountPolicyT>::onSyncAdd(
220 MFieldBaseType * const,
221 FieldContainer * const pObj)
223 RefCountPolicyType::addRef(pObj);
226 template<typename RefCountPolicyT> inline
227 void ChildAccessHandler<RefCountPolicyT>::onSyncSub(
228 SFieldBaseType * const,
229 FieldContainer * const pObj)
233 Thread::getCurrentChangeList()->addDelayedSubRef<
234 RefCountPolicyT>(pObj);
238 template<typename RefCountPolicyT> inline
239 void ChildAccessHandler<RefCountPolicyT>::onSyncSub(
240 MFieldBaseType * const,
241 FieldContainer * const pObj)
245 Thread::getCurrentChangeList()->addDelayedSubRef<
246 RefCountPolicyT>(pObj);
250 template<typename RefCountPolicyT> inline
251 void ChildAccessHandler<RefCountPolicyT>::onSyncReplace(
252 SFieldBaseType * const pSField,
253 FieldContainer * const pOldObj,
254 FieldContainer * const pNewObj)
256 onSyncAdd(pSField, pNewObj);
257 onSyncSub(pSField, pOldObj);
260 template<typename RefCountPolicyT> inline
261 void ChildAccessHandler<RefCountPolicyT>::onSyncReplace(
262 MFieldBaseType * const pMField,
263 FieldContainer * const pOldObj,
264 FieldContainer * const pNewObj)
266 onSyncAdd(pMField, pNewObj);
267 onSyncSub(pMField, pOldObj);