MADARA  3.2.3
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 
5 #include "StringStaged.h"
7 
8 inline void
10 {
11  ContextGuard context_guard (*context_);
12  if (context_ && name_ != "")
13  {
15  }
16 }
17 
18 inline std::string
20 {
21  std::stringstream result;
22 
23  result << "StringStaged: ";
24 
25  if (context_)
26  {
27  ContextGuard context_guard (*context_);
28  MADARA_GUARD_TYPE guard (mutex_);
29 
30  result << this->name_;
31  result << " = " << context_->get (variable_).to_string ();
32  }
33 
34  return result.str ();
35 }
36 
39 {
40  return new StringStaged (*this);
41 }
42 
43 inline void
45 {
46  if (this != &rhs)
47  {
48  MADARA_GUARD_TYPE guard (mutex_), guard2 (rhs.mutex_);
49 
50  this->has_changed_ = rhs.has_changed_;
51  this->value_ = rhs.value_;
52  this->context_ = rhs.context_;
53  this->name_ = rhs.name_;
54  this->settings_ = rhs.settings_;
55  this->variable_ = rhs.variable_;
56  }
57 }
58 
59 inline void
61  const std::string & var_name,
63  bool sync)
64 {
65  KnowledgeUpdateSettings keep_local (true);
66  context_ = &(knowledge.get_context ());
67 
68  ContextGuard context_guard (*context_);
69  MADARA_GUARD_TYPE guard (mutex_);
70 
71  name_ = var_name;
72  variable_ = context_->get_ref (name_, keep_local);
73 
74  if (sync)
75  {
77  has_changed_ = false;
78  }
79 }
80 
81 inline void
83  const std::string & var_name,
85  bool sync)
86 {
87  KnowledgeUpdateSettings keep_local (true);
88  context_ = &knowledge;
89 
90  ContextGuard context_guard (*context_);
91  MADARA_GUARD_TYPE guard (mutex_);
92 
93  name_ = var_name;
94  variable_ = context_->get_ref (name_, keep_local);
95 
96  if (sync)
97  {
99  has_changed_ = false;
100  }
101 }
102 
103 inline void
105  const std::string & var_name,
107  bool sync)
108 {
109  KnowledgeUpdateSettings keep_local (true);
110  context_ = knowledge.get_context ();
111 
112  ContextGuard context_guard (*context_);
113  MADARA_GUARD_TYPE guard (mutex_);
114 
115  name_ = var_name;
116  variable_ = context_->get_ref (name_, keep_local);
117 
118  if (sync)
119  {
121  has_changed_ = false;
122  }
123 }
124 
127 {
128  has_changed_ = true;
129  return value_ = value;
130 }
131 
132 inline bool
134 {
135  return value_ == value;
136 }
137 
138 inline bool
140 {
141  return value_ != value;
142 }
143 
144 inline bool
146 const StringStaged & value) const
147 {
148  return value_ == value.value_;
149 }
150 
151 inline bool
153  const StringStaged & value) const
154 {
155  return value_ != value.value_;
156 }
157 
158 inline bool
160 {
161  return value_ < value;
162 }
163 
164 inline bool
166 {
167  return value_ <= value;
168 }
169 
170 inline bool
172 {
173  return value_ > value;
174 }
175 
176 inline bool
178 {
179  return value_ >= value;
180 }
181 
184 {
185  return to_string ();
186 }
187 
188 inline bool
190 {
191  bool result (false);
192 
193  if (context_)
194  {
195  ContextGuard context_guard (*context_);
196  MADARA_GUARD_TYPE guard (mutex_);
197  result = context_->exists (variable_);
198  }
199 
200  return result;
201 }
202 
203 inline bool
205 {
206  return value_ != "";
207 }
208 
209 inline bool
211 {
212  return value_ == "";
213 }
214 
217 {
218  return KnowledgeRecord (value_);
219 }
220 
223 {
224  KnowledgeRecord value (value_);
225  return value.to_integer ();
226 }
227 
230 {
231  has_changed_ = true;
232  value_ += value;
233 
234  return value_;
235 }
236 
239 {
240  has_changed_ = true;
241  value_ += value;
242 
243  return value_;
244 }
245 
246 inline double
248 {
249  KnowledgeRecord value (value_);
250  return value.to_double ();
251 }
252 
253 inline std::string
255 {
256  return value_;
257 }
258 
259 inline void
261  uint32_t quality,
262  const KnowledgeReferenceSettings & settings)
263 {
264  if (context_)
265  {
266  ContextGuard context_guard (*context_);
267  MADARA_GUARD_TYPE guard (mutex_);
268  context_->set_quality (name_, quality, true, settings);
269  }
270 }
271 
272 inline void
274 {
275  has_changed_ = false;
277 }
278 
279 inline void
281 {
282  if (has_changed_)
284 }
285 
286 #endif // _MADARA_KNOWLEDGE_CONTAINERS_STRINGSTAGED_INL_
This class encapsulates an entry in a KnowledgeBase.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the variable.
type operator+=(const type &value)
Increments by a value.
bool is_false(void) const
Determines if the value is zero.
type operator*(void) const
Returns the value of the variable.
madara::knowledge::KnowledgeRecord KnowledgeRecord
void modify(void)
Mark the value as modified.
Definition: StringStaged.inl:9
double to_double(void) const
converts the value to a float/double.
std::string name_
Prefix of variable.
void operator=(const StringStaged &rhs)
Assignment operator.
bool operator>(const type &value) const
Checks for greater than relationship.
This class stores variables and their values for use by any entity needing state information in a thr...
bool has_changed_
Tracks if value_ has changed since last read.
Definition: StringStaged.h:377
double to_double(void) const
Returns the value as a double.
MADARA_LOCK_TYPE mutex_
guard for access and changes
virtual BaseContainer * clone(void) const
Clones this container.
bool is_true(void) const
Determines if the value is true.
void write(void)
Writes the value to the knowledge base.
type operator-=(const type &value)
Decrements by a value.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
bool operator<(const type &value) const
Checks for less than relationship.
bool operator<=(const type &value) const
Checks for less than or equal to relationship.
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:23
static struct madara::knowledge::tags::string_t string
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
Integer to_integer(void) const
converts the value to an integer.
std::string type
trait that describes the value type
Definition: StringStaged.h:42
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
VariableReference variable_
Variable reference.
Definition: StringStaged.h:367
Provides functions and classes for the distributed knowledge base.
knowledge::KnowledgeRecord to_record(void) const
Returns the value as a knowledge::KnowledgeRecord.
KnowledgeUpdateSettings settings_
Settings for modifications.
void read(void)
Reads the value from the knowledge base.
bool operator>=(const type &value) const
Checks for greater than or equal to relationship.
Settings for applying knowledge updates.
std::string to_string(void) const
Returns the value as a string.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, bool sync=true)
Sets the variable name that this refers to.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
Settings for applying knowledge updates.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
Definition: BaseContainer.h:33
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: StringStaged.h:362
StringStaged(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
Definition: StringStaged.cpp:4
bool exists(void) const
Checks to see if the variable has ever been assigned a value.
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...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.
bool operator==(const StringStaged &value) const
Checks for equality.
Stages a string value to and from the knowledge base.
Definition: StringStaged.h:38
bool operator!=(const StringStaged &value) const
Checks for inequality.