Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ObjectFactory.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2006-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Lars Hagström / stlrha
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 
25 #ifndef __DOTS_OBJECT_FACTORY_H__
26 #define __DOTS_OBJECT_FACTORY_H__
27 
28 #include <boost/noncopyable.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/thread/once.hpp>
33 
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4275)
37 #endif
38 
39 namespace Safir
40 {
41 namespace Dob
42 {
43 namespace Typesystem
44 {
45  //forward declaration since we would rather not include dots_object.h (Object.cpp includes this file...)
46  class Object;
47 
49  typedef boost::shared_ptr<Object> ObjectPtr;
50 
59  : private boost::noncopyable
60  {
61  public:
67  static ObjectFactory & Instance();
68 
79  ObjectPtr CreateObject(const TypeId typeId) const;
80 
92  typedef ObjectPtr (*CreateObjectCallback)(char const * const blob);
93 
100  bool RegisterClass(const TypeId typeId, CreateObjectCallback createFunction);
101 
124  ObjectPtr CreateObject(char const * const blob) const;
125 
128  private:
129  ObjectFactory();
130  ~ObjectFactory();
131 
132 #ifdef _MSC_VER
133 #pragma warning (push)
134 #pragma warning (disable: 4251) // warning C4251: 'Safir::Dob::Typesystem::ObjectFactory::m_CallbackMap' : class 'stdext::hash_map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'Safir::Dob::Typesystem::ObjectFactory'
135 #endif
136 
137  typedef unordered_map<TypeId,CreateObjectCallback> CallbackMap;
138  CallbackMap m_CallbackMap;
139 
140 #ifdef _MSC_VER
141 #pragma warning (pop)
142 #endif
143 
150  struct SingletonHelper
151  {
152  private:
154 
155  static ObjectFactory& Instance();
156  static boost::once_flag m_onceFlag;
157  };
158  };
159 }
160 }
161 }
162 
163 #ifdef _MSC_VER
164 #pragma warning(pop)
165 #endif
166 
167 #endif
168 
DotsC_TypeId TypeId
A unique type identifier.
Definition: Defs.h:219
boost::shared_ptr< Object > ObjectPtr
A smart pointer to an Object.
Definition: Object.h:41
This class is an object factory for all automatically generated DOB classes.
Definition: ObjectFactory.h:58
static ObjectFactory & Instance()
Get the instance of the singleton.
#define DOTS_CPP_API
Definition: Defs.h:33