1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/*
* Copyright (C) 2013-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "SettingConditions.h"
#include "utils/BooleanLogic.h"
#include "utils/logtypes.h"
#include <list>
#include <set>
#include <string>
enum class SettingDependencyType {
Unknown = 0,
Enable,
Update,
Visible
};
enum class SettingDependencyOperator {
Unknown = 0,
Equals,
LessThan,
GreaterThan,
Contains
};
enum class SettingDependencyTarget {
Unknown = 0,
Setting,
Property
};
class CSettingDependencyCondition : public CSettingConditionItem
{
public:
explicit CSettingDependencyCondition(CSettingsManager *settingsManager = nullptr);
CSettingDependencyCondition(const std::string &setting, const std::string &value,
SettingDependencyOperator op, bool negated = false,
CSettingsManager *settingsManager = nullptr);
CSettingDependencyCondition(const std::string &strProperty, const std::string &value,
const std::string &setting = "", bool negated = false,
CSettingsManager *settingsManager = nullptr);
~CSettingDependencyCondition() override = default;
bool Deserialize(const TiXmlNode *node) override;
bool Check() const override;
const std::string& GetName() const { return m_name; }
const std::string& GetSetting() const { return m_setting; }
SettingDependencyTarget GetTarget() const { return m_target; }
SettingDependencyOperator GetOperator() const { return m_operator; }
private:
CSettingDependencyCondition(CSettingsManager* settingsManager,
const std::string& strProperty,
const std::string& setting,
const std::string& value,
SettingDependencyTarget target = SettingDependencyTarget::Unknown,
SettingDependencyOperator op = SettingDependencyOperator::Equals,
bool negated = false);
bool setTarget(const std::string &target);
bool setOperator(const std::string &op);
SettingDependencyTarget m_target = SettingDependencyTarget::Unknown;
SettingDependencyOperator m_operator = SettingDependencyOperator::Equals;
static Logger s_logger;
};
using CSettingDependencyConditionPtr = std::shared_ptr<CSettingDependencyCondition>;
class CSettingDependencyConditionCombination;
using CSettingDependencyConditionCombinationPtr = std::shared_ptr<CSettingDependencyConditionCombination>;
class CSettingDependencyConditionCombination : public CSettingConditionCombination
{
public:
explicit CSettingDependencyConditionCombination(CSettingsManager *settingsManager = nullptr)
: CSettingConditionCombination(settingsManager)
{ }
CSettingDependencyConditionCombination(BooleanLogicOperation op, CSettingsManager *settingsManager = nullptr)
: CSettingConditionCombination(settingsManager)
{
SetOperation(op);
}
~CSettingDependencyConditionCombination() override = default;
bool Deserialize(const TiXmlNode *node) override;
const std::set<std::string>& GetSettings() const { return m_settings; }
CSettingDependencyConditionCombination* Add(const CSettingDependencyConditionPtr& condition);
CSettingDependencyConditionCombination* Add(
const CSettingDependencyConditionCombinationPtr& operation);
private:
CBooleanLogicOperation* newOperation() override { return new CSettingDependencyConditionCombination(m_settingsManager); }
CBooleanLogicValue* newValue() override { return new CSettingDependencyCondition(m_settingsManager); }
std::set<std::string> m_settings;
};
class CSettingDependency : public CSettingCondition
{
public:
explicit CSettingDependency(CSettingsManager *settingsManager = nullptr);
CSettingDependency(SettingDependencyType type, CSettingsManager *settingsManager = nullptr);
~CSettingDependency() override = default;
bool Deserialize(const TiXmlNode *node) override;
SettingDependencyType GetType() const { return m_type; }
std::set<std::string> GetSettings() const;
CSettingDependencyConditionCombinationPtr And();
CSettingDependencyConditionCombinationPtr Or();
private:
bool setType(const std::string &type);
SettingDependencyType m_type = SettingDependencyType::Unknown;
static Logger s_logger;
};
using SettingDependencies = std::list<CSettingDependency>;
using SettingDependencyMap = std::map<std::string, SettingDependencies>;
|