1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2006 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 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGOSBELEMENTFACTORY_H_
40 #define _OSGOSBELEMENTFACTORY_H_
45 #include "OSGConfig.h"
46 #include "OSGFileIODef.h"
47 #include "OSGSingletonHolder.h"
48 #include "OSGOSBElementBase.h"
58 /*! \ingroup GrpFileIOOSB
62 struct OSG_FILEIO_DLLMAPPING OSBElementCreatorBase
64 /*---------------------------------------------------------------------*/
65 /*! \name Destructor */
68 virtual ~OSBElementCreatorBase(void);
71 /*---------------------------------------------------------------------*/
72 /*! \name Create/Destroy */
75 virtual OSBElementBase
*create(OSBRootElement
*root
) = 0;
78 /*---------------------------------------------------------------------*/
81 /*! \ingroup GrpFileIOOSB
85 template <class ElementTypeT
>
86 struct OSBElementCreator
: public OSBElementCreatorBase
88 /*---------------------------------------------------------------------*/
92 typedef ElementTypeT ElementType
;
95 /*---------------------------------------------------------------------*/
96 /*! \name Destructor */
99 virtual ~OSBElementCreator(void);
102 /*---------------------------------------------------------------------*/
103 /*! \name Create/Destroy */
106 virtual OSBElementBase
*create(OSBRootElement
*root
);
109 /*---------------------------------------------------------------------*/
112 /*! \ingroup GrpFileIOOSB
116 class OSG_FILEIO_DLLMAPPING OSBElementFactorySingleton
118 /*========================== PUBLIC =================================*/
121 /*---------------------------------------------------------------------*/
125 typedef std::map
<std::string
, OSBElementCreatorBase
*> RegistryMap
;
126 typedef RegistryMap::iterator RegistryMapIt
;
127 typedef RegistryMap::const_iterator RegistryMapConstIt
;
130 /*---------------------------------------------------------------------*/
131 /*! \name Registration */
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);
145 /*---------------------------------------------------------------------*/
146 /*! \name Acquire/Release */
149 inline OSBElementBase
*acquire(const std::string
&typeName
,
150 OSBRootElement
*root
);
151 inline void release( OSBElementBase
*element
);
154 /*========================== PRIVATE ================================*/
157 /*---------------------------------------------------------------------*/
158 /*! \name Constructor */
161 OSBElementFactorySingleton(void);
164 /*---------------------------------------------------------------------*/
165 /*! \name Destructor */
168 ~OSBElementFactorySingleton(void);
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
);
184 OSG_FILEIO_EXPIMP_TMPL
185 template class OSG_FILEIO_DLLMAPPING SingletonHolder
<OSBElementFactorySingleton
>;
188 /*! \ingroup GrpFileIOOSB
191 typedef SingletonHolder
<OSBElementFactorySingleton
> OSBElementFactory
;
195 #include "OSGOSBElementFactory.inl"
197 #endif /* _OSGOSBELEMENTFACTORY_H_ */