Atoms Crowd  4.1.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 }
Atoms::StateMachines::addStateMachine
void addStateMachine(const std::string &name, const StateMachine &stateMachine, bool replace=true)
Add a state machine to the map.
Atoms::StateMachines::instance
static StateMachines & instance()
Singleton access.
Atoms::StateMachines::stateMachineExists
bool stateMachineExists(const std::string &name)
Checks if a state machine exists.
Atoms::StateMachines::removeStateMachine
void removeStateMachine(const std::string &name)
Removes a state machine from the map.
Atoms::StateMachines
Container for all state machines.
Definition: StateMachines.h:21
Atoms
Atoms namespace.
Definition: Agent.h:28
Atoms::StateMachines::stateMachine
AtomsPtr< StateMachine > stateMachine(const std::string &typeName)
Gets a state machine by name.
Atoms::StateMachines::clear
void clear()
Removes all state machines.
Atoms::StateMachines::numStateMachines
unsigned int numStateMachines()
Gets the number fo state machines.
Atoms::StateMachine
State machine.
Definition: StateMachine.h:27
Atoms::StateMachines::stateMachineNames
std::vector< std::string > stateMachineNames()
Gets all state machines names.