TuringSim
C++ framework to simulate abstract computing models
deterministicCounterListener.h
1 #pragma once
2 
3 #include <listener/listener.h>
4 #include <utils/uidDispenser.h>
5 
6 namespace TuringSim::Listener {
11  template<typename MachineType_>
12  class DeterministicCounterListener : public Listener<MachineType_, unsigned long long int> {
14  public:
15  using typename Listener_::IdType;
16  using typename Listener_::StateType;
17  using typename Listener_::MachineType;
18  using typename Listener_::StorageType;
19  using typename Listener_::TransitionType;
20  using typename Listener_::ApplyHelperType;
21 
22  static_assert(MachineType::IsDeterministic::value,
23  "Machine must be deterministic.");
24 
28 
33 
38 
44 
50 
53  virtual ~DeterministicCounterListener() override = default;
54 
58  virtual IdType getInitialId() override {
59  return initialId;
60  }
61 
62 #pragma clang diagnostic push
63 #pragma clang diagnostic ignored "-Wunused-parameter"
64 
70  virtual IdType registerPreTransition(const StateType& state, const StorageType& storage, const IdType& preId) override {
71  return dispenser();
72  }
73 
79  virtual void registerNoTransition(const IdType& id, const StateType& state, const StorageType& storage) override {
80  }
81 
90  virtual void registerPostTransition(const IdType& id, const StateType& state, const StorageType& storage, const TransitionType& transition, const ApplyHelperType& applyHelper, bool running) override {
91  numberOfTransitions++;
92  }
93 #pragma clang diagnostic pop
94 
98  unsigned long long int getNumberOfTransitions() const {
99  return numberOfTransitions;
100  }
101 
102  private:
104  unsigned long long int initialId = dispenser();
105  unsigned long long int numberOfTransitions{};
106  };
107 }
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::StorageType
MachineType::StorageType StorageType
The type of the memory of the machine.
Definition: listener.h:38
TuringSim::Listener::DeterministicCounterListener::~DeterministicCounterListener
virtual ~DeterministicCounterListener() override=default
The default destructor.
TuringSim::Listener::DeterministicCounterListener::registerPreTransition
virtual IdType registerPreTransition(const StateType &state, const StorageType &storage, const IdType &preId) override
Return a new unique identifier.
Definition: deterministicCounterListener.h:70
TuringSim::Listener::DeterministicCounterListener::registerNoTransition
virtual void registerNoTransition(const IdType &id, const StateType &state, const StorageType &storage) override
Called by a TuringSim::Runner::Runner when no transition matches. Does nothing.
Definition: deterministicCounterListener.h:79
TuringSim::Listener::DeterministicCounterListener::operator=
DeterministicCounterListener & operator=(const DeterministicCounterListener &other)=default
Copy assignment operator.
TuringSim::Listener::Listener
The base class for listeners.
Definition: listener.h:18
TuringSim::Listener::DeterministicCounterListener
A listener that counts transitions of deterministic machines.
Definition: deterministicCounterListener.h:12
TuringSim::Listener::DeterministicCounterListener::registerPostTransition
virtual void registerPostTransition(const IdType &id, const StateType &state, const StorageType &storage, const TransitionType &transition, const ApplyHelperType &applyHelper, bool running) override
Called by a TuringSim::Runner::Runner after executing a transition. Increments the number of transiti...
Definition: deterministicCounterListener.h:90
TuringSim::Listener::DeterministicCounterListener::operator=
DeterministicCounterListener & operator=(DeterministicCounterListener &&other)=default
Move assignment operator.
TuringSim::Listener::DeterministicCounterListener::DeterministicCounterListener
DeterministicCounterListener()=default
Default constructor.
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::IdType
unsigned long long int IdType
The type of identifiers of the listener.
Definition: listener.h:23
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::ApplyHelperType
MachineType::ApplyHelperType ApplyHelperType
The type of the transitions apply helper of the machine.
Definition: listener.h:48
TuringSim::Listener::DeterministicCounterListener::getNumberOfTransitions
unsigned long long int getNumberOfTransitions() const
Gets the number of transitions executed so far.
Definition: deterministicCounterListener.h:98
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::MachineType
MachineType_ MachineType
The type of the listened machine.
Definition: listener.h:28
TuringSim::Listener::DeterministicCounterListener::DeterministicCounterListener
DeterministicCounterListener(const DeterministicCounterListener &other)=default
Copy constructor.
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::TransitionType
MachineType::TransitionType TransitionType
The type of the transitions of the machine.
Definition: listener.h:43
TuringSim::Listener
The namespace of runner listener, used to follow the execution of a Machine.
Definition: deterministicCounterListener.h:6
TuringSim::Listener::Listener< MachineType_, unsigned long long int >::StateType
MachineType::StateType StateType
The type of states of the machine.
Definition: listener.h:33
TuringSim::Utils::UidDispenser< unsigned long long int >
TuringSim::Listener::DeterministicCounterListener::getInitialId
virtual IdType getInitialId() override
Get the initial identifier, before any transition.
Definition: deterministicCounterListener.h:58
TuringSim::Listener::DeterministicCounterListener::DeterministicCounterListener
DeterministicCounterListener(DeterministicCounterListener &&other)=default
Move constructor.