fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBElementFactory.h
bloba51ad393acf42c246146dd2924f22e718288d815
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2006 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 #ifndef _OSGOSBELEMENTFACTORY_H_
40 #define _OSGOSBELEMENTFACTORY_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGConfig.h"
46 #include "OSGFileIODef.h"
47 #include "OSGSingletonHolder.h"
48 #include "OSGOSBElementBase.h"
50 #include <map>
51 #include <string>
53 OSG_BEGIN_NAMESPACE
55 class OSBElementBase;
56 class OSBRootElement;
58 /*! \ingroup GrpFileIOOSB
59 \nohierarchy
62 struct OSG_FILEIO_DLLMAPPING OSBElementCreatorBase
64 /*---------------------------------------------------------------------*/
65 /*! \name Destructor */
66 /*! \{ */
68 virtual ~OSBElementCreatorBase(void);
70 /*! \} */
71 /*---------------------------------------------------------------------*/
72 /*! \name Create/Destroy */
73 /*! \{ */
75 virtual OSBElementBase *create(OSBRootElement *root) = 0;
77 /*! \} */
78 /*---------------------------------------------------------------------*/
81 /*! \ingroup GrpFileIOOSB
82 \nohierarchy
85 template <class ElementTypeT>
86 struct OSBElementCreator : public OSBElementCreatorBase
88 /*---------------------------------------------------------------------*/
89 /*! \name Types */
90 /*! \{ */
92 typedef ElementTypeT ElementType;
94 /*! \} */
95 /*---------------------------------------------------------------------*/
96 /*! \name Destructor */
97 /*! \{ */
99 virtual ~OSBElementCreator(void);
101 /*! \} */
102 /*---------------------------------------------------------------------*/
103 /*! \name Create/Destroy */
104 /*! \{ */
106 virtual OSBElementBase *create(OSBRootElement *root);
108 /*! \} */
109 /*---------------------------------------------------------------------*/
112 /*! \ingroup GrpFileIOOSB
113 \nohierarchy
116 class OSG_FILEIO_DLLMAPPING OSBElementFactorySingleton
118 /*========================== PUBLIC =================================*/
119 public:
121 /*---------------------------------------------------------------------*/
122 /*! \name Types */
123 /*! \{ */
125 typedef std::map<std::string, OSBElementCreatorBase *> RegistryMap;
126 typedef RegistryMap::iterator RegistryMapIt;
127 typedef RegistryMap::const_iterator RegistryMapConstIt;
129 /*! \} */
130 /*---------------------------------------------------------------------*/
131 /*! \name Registration */
132 /*! \{ */
134 bool registerElement (const std::string &typeName,
135 OSBElementCreatorBase *creator );
136 bool unregisterElement(const std::string &typeName );
138 bool registerDefault ( OSBElementCreatorBase *creator );
139 bool unregisterDefault( void );
141 const RegistryMap &getRegistryMap (void) const;
142 RegistryMap &editRegistryMap(void);
144 /*! \} */
145 /*---------------------------------------------------------------------*/
146 /*! \name Acquire/Release */
147 /*! \{ */
149 inline OSBElementBase *acquire(const std::string &typeName,
150 OSBRootElement *root );
151 inline void release( OSBElementBase *element );
153 /*! \} */
154 /*========================== PRIVATE ================================*/
155 private:
157 /*---------------------------------------------------------------------*/
158 /*! \name Constructor */
159 /*! \{ */
161 OSBElementFactorySingleton(void);
163 /*! \} */
164 /*---------------------------------------------------------------------*/
165 /*! \name Destructor */
166 /*! \{ */
168 ~OSBElementFactorySingleton(void);
170 /*! \} */
171 /*---------------------------------------------------------------------*/
173 template <class SingletonT>
174 friend class SingletonHolder;
176 RegistryMap _registry;
177 OSBElementCreatorBase *_defaultCreator;
179 OSBElementFactorySingleton(const OSBElementFactorySingleton &other);
180 void operator =(const OSBElementFactorySingleton &rhs);
183 #if defined(WIN32)
184 OSG_FILEIO_EXPIMP_TMPL
185 template class OSG_FILEIO_DLLMAPPING SingletonHolder<OSBElementFactorySingleton>;
186 #endif
188 /*! \ingroup GrpFileIOOSB
191 typedef SingletonHolder<OSBElementFactorySingleton> OSBElementFactory;
193 OSG_END_NAMESPACE
195 #include "OSGOSBElementFactory.inl"
197 #endif /* _OSGOSBELEMENTFACTORY_H_ */