Atoms Crowd  7.0.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 }
Behaviour factory.
Definition: BehaviourFactory.h:22
bool isRegistered(const std::string &name)
Check if a behaviour is registered.
Behaviour * createBehaviour(const std::string &name)
Creates a behaviour.
std::vector< std::string > getRegisteredBehaviours()
Gets all registered behaviour modules.
void clear()
Clear factory.
bool deregisterBehaviour(const std::string &name)
Deregisters a Behaviour type from the factory.
static BehaviourFactory & instance()
Singleton access.
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.
const std::string getBehaviourCategory(const std::string &moduleName)
Gets a registered behaviour category.
short moduleType(const std::string &name)
Gets the module type.
Definition: Behaviour.h:21
Atoms namespace.
Definition: Agent.h:29