@@ -1,43 +1,71 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLESTATES_H |
|
2 | 2 | #define SCIQLOP_VARIABLESTATES_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Common/MetaTypes.h> |
|
7 | 7 | |
|
8 | 8 | #include <memory> |
|
9 | 9 | #include <tuple> |
|
10 | 10 | |
|
11 | 11 | #include <QVariantMap> |
|
12 | 12 | |
|
13 | 13 | using StateData = QVariantMap; |
|
14 | 14 | SCIQLOP_REGISTER_META_TYPE(STATEDATA_REGISTRY, StateData) |
|
15 | 15 | |
|
16 | 16 | /** |
|
17 | 17 | * @brief The IVariableState class is the representation interface of a state in which a variable |
|
18 | 18 | * may be. It proposes different methods to represent the variable according to its current state |
|
19 | 19 | * @sa Variable |
|
20 | 20 | */ |
|
21 | 21 | struct SCIQLOP_CORE_EXPORT IVariableState { |
|
22 | 22 | virtual ~IVariableState() noexcept = default; |
|
23 | 23 | |
|
24 | 24 | virtual std::unique_ptr<IVariableState> clone() const = 0; |
|
25 | 25 | |
|
26 | 26 | /// @return the data associated with the state |
|
27 | 27 | virtual StateData data() const = 0; |
|
28 | 28 | }; |
|
29 | 29 | |
|
30 | 30 | /// Default implementation of @sa IVariableState |
|
31 | 31 | class AbstractVariableState : public IVariableState { |
|
32 | 32 | public: |
|
33 | 33 | /// @sa IVariableState::data() |
|
34 | 34 | StateData data() const override; |
|
35 | 35 | |
|
36 | 36 | protected: |
|
37 | 37 | explicit AbstractVariableState(StateData data); |
|
38 | 38 | |
|
39 | 39 | private: |
|
40 | 40 | StateData m_Data; |
|
41 | 41 | }; |
|
42 | 42 | |
|
43 | /** | |
|
44 | * State when a variable is fully loaded (i.e. the last request on the variable has been | |
|
45 | * successfully completed) | |
|
46 | */ | |
|
47 | class LoadedState : public AbstractVariableState { | |
|
48 | public: | |
|
49 | explicit LoadedState(); | |
|
50 | std::unique_ptr<IVariableState> clone() const override; | |
|
51 | }; | |
|
52 | ||
|
53 | /** | |
|
54 | * State when a variable is loading (i.e. there's pending requests for the variable) | |
|
55 | */ | |
|
56 | class LoadingState : public AbstractVariableState { | |
|
57 | public: | |
|
58 | explicit LoadingState(); | |
|
59 | std::unique_ptr<IVariableState> clone() const override; | |
|
60 | }; | |
|
61 | ||
|
62 | /** | |
|
63 | * State when a variable is canceled (i.e. the last request on the variable has been canceled) | |
|
64 | */ | |
|
65 | class CanceledState : public AbstractVariableState { | |
|
66 | public: | |
|
67 | explicit CanceledState(); | |
|
68 | std::unique_ptr<IVariableState> clone() const override; | |
|
69 | }; | |
|
70 | ||
|
43 | 71 | #endif // SCIQLOP_VARIABLESTATES_H |
@@ -1,10 +1,49 | |||
|
1 | 1 | #include "Variable/VariableStates.h" |
|
2 | 2 | |
|
3 | 3 | AbstractVariableState::AbstractVariableState(StateData data) : m_Data{std::move(data)} |
|
4 | 4 | { |
|
5 | 5 | } |
|
6 | 6 | |
|
7 | 7 | StateData AbstractVariableState::data() const |
|
8 | 8 | { |
|
9 | 9 | return m_Data; |
|
10 | 10 | } |
|
11 | ||
|
12 | // /////////// // | |
|
13 | // LoadedState // | |
|
14 | // /////////// // | |
|
15 | ||
|
16 | LoadedState::LoadedState() : AbstractVariableState{{{"color", "green"}}} | |
|
17 | { | |
|
18 | } | |
|
19 | ||
|
20 | std::unique_ptr<IVariableState> LoadedState::clone() const | |
|
21 | { | |
|
22 | return std::make_unique<LoadedState>(*this); | |
|
23 | } | |
|
24 | ||
|
25 | // //////////// // | |
|
26 | // LoadingState // | |
|
27 | // //////////// // | |
|
28 | ||
|
29 | LoadingState::LoadingState() : AbstractVariableState{{{"color", "blue"}}} | |
|
30 | { | |
|
31 | } | |
|
32 | ||
|
33 | std::unique_ptr<IVariableState> LoadingState::clone() const | |
|
34 | { | |
|
35 | return std::make_unique<LoadingState>(*this); | |
|
36 | } | |
|
37 | ||
|
38 | // ///////////// // | |
|
39 | // CanceledState // | |
|
40 | // ///////////// // | |
|
41 | ||
|
42 | CanceledState::CanceledState() : AbstractVariableState{{{"color", "red"}}} | |
|
43 | { | |
|
44 | } | |
|
45 | ||
|
46 | std::unique_ptr<IVariableState> CanceledState::clone() const | |
|
47 | { | |
|
48 | return std::make_unique<CanceledState>(*this); | |
|
49 | } |
General Comments 0
You need to be logged in to leave comments.
Login now