TDME2 1.9.121
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
11using std::find;
12using std::string;
13using std::vector;
14
16
17/**
18 * GUI element node conditions
19 * @author Andreas Drewke
20 * @version $Id$
21 */
23{
24 friend class GUINode;
25
26private:
28 vector<string> conditions;
29
30 /**
31 * Update node
32 * @param node node
33 * @param conditions conditions that have been set
34 */
35 void updateNode(GUINode* node, const vector<string>& conditions) const;
36
37 /**
38 * Update element node
39 * @param conditions conditions that have been set
40 */
41 void updateElementNode(const vector<string>& conditions) const;
42
43public:
44 /**
45 * Public constructor
46 * @param node node
47 */
48 GUINodeConditions(GUIElementNode* node = nullptr);
49
50 /**
51 * @return conditions
52 */
53 inline const vector<string>& getConditions() const {
54 return conditions;
55 }
56
57 /**
58 * Returns if condition is set
59 * @param condition condition name
60 * @return if condition is set
61 */
62 inline bool has(const string& condition) const {
63 return find(conditions.begin(), conditions.end(), condition) != conditions.end();
64 }
65
66 /**
67 * Set condition
68 * @param condition condition
69 */
70 inline void set(const string& condition) {
71 this->conditions = {{ condition }};
73 }
74
75 /**
76 * Set multiple conditions
77 * @param conditions conditions
78 */
79 inline void set(const vector<string>& conditions) {
80 this->conditions = conditions;
82 }
83
84 /**
85 * Add a condition
86 * @param condition condition
87 * @return condition changed
88 */
89 inline bool add(const string& condition) {
90 auto conditionsChanged = has(condition) == false;
91 if (conditionsChanged == true) {
92 conditions.push_back(condition);
93 updateElementNode({condition});
94 }
95 return conditionsChanged;
96 }
97
98 /**
99 * Remove a condition
100 * @param condition condition
101 * @return condition changed
102 */
103 inline bool remove(const string& condition) {
104 auto conditionsChanged = has(condition);
105 if (conditionsChanged == true) {
106 conditions.erase(std::remove(conditions.begin(), conditions.end(), condition), conditions.end());
108 }
109 return conditionsChanged;
110 }
111
112 /**
113 * Remove all
114 * @return condition changed
115 */
116 inline bool removeAll() {
117 auto conditionsChanged = conditions.empty() == false;
118 if (conditionsChanged == true) {
119 conditions.clear();
121 }
122 return conditionsChanged;
123 }
124
125};
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.
const vector< string > & getConditions() const
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.
GUI node base class.
Definition: GUINode.h:63