xbmc
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 
16 namespace INFO
17 {
22 class InfoBool
23 {
24 public:
25  InfoBool(const std::string &expression, int context, unsigned int &refreshCounter);
26  virtual ~InfoBool() = default;
27 
28  virtual void Initialize() {}
29 
35  inline bool Get(int contextWindow, const CGUIListItem* item = nullptr)
36  {
37  if (item && m_listItemDependent)
38  Update(contextWindow, item);
39  else if (m_refreshCounter != m_parentRefreshCounter || m_refreshCounter == 0)
40  {
41  Update(contextWindow, nullptr);
42  m_refreshCounter = m_parentRefreshCounter;
43  }
44  return m_value;
45  }
46 
47  bool operator==(const InfoBool &right) const
48  {
49  return (m_context == right.m_context &&
50  m_expression == right.m_expression);
51  }
52 
53  bool operator<(const InfoBool &right) const
54  {
55  if (m_context < right.m_context)
56  return true;
57  else if (m_context == right.m_context)
58  return m_expression < right.m_expression;
59  else
60  return false;
61  }
62 
66  virtual void Update(int contextWindow, const CGUIListItem* item) {}
67 
68  const std::string &GetExpression() const { return m_expression; }
69  bool ListItemDependent() const { return m_listItemDependent; }
70 protected:
71 
72  bool m_value;
73  int m_context;
75  std::string m_expression;
76 
77 private:
78  unsigned int m_refreshCounter;
79  unsigned int &m_parentRefreshCounter;
80 };
81 
82 typedef std::shared_ptr<InfoBool> InfoPtr;
83 };
Definition: GUIListItem.h:30
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:66
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:35
Base class, wrapping boolean conditions and expressions.
Definition: InfoBool.h:22