PLaSK library
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__UTILS_EVENT_H
15#define PLASK__UTILS_EVENT_H
16
21namespace plask {
22
29template <typename SourceType, typename _FlagsType = unsigned char>
31
33 SourceType* _source;
34
36 _FlagsType _flags;
37
38public:
39
41
46 const SourceType* source() const { return _source; }
47
52 SourceType* source() { return _source; }
53
59 template <typename T>
60 const T* source() const {
61 const T* casted = dynamic_cast<const T*>(_source);
62 if (!casted && _source) throw std::bad_cast();
63 return casted;
64 }
65
71 template <typename T>
72 T* source() {
73 T* casted = dynamic_cast<T*>(_source);
74 if (!casted && _source) throw std::bad_cast();
75 return casted;
76 }
77
82 FlagsType flags() const { return _flags; }
83
90
96 bool hasAllFlags(FlagsType flags) const { return (_flags & flags) == flags; }
97
103 bool hasAnyFlag(FlagsType flags) const { return (_flags & flags) != 0; }
104
110 explicit EventWithSourceAndFlags(SourceType* source, FlagsType flags = 0): _source(source), _flags(flags) {}
111
114
115};
116
117} // namespace plask
118
119#endif // PLASK__UTILS_EVENT_H