blob: 6906276b7b9b7aaf1be33b9e19c7cf53dc507b36 (
plain)
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
|
/*
* Copyright (C) 2005-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 <memory>
#include <string>
class CGUIListItem;
namespace INFO
{
/*!
\ingroup info
\brief Base class, wrapping boolean conditions and expressions
*/
class InfoBool
{
public:
InfoBool(const std::string &expression, int context, unsigned int &refreshCounter);
virtual ~InfoBool() = default;
virtual void Initialize() {}
/*! \brief Get the value of this info bool
This is called to update (if dirty) and fetch the value of the info bool
\param contextWindow the context (window id) where this condition is being evaluated
\param item the item used to evaluate the bool
*/
inline bool Get(int contextWindow, const CGUIListItem* item = nullptr)
{
if (item && m_listItemDependent)
Update(contextWindow, item);
else if (m_refreshCounter != m_parentRefreshCounter || m_refreshCounter == 0)
{
Update(contextWindow, nullptr);
m_refreshCounter = m_parentRefreshCounter;
}
return m_value;
}
bool operator==(const InfoBool &right) const
{
return (m_context == right.m_context &&
m_expression == right.m_expression);
}
bool operator<(const InfoBool &right) const
{
if (m_context < right.m_context)
return true;
else if (m_context == right.m_context)
return m_expression < right.m_expression;
else
return false;
}
/*! \brief Update the value of this info bool
This is called if and only if the info bool is dirty, allowing it to update it's current value
*/
virtual void Update(int contextWindow, const CGUIListItem* item) {}
const std::string &GetExpression() const { return m_expression; }
bool ListItemDependent() const { return m_listItemDependent; }
protected:
bool m_value; ///< current value
int m_context; ///< contextual information to go with the condition
bool m_listItemDependent; ///< do not cache if a listitem pointer is given
std::string m_expression; ///< original expression
private:
unsigned int m_refreshCounter;
unsigned int &m_parentRefreshCounter;
};
typedef std::shared_ptr<InfoBool> InfoPtr;
};
|