Atoms Crowd  4.1.0
BehaviourFactory.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <Atoms/Globals.h>
11 #include <AtomsCore/Globals.h>
12 #include <Atoms/BehaviourTree/Behaviour.h>
13 #include <map>
14 
15 
16 namespace Atoms
17 {
19 
21  class ATOMS_EXPORT BehaviourFactory
22  {
23  public:
24 
25  enum ModuleType
26  {
27  kNone = -1,
28  kNative = 0,
29  kScript = 1
30  };
31 
32  typedef Behaviour* (*creatorFn)();
33 
36 
38 
42  Behaviour* createBehaviour(const std::string& name);
43 
45 
51  bool registerBehaviour(const std::string& moduleName, creatorFn func, unsigned int moduleType = kNative, bool replace = false, const std::string category = "");
52 
54 
58  bool deregisterBehaviour(const std::string& name);
59 
61 
64  std::vector<std::string> getRegisteredBehaviours();
65 
67 
70  const std::string getBehaviourCategory(const std::string& moduleName);
71 
73 
77  bool isRegistered(const std::string& name);
78 
80  void clear();
81 
83  short moduleType(const std::string& name);
84 
85  private:
86 
89 
92 
95 
97  BehaviourFactory& operator=(const BehaviourFactory&);
98 
99  private:
100 
102 
105  std::map<std::string, creatorFn> m_factoryMap;
106 
107  std::map<std::string, short> m_moduleTypes;
108 
109  std::map<std::string, std::string> m_moduleCategories;
110  };
111 }
Atoms::BehaviourFactory::instance
static BehaviourFactory & instance()
Singleton access.
Atoms::BehaviourFactory::clear
void clear()
Clear factory.
Atoms::BehaviourFactory::moduleType
short moduleType(const std::string &name)
Gets the module type.
Atoms::BehaviourFactory::getBehaviourCategory
const std::string getBehaviourCategory(const std::string &moduleName)
Gets a registered behaviour category.
Atoms::BehaviourFactory::registerBehaviour
bool registerBehaviour(const std::string &moduleName, creatorFn func, unsigned int moduleType=kNative, bool replace=false, const std::string category="")
Registers a behaviour in the factory.
Atoms
Atoms namespace.
Definition: Agent.h:28
Atoms::BehaviourFactory::isRegistered
bool isRegistered(const std::string &name)
Check if a behaviour is registered.
Atoms::BehaviourFactory
Behaviour factory.
Definition: BehaviourFactory.h:22
Atoms::BehaviourFactory::createBehaviour
Behaviour * createBehaviour(const std::string &name)
Creates a behaviour.
Atoms::BehaviourFactory::getRegisteredBehaviours
std::vector< std::string > getRegisteredBehaviours()
Gets all registered behaviour modules.
Atoms::BehaviourFactory::deregisterBehaviour
bool deregisterBehaviour(const std::string &name)
Deregisters a Behaviour type from the factory.
Atoms::Behaviour
Definition: Behaviour.h:21