Lumiverse  2.5
A framework for creating lighting control applications
DeviceSet.h
Go to the documentation of this file.
1 
4 #ifndef _DEVICESET_H_
5 #define _DEVICESET_H_
6 
7 #pragma once
8 
9 #include <sstream>
10 #include <set>
11 #include <regex>
12 #include <functional>
13 
14 #include "Logger.h"
15 #include "Device.h"
16 #include "Rig.h"
17 
18 namespace Lumiverse {
19  class Rig;
20  class LumiverseType;
21 
41  class DeviceSet
42  {
43  public:
52  DeviceSet() { };
53 
60  DeviceSet(Rig* rig);
61 
70  DeviceSet(Rig* rig, set<Device *> devices);
71 
75  DeviceSet(Rig* rig, JSONNode node);
76 
82  DeviceSet(const DeviceSet& dc);
83 
87  ~DeviceSet();
88 
96  std::ostream & operator<< (std::ostream &str) {
97  str << info();
98  return str;
99  };
100 
109  DeviceSet select(string selector);
110 
111  private:
112  // Grouped here for convenience
113 
127  DeviceSet parseSelector(string selector, bool filter);
128 
139  DeviceSet parseMetadataSelector(string selector, bool filter);
140 
151  DeviceSet parseChannelSelector(string selector, bool filter);
152 
164  DeviceSet parseParameterSelector(string selector, bool filter);
165 
182  DeviceSet parseFloatParameter(string param, string op, float val, bool filter, bool eq);
183 
184  public:
190  DeviceSet add(Device* device);
191 
197  DeviceSet add(unsigned int channel);
198 
205  DeviceSet add(unsigned int lower, unsigned int upper);
206 
207 
220  DeviceSet add(string key, string val, bool isEqual);
221 
236  DeviceSet add(string key, regex val, bool isEqual);
237 
252  DeviceSet add(string key, LumiverseType* val, function<bool(LumiverseType* a, LumiverseType* b)> cmp, bool isEqual);
253 
261  DeviceSet add(string query);
262 
268  DeviceSet add(DeviceSet set);
269 
275  DeviceSet remove(Device* device);
276 
282  DeviceSet remove(unsigned int channel);
283 
290  DeviceSet remove(unsigned int lower, unsigned int upper);
291 
304  DeviceSet remove(string key, string val, bool isEqual);
305 
306 
321  DeviceSet remove(string key, regex val, bool isEqual);
322 
337  DeviceSet remove(string key, LumiverseType* val, function<bool(LumiverseType* a, LumiverseType* b)> cmp, bool isEqual);
338 
346  DeviceSet remove(string query);
347 
353  DeviceSet remove(DeviceSet set);
354 
355  // Inverts the selection.
356  //DeviceSet invert();
357 
362  void reset();
363 
364  // These must mirror the device setparam functions.
365 
375  void setParam(string param, float val);
376 
387  void setParam(string param, string val, float val2 = -1.0f);
388 
400  void setParam(string param, string channel, double val);
401 
407  void setParam(string param, string val, float val2, LumiverseEnum::Mode mode, LumiverseEnum::InterpolationMode interpMode);
408 
420  void setParam(string param, double x, double y, double weight = 1.0);
421 
429  void setColorRGBRaw(string param, double r, double g, double b, double weight = 1.0);
430 
436  void setRGBRaw(double r, double g, double b, double weight = 1.0);
437 
441  void setIntensity(float val) { setParam("intensity", val); }
442 
448  void setColorRGB(string param, double r, double g, double b, double weight = 1.0, RGBColorSpace cs = sRGB);
449 
453  void setColorHSV(string param, double H, double S, double V, double weight = 1.0);
454 
458  void setColorWeight(string param, double weight);
459 
466  void setMetadata(string key, string val);
467 
473  inline const set<Device *>& getDevices() { return m_workingSet; }
474 
478  vector<string> getIds();
479 
485  set<string> getAllParams();
486 
490  set<string> getAllMetadata();
491 
495  set<string> getAllMetadataForKey(string key);
496 
503  string info();
504 
509  inline size_t size() { return m_workingSet.size(); }
510 
519  bool hasSameIds(DeviceSet& devices);
520 
528  bool hasSameDevices(DeviceSet& devices);
529 
533  void clear() { m_workingSet.clear(); }
534 
541  bool contains(Device* d);
542 
549  bool contains(string id);
550 
558  JSONNode toJSON(string name);
559 
560  private:
567  void addDevice(Device* device);
568 
575  void removeDevice(Device* device);
576 
583  void addSet(DeviceSet otherSet);
584 
591  void removeSet(DeviceSet otherSet);
592 
596  set<Device *> m_workingSet;
597 
602  };
603 }
604 
605 #endif
Represents a physical lighting Device in Lumiverse.
bool hasSameIds(DeviceSet &devices)
Returns true if the device sets have the same number of devices and contain the same set of IDs...
Definition: DeviceSet.cpp:655
vector< string > getIds()
Gets a copy of the list of the IDs contained by this DeviceSet.
Definition: DeviceSet.cpp:593
void setColorRGB(string param, double r, double g, double b, double weight=1.0, RGBColorSpace cs=sRGB)
Sets the value of a LumiverseColor parameter.
Definition: DeviceSet.cpp:565
The Rig contains information about the state of the lighting system.
This class is a wapper around a variety of different possible data types that might be needed by a De...
Definition: LumiverseType.h:33
string info()
Returns a string containing info about the DeviceSet.
Definition: DeviceSet.cpp:640
DeviceSet parseChannelSelector(string selector, bool filter)
Processes a channel selector.
Definition: DeviceSet.cpp:191
void setParam(string param, float val)
Sets the value of a LumiverseFloat parameter on every device in the group.
Definition: DeviceSet.cpp:511
void setColorRGBRaw(string param, double r, double g, double b, double weight=1.0)
Sets the value of a LumiverseColor parameter.
Definition: DeviceSet.cpp:551
void clear()
Removes all devices from the device set.
Definition: DeviceSet.h:533
const set< Device * > & getDevices()
Gets the devices managed by this set.
Definition: DeviceSet.h:473
Definition: LumiverseColorLib.h:30
void setColorHSV(string param, double H, double S, double V, double weight=1.0)
Sets the value of a LumiverseColor parameter using HSV.
Definition: DeviceSet.cpp:573
RGBColorSpace
Selects a RGB color space to use in color conversion functions.
Definition: LumiverseColorLib.h:29
A DeviceSet is a set of devices.
Definition: DeviceSet.h:41
bool hasSameDevices(DeviceSet &devices)
Returns true if the device sets have the same number of devices and point to the same Devices...
Definition: DeviceSet.cpp:668
DeviceSet parseMetadataSelector(string selector, bool filter)
Processes a metadata selector.
Definition: DeviceSet.cpp:142
DeviceSet add(Device *device)
Adds a Device to the set.
Definition: DeviceSet.cpp:318
Rig * m_rig
Pointer to the rig for accessing indexes and devices.
Definition: DeviceSet.h:601
InterpolationMode
Sets the interpolation mode when transitioning between two LumiverseEnums.
Definition: LumiverseEnum.h:71
DeviceSet parseParameterSelector(string selector, bool filter)
Processes a parameter selector.
Definition: DeviceSet.cpp:250
void addSet(DeviceSet otherSet)
Adds a set to the current set.
Definition: DeviceSet.cpp:501
void reset()
Resets all the parameters in each Device in the device set.
Definition: DeviceSet.cpp:485
void removeDevice(Device *device)
Removes from the set without returning a new copy.
Definition: DeviceSet.cpp:497
set< string > getAllParams()
Gets a copy of the set of all the parameters used by devices in this set.
Definition: DeviceSet.cpp:603
Contains functions for logging information to console or file.
DeviceSet parseFloatParameter(string param, string op, float val, bool filter, bool eq)
Processes a float parameter selector.
Definition: DeviceSet.cpp:285
set< string > getAllMetadata()
Gets a copy of the set of all the metadata keys used by devices in this set.
Definition: DeviceSet.cpp:615
int cmp(LumiverseType *lhs, LumiverseType *rhs)
Compares two LumiverseType objects.
Definition: LumiverseTypeUtils.cpp:60
Mode
When you select an enumeration, mode determines where in the range the calculated value will fall...
Definition: LumiverseEnum.h:56
void setRGBRaw(double r, double g, double b, double weight=1.0)
Sets the value of a LumiverseColor paramter.
Definition: DeviceSet.cpp:559
std::ostream & operator<<(std::ostream &str)
Override for steam output.
Definition: DeviceSet.h:96
~DeviceSet()
Destructor for the DeviceSet.
Definition: DeviceSet.cpp:27
DeviceSet()
Constructs a DeviceSet unassociated with a Rig.
Definition: DeviceSet.h:52
set< Device * > m_workingSet
Set of devices currently contained in the Deviceset.
Definition: DeviceSet.h:596
bool contains(Device *d)
Checks to see if a device is in the device set.
Definition: DeviceSet.cpp:680
void setColorWeight(string param, double weight)
Sets the weight of a LumiverseColor parameter.
Definition: DeviceSet.cpp:580
DeviceSet select(string selector)
Get devices matching a query from the Rig.
Definition: DeviceSet.cpp:31
JSONNode toJSON(string name)
Saves the device set as a JSON object with the given name.
Definition: DeviceSet.cpp:693
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
The Rig contains information about the state of the lighting system.
Definition: Rig.h:58
void removeSet(DeviceSet otherSet)
Removes a set from the current set.
Definition: DeviceSet.cpp:505
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
set< string > getAllMetadataForKey(string key)
Gets a copy of the set of all metadata values used by a particular key.
Definition: DeviceSet.cpp:627
void addDevice(Device *device)
Adds to the set without returning a new copy.
Definition: DeviceSet.cpp:491
size_t size()
Returns the number of devices in the DeviceSet.
Definition: DeviceSet.h:509
void setIntensity(float val)
Proxy for setParam("intensity", val). Assumes the existence of an "intensity" parameter.
Definition: DeviceSet.h:441
DeviceSet parseSelector(string selector, bool filter)
Parses a single selector.
Definition: DeviceSet.cpp:109
void setMetadata(string key, string val)
Sets the metadata for the given key-value pair for all devices in the DeviceSet.
Definition: DeviceSet.cpp:587