MADARA  3.4.1
Collection.cpp
Go to the documentation of this file.
1 #include "Collection.h"
2 
4 
6  : BaseContainer()
7 {
8  vector_.resize(rhs.vector_.size());
9  for (size_t i = 0; i < rhs.vector_.size(); ++i)
10  {
11  vector_[i] = rhs.vector_[i]->clone();
12  }
13 }
14 
16 {
17  clear();
18 }
19 
21 {
22  MADARA_GUARD_TYPE guard(mutex_);
23 
24  for (size_t i = 0; i < vector_.size(); ++i)
25  {
26  vector_[i]->modify_();
27  }
28 }
29 
31 {
32  MADARA_GUARD_TYPE guard(mutex_);
33 
34  std::stringstream result;
35 
36  for (size_t i = 0; i < vector_.size(); ++i)
37  {
38  result << vector_[i]->get_debug_info_() << "\n";
39  }
40 
41  return result.str();
42 }
43 
45 {
46  modify();
47 }
48 
50 {
51  return get_debug_info();
52 }
53 
56 {
57  return new Collection(*this);
58 }
59 
61 {
62  bool result(true);
63 
65  "Collection::is_true: checking all containers for truth\n");
66 
67  if (context_)
68  {
69  ContextGuard context_guard(*context_);
70  MADARA_GUARD_TYPE guard(mutex_);
71 
72  for (size_t i = 0; i < vector_.size(); ++i)
73  {
74  if (vector_[i]->is_false_())
75  {
76  result = false;
77  break;
78  }
79  }
80  }
81 
83  "Collection::is_true: final result is %d\n", (int)result);
84 
85  return result;
86 }
87 
89 {
90  return !is_true();
91 }
92 
94 {
95  return is_true();
96 }
97 
99 {
100  return is_false();
101 }
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:24
This class is an abstract base class for all containers.
Definition: BaseContainer.h:34
A collection of MADARA containers that can be used for aggregate operations on all containers in the ...
Definition: Collection.h:44
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Definition: Collection.cpp:49
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: Collection.cpp:98
virtual BaseContainer * clone(void) const
Clones this container.
Definition: Collection.cpp:55
void modify(void)
Mark all values in the container as modified.
Definition: Collection.cpp:20
std::vector< BaseContainer * > vector_
The underlying collection of containers.
Definition: Collection.h:154
std::string get_debug_info(void)
Returns the type of the containers along with name and any other useful information.
Definition: Collection.cpp:30
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Definition: Collection.cpp:44
bool is_false(void) const
Determines if the value of the collection is false.
Definition: Collection.cpp:88
bool is_true(void) const
Determines if all values in the collection are true.
Definition: Collection.cpp:60
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: Collection.cpp:93
constexpr string_t string