Documentation of CSL
lock.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
24 #ifndef LOCK_H_INCLUDED
25 #define LOCK_H_INCLUDED
26 
27 #include <functional>
28 #include <string>
29 #include <map>
30 
31 namespace csl {
32 
33 class Expr;
34 
44 class Lock {
45 
46 public:
47 
51  using ID_t = int;
55  using predicate = std::function<bool(Expr const&)>;
56 
75  static
76  void lock(
77  Expr &init,
78  int lockId,
79  predicate const &f
80  );
81 
101  static
102  void lock(
103  Expr &init,
104  predicate const &f
105  );
106 
117  static
118  void unlock(
119  Expr &init,
120  int lockId
121  );
122 
134  static
135  void unlock(
136  Expr &init
137  );
138 
148  static
149  std::string lockNameOf(ID_t id);
150 
151 private:
152 
163  static
164  bool doLock(
165  Expr &init,
166  ID_t id,
167  predicate const &f
168  );
169 
179  static
180  void doUnlock(
181  Expr &init,
182  ID_t id
183  );
184 
185 private:
186 
190  static inline
191  std::map<ID_t, std::string> lockName;
192 };
193 
194 } // End of namespace mty
195 
196 #endif
Namespace for csl library.
Definition: abreviation.h:34
static void unlock(Expr &init, int lockId)
Expand abbreviations from a previous lock. The lock id should be the same.
Definition: lock.cpp:55
static std::string lockNameOf(ID_t id)
Returns the generic abbreviation name of a lock given its id.
Definition: lock.cpp:26
Static class allowing to compress expressions given a boolean predicate.
Definition: lock.h:44
std::function< bool(Expr const &)> predicate
Typedef for the boolean predicate.
Definition: lock.h:55
int ID_t
Typedef for lock id.
Definition: lock.h:51
static void lock(Expr &init, int lockId, predicate const &f)
Abbreviates all parts of an expression depending on a condition.
Definition: lock.cpp:33
Expression type/.
Definition: abstract.h:1573