MADARA  3.2.3
Integer.cpp
Go to the documentation of this file.
1 #include "Integer.h"
3 
5  const KnowledgeUpdateSettings & settings)
6 : BaseContainer ("", settings), context_ (0)
7 {
8 }
9 
11  const std::string & name,
13  const KnowledgeUpdateSettings & settings)
14 : BaseContainer (name, settings), context_ (&(knowledge.get_context ()))
15 {
16  variable_ = knowledge.get_ref (name, settings_);
17 }
18 
20  const std::string & name,
22  const KnowledgeUpdateSettings & settings)
23 : BaseContainer (name, settings), context_ (knowledge.get_context ())
24 {
25  variable_ = knowledge.get_ref (name, settings_);
26 }
27 
29  const std::string & name,
31  type value,
32  const KnowledgeUpdateSettings & settings)
33 : BaseContainer (name, settings), context_ (&(knowledge.get_context ()))
34 {
35  variable_ = knowledge.get_ref (name);
36  context_->set (variable_, value, settings);
37 }
38 
40  const std::string & name,
42  type value,
43  const KnowledgeUpdateSettings & settings)
44 : BaseContainer (name, settings), context_ (knowledge.get_context ())
45 {
46  variable_ = knowledge.get_ref (name);
47  context_->set (variable_, value, settings);
48 }
49 
50 
53 {
54 
55 }
56 
57 
59 {
60 
61 }
62 
63 void
65 {
66  modify ();
67 }
68 
71 {
72  return get_debug_info ();
73 }
74 
75 void
77  containers::Integer & other)
78 {
79  if (context_ && other.context_)
80  {
81  ContextGuard context_guard (*context_, std::adopt_lock);
82  ContextGuard other_context_guard (*other.context_, std::adopt_lock);
83  MADARA_GUARD_TYPE guard (mutex_, std::adopt_lock),
84  guard2 (other.mutex_, std::adopt_lock);
85 
86 
87  type temp = *other;
88  other = **this;
89  *this = temp;
90  }
91 }
92 
93 
94 bool
96 {
97  return is_true ();
98 }
99 
100 bool
102 {
103  return is_false ();
104 }
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false))
Retrieves the value of a variable.
Integer(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
Definition: Integer.cpp:4
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
Definition: Integer.inl:19
void modify(void)
Mark the value as modified.
Definition: Integer.inl:9
virtual ~Integer()
Destructor.
Definition: Integer.cpp:58
VariableReference variable_
Variable reference.
Definition: Integer.h:358
MADARA_LOCK_TYPE mutex_
guard for access and changes
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Definition: Integer.cpp:70
bool is_true(void) const
Determines if the value is true.
Definition: Integer.inl:247
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:23
virtual bool is_false_(void) const
Polymorphic is false method which can be used to determine if at least one value in the container is ...
Definition: Integer.cpp:101
static struct madara::knowledge::tags::string_t string
bool is_false(void) const
Determines if the value is zero.
Definition: Integer.inl:268
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class stores an integer within a variable context.
Definition: Integer.h:31
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
void exchange(containers::Integer &other)
Exchanges the integer at this location with the integer at another location.
Definition: Integer.cpp:76
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
Definition: Integer.cpp:95
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
Definition: Integer.h:35
Settings for applying knowledge updates.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Definition: Integer.cpp:64
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Integer.h:353
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
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Atomically returns a reference to the variable.