MADARA  3.4.1
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 
12  : BaseContainer(name, settings), context_(&(knowledge.get_context()))
13 {
14  variable_ = knowledge.get_ref(name, settings_);
15 }
16 
19  : BaseContainer(name, settings), context_(knowledge.get_context())
20 {
21  variable_ = knowledge.get_ref(name, settings_);
22 }
23 
26  const KnowledgeUpdateSettings& settings)
27  : BaseContainer(name, settings), context_(&(knowledge.get_context()))
28 {
29  variable_ = knowledge.get_ref(name);
30  context_->set(variable_, value, settings);
31 }
32 
34  Variables& knowledge, type value, const KnowledgeUpdateSettings& settings)
35  : BaseContainer(name, settings), context_(knowledge.get_context())
36 {
37  variable_ = knowledge.get_ref(name);
38  context_->set(variable_, value, settings);
39 }
40 
42  : BaseContainer(rhs), context_(rhs.context_), variable_(rhs.variable_)
43 {
44 }
45 
47 
49 {
50  modify();
51 }
52 
54 {
55  return get_debug_info();
56 }
57 
59  containers::Integer& other)
60 {
61  if (context_ && other.context_)
62  {
63  ContextGuard context_guard(*context_, std::adopt_lock);
64  ContextGuard other_context_guard(*other.context_, std::adopt_lock);
65  MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
66  guard2(other.mutex_, std::adopt_lock);
67 
68  type temp = *other;
69  other = **this;
70  *this = temp;
71  }
72 }
73 
75 {
76  return is_true();
77 }
78 
80 {
81  return is_false();
82 }
const ThreadSafeContext * context_
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
Settings for applying knowledge updates.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
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.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores an integer within a variable context.
Definition: Integer.h:32
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
Definition: Integer.h:35
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Definition: Integer.cpp:48
Integer(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
Definition: Integer.cpp:4
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:74
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Definition: Integer.cpp:53
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Integer.h:337
void exchange(containers::Integer &other)
Exchanges the integer at this location with the integer at another location.
Definition: Integer.cpp:58
VariableReference variable_
Variable reference.
Definition: Integer.h:342
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:79
constexpr string_t string
Provides functions and classes for the distributed knowledge base.