Symmetri
Loading...
Searching...
No Matches
symmetri.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <set>
6
7#include "symmetri/callback.h"
8#include "symmetri/tasks.h"
9#include "symmetri/types.h"
10
11namespace symmetri {
12
19struct Petri;
20
27class PetriNet final {
28 public:
40 PetriNet(const std::set<std::string> &petri_net_xmls,
41 const std::string &case_id, std::shared_ptr<TaskSystem> threadpool,
42 const Marking &goal_marking = {},
43 const PriorityTable &priorities = {});
44
55 PetriNet(const Net &net, const std::string &case_id,
56 std::shared_ptr<TaskSystem> threadpool,
57 const Marking &initial_marking, const Marking &goal_marking = {},
58 const PriorityTable &priorities = {});
59
69 std::function<void()> getInputTransitionHandle(
70 const std::string &transition) const noexcept;
71
79 void registerCallback(const std::string &transition,
80 Callback &&callback) const noexcept;
81
91 template <typename T, typename... Args>
92 void registerCallbackInPlace(const std::string &transition,
93 Args &&...args) const noexcept {
94 if (impl == nullptr || s.empty()) {
95 return;
96 }
97 s.emplace_back(identity<T>{}, std::forward<Args>(args)...);
98 *getCallbackItr(transition) = std::move(s.back());
99 s.pop_back(); }
100
107 Marking getMarking() const noexcept;
108
118 bool reuseApplication(const std::string &case_id);
119
120 friend Token(symmetri::fire)(const PetriNet &);
121 friend void(symmetri::cancel)(const PetriNet &);
122 friend void(symmetri::pause)(const PetriNet &);
123 friend void(symmetri::resume)(const PetriNet &);
124 friend Eventlog(symmetri::getLog)(const PetriNet &);
125
126 private:
134 std::vector<Callback>::iterator getCallbackItr(
135 const std::string &transition_name) const;
136
137 const std::shared_ptr<Petri> impl;
139 std::vector<Callback> &s;
140};
141
142} // namespace symmetri
Token fire(const T &callback)
Generates a Token based on what kind of information the Callback returns.
Definition callback.h:65
Eventlog getLog(const T &)
Get the Log object. By default it returns an empty vector.
Definition callback.h:83
void resume(const T &)
Templates a resume action for a Callback. By default it does nothing and not resume the Callback.
Definition callback.h:53
void cancel(const T &)
The default cancel implementation is naive. It only returns a user-exit state and does nothing to the...
Definition callback.h:35
void pause(const T &)
Implements a pause action for a Callback. By default it does nothing and not pause the Callback.
Definition callback.h:44
Callback is a wrapper around any type that you to tie to a transition. Typically this is an invokable...
Definition callback.h:104
PetriNet exposes the possible constructors to create PetriNets. It also allows the user to register a...
Definition symmetri.h:27
Marking getMarking() const noexcept
Get the Marking object. This function is thread-safe and be called during PetriNet execution.
Definition symmetri.cpp:72
std::function< void()> getInputTransitionHandle(const std::string &transition) const noexcept
By registering a input transition you get a handle to manually force a transition to fire....
Definition symmetri.cpp:39
PetriNet(const std::set< std::string > &petri_net_xmls, const std::string &case_id, std::shared_ptr< TaskSystem > threadpool, const Marking &goal_marking={}, const PriorityTable &priorities={})
Construct a new PetriNet object from a set of paths to PNML- or GRML-files. Since PNML-files do not h...
Definition symmetri.cpp:11
bool reuseApplication(const std::string &case_id)
reuseApplication resets the PetriNet such that the same net can be used again after a cancel call or ...
Definition symmetri.cpp:84
void registerCallback(const std::string &transition, Callback &&callback) const noexcept
The default transition payload (DirectMutation) is overloaded by the Callback supplied for a specific...
Definition symmetri.cpp:58
void registerCallbackInPlace(const std::string &transition, Args &&...args) const noexcept
Construct a Callback of type T in place. This is required for type that are not moveable;.
Definition symmetri.h:92
Tokens are elements that can reside in places. Tokens can have a color which makes them distinguishab...
Definition colors.hpp:107
Petri is a data structure that encodes the Petri net and holds pointers to the thread-pool and the re...
Definition petri.h:115
Definition callback.h:88
std::vector< std::pair< Transition, int8_t > > PriorityTable
Definition types.h:51
std::vector< Event > Eventlog
Definition types.h:32
std::vector< std::pair< Place, Token > > Marking
Definition types.h:46
std::unordered_map< Transition, std::pair< std::vector< std::pair< Place, Token > >, std::vector< std::pair< Place, Token > > > > Net
Definition types.h:35