MADARA  3.4.1
StringStaged.inl
Go to the documentation of this file.
1 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_STRINGSTAGED_INL_
2 #define _MADARA_KNOWLEDGE_CONTAINERS_STRINGSTAGED_INL_
3 
4 #include "StringStaged.h"
6 
8 {
9  ContextGuard context_guard(*context_);
10  if (context_ && name_ != "")
11  {
13  }
14 }
15 
17  void)
18 {
19  std::stringstream result;
20 
21  result << "StringStaged: ";
22 
23  if (context_)
24  {
25  ContextGuard context_guard(*context_);
26  MADARA_GUARD_TYPE guard(mutex_);
27 
28  result << this->name_;
29  result << " = " << context_->get(variable_).to_string();
30  }
31 
32  return result.str();
33 }
34 
37 {
38  return new StringStaged(*this);
39 }
40 
42  const StringStaged& rhs)
43 {
44  if (this != &rhs)
45  {
46  MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.mutex_);
47 
48  this->has_changed_ = rhs.has_changed_;
49  this->value_ = rhs.value_;
50  this->context_ = rhs.context_;
51  this->name_ = rhs.name_;
52  this->settings_ = rhs.settings_;
53  this->variable_ = rhs.variable_;
54  }
55 }
56 
58  const std::string& var_name, KnowledgeBase& knowledge, bool sync)
59 {
60  KnowledgeUpdateSettings keep_local(true);
61  context_ = &(knowledge.get_context());
62 
63  ContextGuard context_guard(*context_);
64  MADARA_GUARD_TYPE guard(mutex_);
65 
66  name_ = var_name;
67  variable_ = context_->get_ref(name_, keep_local);
68 
69  if (sync)
70  {
71  value_ = context_->get(variable_).to_string();
72  has_changed_ = false;
73  }
74 }
75 
77  const std::string& var_name, ThreadSafeContext& knowledge, bool sync)
78 {
79  KnowledgeUpdateSettings keep_local(true);
81 
82  ContextGuard context_guard(*context_);
83  MADARA_GUARD_TYPE guard(mutex_);
84 
85  name_ = var_name;
86  variable_ = context_->get_ref(name_, keep_local);
87 
88  if (sync)
89  {
90  value_ = context_->get(variable_).to_string();
91  has_changed_ = false;
92  }
93 }
94 
96  const std::string& var_name, Variables& knowledge, bool sync)
97 {
98  KnowledgeUpdateSettings keep_local(true);
99  context_ = knowledge.get_context();
100 
101  ContextGuard context_guard(*context_);
102  MADARA_GUARD_TYPE guard(mutex_);
103 
104  name_ = var_name;
105  variable_ = context_->get_ref(name_, keep_local);
106 
107  if (sync)
108  {
109  value_ = context_->get(variable_).to_string();
110  has_changed_ = false;
111  }
112 }
113 
116 {
117  has_changed_ = true;
118  return value_ = value;
119 }
120 
122  const type& value) const
123 {
124  return value_ == value;
125 }
126 
128  const type& value) const
129 {
130  return value_ != value;
131 }
132 
134  const StringStaged& value) const
135 {
136  return value_ == value.value_;
137 }
138 
140  const StringStaged& value) const
141 {
142  return value_ != value.value_;
143 }
144 
146  const type& value) const
147 {
148  return value_ < value;
149 }
150 
152  const type& value) const
153 {
154  return value_ <= value;
155 }
156 
158  const type& value) const
159 {
160  return value_ > value;
161 }
162 
164  const type& value) const
165 {
166  return value_ >= value;
167 }
168 
171 {
172  return to_string();
173 }
174 
176 {
177  bool result(false);
178 
179  if (context_)
180  {
181  ContextGuard context_guard(*context_);
182  MADARA_GUARD_TYPE guard(mutex_);
183  result = context_->exists(variable_);
184  }
185 
186  return result;
187 }
188 
190 {
191  return value_ != "";
192 }
193 
195 {
196  return value_ == "";
197 }
198 
201 {
202  return KnowledgeRecord(value_);
203 }
204 
207 {
208  KnowledgeRecord value(value_);
209  return value.to_integer();
210 }
211 
214 {
215  has_changed_ = true;
216  value_ += value;
217 
218  return value_;
219 }
220 
223 {
224  has_changed_ = true;
225  value_ += value;
226 
227  return value_;
228 }
229 
231 {
232  KnowledgeRecord value(value_);
233  return value.to_double();
234 }
235 
237  void) const
238 {
239  return value_;
240 }
241 
243  uint32_t quality, const KnowledgeReferenceSettings& settings)
244 {
245  if (context_)
246  {
247  ContextGuard context_guard(*context_);
248  MADARA_GUARD_TYPE guard(mutex_);
249  context_->set_quality(name_, quality, true, settings);
250  }
251 }
252 
254 {
255  has_changed_ = false;
256  value_ = context_->get(variable_).to_string();
257 }
258 
260 {
261  if (has_changed_)
262  context_->set(variable_, value_);
263 }
264 
265 #endif // _MADARA_KNOWLEDGE_CONTAINERS_STRINGSTAGED_INL_
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:24
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
double to_double(void) const
converts the value to a float/double.
Integer to_integer(void) const
converts the value to an integer.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class is an abstract base class for all containers.
Definition: BaseContainer.h:34
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
Stages a string value to and from the knowledge base.
Definition: StringStaged.h:39
bool exists(void) const
Checks to see if the variable has ever been assigned a value.
bool operator<=(const type &value) const
Checks for less than or equal to relationship.
bool has_changed_
Tracks if value_ has changed since last read.
Definition: StringStaged.h:363
type operator*(void) const
Returns the value of the variable.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the variable.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
knowledge::KnowledgeRecord to_record(void) const
Returns the value as a knowledge::KnowledgeRecord.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, bool sync=true)
Sets the variable name that this refers to.
bool is_true(void) const
Determines if the value is true.
bool operator>(const type &value) const
Checks for greater than relationship.
virtual BaseContainer * clone(void) const
Clones this container.
bool operator<(const type &value) const
Checks for less than relationship.
bool operator>=(const type &value) const
Checks for greater than or equal to relationship.
bool operator!=(const StringStaged &value) const
Checks for inequality.
void operator=(const StringStaged &rhs)
Assignment operator.
double to_double(void) const
Returns the value as a double.
VariableReference variable_
Variable reference.
Definition: StringStaged.h:353
void write(void)
Writes the value to the knowledge base.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
std::string to_string(void) const
Returns the value as a string.
void read(void)
Reads the value from the knowledge base.
bool operator==(const StringStaged &value) const
Checks for equality.
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: StringStaged.h:348
bool is_false(void) const
Determines if the value is zero.
type operator-=(const type &value)
Decrements by a value.
std::string type
trait that describes the value type
Definition: StringStaged.h:42
void modify(void)
Mark the value as modified.
Definition: StringStaged.inl:7
type operator+=(const type &value)
Increments by a value.
constexpr string_t string
Provides functions and classes for the distributed knowledge base.