i6engine  1.0
ComponentFactory.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MODULES_COMPONENTFACTORY_H__
26 #define __I6ENGINE_MODULES_COMPONENTFACTORY_H__
27 
28 #include <map>
29 #include <string>
30 
32 #include "i6engine/utils/weakPtr.h"
33 
35 
36 #include "boost/function.hpp"
37 
38 namespace i6e {
39 namespace api {
40  class Component;
41  class GameObject;
42 
43  typedef utils::sharedPtr<Component, Component> ComPtr;
44  typedef utils::weakPtr<GameObject> WeakGOPtr;
45 
50  typedef boost::function<ComPtr(const int64_t, const attributeMap &)> createGOCCallback;
51 } /* namespace api */
52 
53 namespace modules {
54 
61  public:
69 
74 
83  void registerCTemplate(const std::string & GOCType, const api::createGOCCallback & fn);
84 
93  api::ComPtr createGOC(int64_t id, const std::string & GOCType, const api::attributeMap & params, const api::WeakGOPtr & owner) const;
94 
99  void enableTicking(bool allowTicking) {
100  _tickingAllowed = allowTicking;
101  }
102 
103  private:
104  typedef std::map<std::string, api::createGOCCallback> callbackMap;
105 
111  callbackMap _callbacks;
112 
116  bool _tickingAllowed;
117 
121  ComponentFactory(const ComponentFactory &) = delete;
122 
126  ComponentFactory & operator=(const ComponentFactory &) = delete;
127 
129  };
130 
131 } /* namespace modules */
132 } /* namespace i6e */
133 
134 #endif /* __I6ENGINE_MODULES_COMPONENTFACTORY_H__ */
135 
void registerCTemplate(const std::string &GOCType, const api::createGOCCallback &fn)
register a new Template After a template is registered you can easily create new objects of that type...
void enableTicking(bool allowTicking)
sets whether newly created Components shall be allowed to tick or not default value is true ...
Factory in order to create Component.
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
ComponentFactory()
used to easily create special Components
utils::weakPtr< GameObject > WeakGOPtr
Definition: Component.h:57
~ComponentFactory()
Destructor for ComponentsFactory. Clears the map of Create methods.
#define ASSERT_THREAD_SAFETY_HEADER
A shared pointer counting references and adds objects being not referenced any more to an internal li...
Definition: sharedPtr.h:50
api::ComPtr createGOC(int64_t id, const std::string &GOCType, const api::attributeMap &params, const api::WeakGOPtr &owner) const
Creates a new Component.
boost::function< ComPtr(const int64_t, const attributeMap &)> createGOCCallback
Definition: Component.h:58
utils::sharedPtr< Component, Component > ComPtr
Definition: Component.h:52