-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.cpp
83 lines (69 loc) · 1.63 KB
/
group.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "group.h"
#include <memory>
Group::Group()
: Light(-1, "", true, 200, 0, 0, false, true)
{
}
void Group::setOn(bool on)
{
Light::setOn(on);
for(auto i = lights_.begin(); i != lights_.end(); i++){
auto l = (*i).lock();
if(!l) continue;
l->setOn(on);
}
}
void Group::setBri(double bri)
{
Light::setBri(bri);
for(auto i = lights_.begin(); i != lights_.end(); i++){
auto l = (*i).lock();
if(!l) continue;
l->setBri(bri);
}
}
void Group::setSat(double sat)
{
Light::setSat(sat);
for(auto i = lights_.begin(); i != lights_.end(); i++){
auto l = (*i).lock();
if(!l) continue;
l->setSat(sat);
}
}
void Group::setHue(double hue)
{
Light::setHue(hue);
for(auto i = lights_.begin(); i != lights_.end(); i++){
auto l = (*i).lock();
if(!l) continue;
l->setHue(hue);
}
}
void Group::setIsAmbi(bool isAmbi)
{
Light::setIsAmbi(isAmbi);
for(auto i = lights_.begin(); i != lights_.end(); i++){
auto l = (*i).lock();
if(!l) continue;
l->setIsAmbi(isAmbi);
}
}
void Group::addLight(std::shared_ptr<Group> group, std::shared_ptr<Light> light){
group->lights().push_back(light);
light->setParentGroup(std::weak_ptr<Group>(group));
}
void Group::removeLight(int index) {
auto l = lights_.at(index).lock();
if(!l) return;
l->setParentGroup(std::weak_ptr<Group>());
lights_.erase(lights_.begin()+index);
}
std::vector<std::weak_ptr<Light> > Group::lights() const
{
return lights_;
}
std::vector<std::weak_ptr<Light> > &Group::lights()
{
return lights_;
}