TDME2  1.9.200
GUINodeConditions.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
10 
11 using std::find;
12 using std::string;
13 using std::vector;
14 
16 
17 /**
18  * GUI element node conditions
19  * @author Andreas Drewke
20  */
22 {
23  friend class GUINode;
24 
25 private:
27  vector<string> conditions;
28 
29  /**
30  * Update node
31  * @param node node
32  * @param conditions conditions that have been set
33  */
34  void updateNode(GUINode* node, const vector<string>& conditions) const;
35 
36  /**
37  * Update element node
38  * @param conditions conditions that have been set
39  */
40  void updateElementNode(const vector<string>& conditions) const;
41 
42 public:
43  /**
44  * Public constructor
45  * @param node node
46  */
47  GUINodeConditions(GUIElementNode* node = nullptr);
48 
49  /**
50  * @return conditions
51  */
52  inline const vector<string>& getConditions() const {
53  return conditions;
54  }
55 
56  /**
57  * Returns if condition is set
58  * @param condition condition name
59  * @return if condition is set
60  */
61  inline bool has(const string& condition) const {
62  return find(conditions.begin(), conditions.end(), condition) != conditions.end();
63  }
64 
65  /**
66  * Set condition
67  * @param condition condition
68  */
69  inline void set(const string& condition) {
70  this->conditions = {{ condition }};
72  }
73 
74  /**
75  * Set multiple conditions
76  * @param conditions conditions
77  */
78  inline void set(const vector<string>& conditions) {
79  this->conditions = conditions;
81  }
82 
83  /**
84  * Add a condition
85  * @param condition condition
86  * @return condition changed
87  */
88  inline bool add(const string& condition) {
89  auto conditionsChanged = has(condition) == false;
90  if (conditionsChanged == true) {
91  conditions.push_back(condition);
92  updateElementNode({condition});
93  }
94  return conditionsChanged;
95  }
96 
97  /**
98  * Remove a condition
99  * @param condition condition
100  * @return condition changed
101  */
102  inline bool remove(const string& condition) {
103  auto conditionsChanged = has(condition);
104  if (conditionsChanged == true) {
105  conditions.erase(std::remove(conditions.begin(), conditions.end(), condition), conditions.end());
106  updateElementNode({});
107  }
108  return conditionsChanged;
109  }
110 
111  /**
112  * Remove all
113  * @return condition changed
114  */
115  inline bool removeAll() {
116  auto conditionsChanged = conditions.empty() == false;
117  if (conditionsChanged == true) {
118  conditions.clear();
119  updateElementNode({});
120  }
121  return conditionsChanged;
122  }
123 
124 };
GUI element node conditions.
bool add(const string &condition)
Add a condition.
void updateNode(GUINode *node, const vector< string > &conditions) const
Update node.
bool has(const string &condition) const
Returns if condition is set.
void set(const vector< string > &conditions)
Set multiple conditions.
bool remove(const string &condition)
Remove a condition.
void set(const string &condition)
Set condition.
void updateElementNode(const vector< string > &conditions) const
Update element node.
GUINodeConditions(GUIElementNode *node=nullptr)
Public constructor.
const vector< string > & getConditions() const
GUI node base class.
Definition: GUINode.h:64