fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FieldContainer / Misc / OSGSceneGraphUtils.inl
blob1cd4f14defdff847798149048e60de9c0173db54
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 namespace
43     template<class CoreT>
44     struct CoreCollector
45     {
46         std::vector<CoreT *> &_vResultStore;
48         CoreCollector(std::vector<CoreT *> &vResultStore);
49         ~CoreCollector(void);
51         Action::ResultE travEnter(Node * const pRoot);
53       private:
54         
55         CoreCollector(const CoreCollector &source);
56         void operator =(const CoreCollector &source);
57     };
59     template <class CoreT> inline
60     CoreCollector<CoreT>::CoreCollector(std::vector<CoreT *> &vResultStore) :
61         _vResultStore(vResultStore)
62     {
63     }
64     
65     template <class CoreT> inline
66     CoreCollector<CoreT>::~CoreCollector(void)
67     {
68     }
70     template <class CoreT> inline
71     Action::ResultE CoreCollector<CoreT>::travEnter(Node * const pRoot)
72     {
73         if(pRoot != NULL)
74         {
75             CoreT *pTypedCore = dynamic_cast<CoreT *>(pRoot->getCore());
77             if(pTypedCore != NULL)
78             {
79                 _vResultStore.push_back(pTypedCore);
80             }
81         }
83         return Action::Continue;
84     }
87 template<class CoreT> inline
88 void collectCoresByType(Node                 *pRoot, 
89                         std::vector<CoreT *> &result)
91     CoreCollector<CoreT> oCoreColl(result);
93     traverse(pRoot, boost::bind(&CoreCollector<CoreT>::travEnter,
94                                 &oCoreColl,
95                                 _1                              ));
98 OSG_END_NAMESPACE