Atoms Crowd  7.0.0
StateMachines.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 <Atoms/StateMachine.h>
12 #include <map>
13 #include <vector>
14 #include <mutex>
15 #include <functional>
16 
17 namespace Atoms
18 {
20  class ATOMS_EXPORT StateMachines
21  {
22  public:
23 
26 
28 
32  AtomsPtr<StateMachine> stateMachine(const std::string& typeName);
33 
35 
39  void addStateMachine(const std::string& name, const StateMachine& stateMachine, bool replace = true);
40 
42 
45  void removeStateMachine(const std::string& name);
46 
48 
51  std::vector<std::string> stateMachineNames();
52 
54 
58  bool stateMachineExists(const std::string& name);
59 
61  unsigned int numStateMachines();
62 
64  void clear();
65 
66  void registerLoaderCallback(std::function<StateMachine(const char*)>& callback);
67 
68  private:
69 
71  StateMachines();
72 
75 
77  ~StateMachines();
78 
80  StateMachines& operator=(const StateMachines&);
81 
82  typedef std::map<std::string, AtomsPtr<StateMachine>> StateMachineMap;
83 
84  StateMachineMap m_stateMachineMap;
85 
86  std::function<StateMachine(const char*)> m_loaderCallback;
87 
88  mutable std::mutex m_mutex;
89  };
90 }
State machine.
Definition: StateMachine.h:27
Container for all state machines.
Definition: StateMachines.h:21
void removeStateMachine(const std::string &name)
Removes a state machine from the map.
std::vector< std::string > stateMachineNames()
Gets all state machines names.
unsigned int numStateMachines()
Gets the number fo state machines.
void addStateMachine(const std::string &name, const StateMachine &stateMachine, bool replace=true)
Add a state machine to the map.
static StateMachines & instance()
Singleton access.
void clear()
Removes all state machines.
bool stateMachineExists(const std::string &name)
Checks if a state machine exists.
AtomsPtr< StateMachine > stateMachine(const std::string &typeName)
Gets a state machine by name.
Atoms namespace.
Definition: Agent.h:29