kodi
InfoBool.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <memory>
12 #include <string>
13 
14 class CGUIListItem;
15 class CGUIInfoManager;
16 
17 namespace INFO
18 {
23 class InfoBool
24 {
25 public:
26  InfoBool(const std::string &expression, int context, unsigned int &refreshCounter);
27  virtual ~InfoBool() = default;
28 
29  virtual void Initialize(CGUIInfoManager* infoMgr) { m_infoMgr = infoMgr; }
30 
36  inline bool Get(int contextWindow, const CGUIListItem* item = nullptr)
37  {
38  if (item && m_listItemDependent)
39  Update(contextWindow, item);
40  else if (m_refreshCounter != m_parentRefreshCounter || m_refreshCounter == 0)
41  {
42  Update(contextWindow, nullptr);
43  m_refreshCounter = m_parentRefreshCounter;
44  }
45  return m_value;
46  }
47 
48  bool operator==(const InfoBool &right) const
49  {
50  return (m_context == right.m_context &&
51  m_expression == right.m_expression);
52  }
53 
54  bool operator<(const InfoBool &right) const
55  {
56  if (m_context < right.m_context)
57  return true;
58  else if (m_context == right.m_context)
59  return m_expression < right.m_expression;
60  else
61  return false;
62  }
63 
67  virtual void Update(int contextWindow, const CGUIListItem* item) {}
68 
69  const std::string &GetExpression() const { return m_expression; }
70  bool ListItemDependent() const { return m_listItemDependent; }
71 protected:
72  bool m_value = false;
73  int m_context;
74  bool m_listItemDependent = false;
75  std::string m_expression;
76  CGUIInfoManager* m_infoMgr;
77 
78 private:
79  unsigned int m_refreshCounter = 0;
80  unsigned int &m_parentRefreshCounter;
81 };
82 
83 typedef std::shared_ptr<InfoBool> InfoPtr;
84 };
Definition: GUIInfoManager.h:56
Definition: GUIListItem.h:29
bool m_listItemDependent
do not cache if a listitem pointer is given
Definition: InfoBool.h:74
Definition: ContextMenuItem.h:23
virtual void Update(int contextWindow, const CGUIListItem *item)
Update the value of this info bool This is called if and only if the info bool is dirty...
Definition: InfoBool.h:67
bool m_value
current value
Definition: InfoBool.h:72
int m_context
contextual information to go with the condition
Definition: InfoBool.h:73
std::string m_expression
original expression
Definition: InfoBool.h:75
bool Get(int contextWindow, const CGUIListItem *item=nullptr)
Get the value of this info bool This is called to update (if dirty) and fetch the value of the info b...
Definition: InfoBool.h:36
Base class, wrapping boolean conditions and expressions.
Definition: InfoBool.h:23