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