Lumiverse  2.5
A framework for creating lighting control applications
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Lumiverse::DeviceSet Class Reference

A DeviceSet is a set of devices. More...

#include <DeviceSet.h>

Collaboration diagram for Lumiverse::DeviceSet:
Collaboration graph
[legend]

Public Member Functions

 DeviceSet ()
 Constructs a DeviceSet unassociated with a Rig. More...
 
 DeviceSet (Rig *rig)
 Constructs an empty set. More...
 
 DeviceSet (Rig *rig, set< Device * > devices)
 Constructs a set with the given devices. More...
 
 DeviceSet (Rig *rig, JSONNode node)
 Constructs a DeviceSet from a JSON node and a given Rig.
 
 DeviceSet (const DeviceSet &dc)
 Copy a DeviceSet. More...
 
 ~DeviceSet ()
 Destructor for the DeviceSet.
 
std::ostream & operator<< (std::ostream &str)
 Override for steam output. More...
 
DeviceSet select (string selector)
 Get devices matching a query from the Rig. More...
 
DeviceSet add (Device *device)
 Adds a Device to the set. More...
 
DeviceSet add (unsigned int channel)
 Adds Devices in the specified channel to the set. More...
 
DeviceSet add (unsigned int lower, unsigned int upper)
 Adds Devices in the specified inclusive channel range to the set. More...
 
DeviceSet add (string key, string val, bool isEqual)
 Adds Devices matching the specified metadata value to the set. More...
 
DeviceSet add (string key, regex val, bool isEqual)
 Adds Devices matching the specified metadata value to the set. More...
 
DeviceSet add (string key, LumiverseType *val, function< bool(LumiverseType *a, LumiverseType *b)> cmp, bool isEqual)
 Adds devices based on a parameter comparison function provided by the caller. More...
 
DeviceSet add (string query)
 Adds devices based on a query string. More...
 
DeviceSet add (DeviceSet set)
 Adds devices from another set. More...
 
DeviceSet remove (Device *device)
 Removes a device from the set. More...
 
DeviceSet remove (unsigned int channel)
 Removes Devices in the specified channel from the set. More...
 
DeviceSet remove (unsigned int lower, unsigned int upper)
 Removes Devices in the specified inclusive channel range from the set. More...
 
DeviceSet remove (string key, string val, bool isEqual)
 Removes Devices matching the specified metadata value to the set. More...
 
DeviceSet remove (string key, regex val, bool isEqual)
 Removes Devices matching the specified metadata value from the set. More...
 
DeviceSet remove (string key, LumiverseType *val, function< bool(LumiverseType *a, LumiverseType *b)> cmp, bool isEqual)
 Removes devices based on a parameter comparison function provided by the caller. More...
 
DeviceSet remove (string query)
 Removes devices based on a query string. More...
 
DeviceSet remove (DeviceSet set)
 Removes devices contained in another set from this set. More...
 
void reset ()
 Resets all the parameters in each Device in the device set. More...
 
void setParam (string param, float val)
 Sets the value of a LumiverseFloat parameter on every device in the group. More...
 
void setParam (string param, string val, float val2=-1.0f)
 Sets the value of a LumiverseEnum parameter on every device in the group. More...
 
void setParam (string param, string channel, double val)
 Sets the value of a LumiverseColor parameter. More...
 
void setParam (string param, string val, float val2, LumiverseEnum::Mode mode, LumiverseEnum::InterpolationMode interpMode)
 Sets the value of a LumiverseEnum parameter. More...
 
void setParam (string param, double x, double y, double weight=1.0)
 Sets the value of a LumiverseColor parameter using LumiverseColor::setxy() More...
 
void setColorRGBRaw (string param, double r, double g, double b, double weight=1.0)
 Sets the value of a LumiverseColor parameter. More...
 
void setRGBRaw (double r, double g, double b, double weight=1.0)
 Sets the value of a LumiverseColor paramter. More...
 
void setIntensity (float val)
 Proxy for setParam("intensity", val). Assumes the existence of an "intensity" parameter.
 
void setColorRGB (string param, double r, double g, double b, double weight=1.0, RGBColorSpace cs=sRGB)
 Sets the value of a LumiverseColor parameter. More...
 
void setColorHSV (string param, double H, double S, double V, double weight=1.0)
 Sets the value of a LumiverseColor parameter using HSV.
 
void setColorWeight (string param, double weight)
 Sets the weight of a LumiverseColor parameter.
 
void setMetadata (string key, string val)
 Sets the metadata for the given key-value pair for all devices in the DeviceSet. More...
 
const set< Device * > & getDevices ()
 Gets the devices managed by this set. More...
 
vector< string > getIds ()
 Gets a copy of the list of the IDs contained by this DeviceSet.
 
set< string > getAllParams ()
 Gets a copy of the set of all the parameters used by devices in this set. More...
 
set< string > getAllMetadata ()
 Gets a copy of the set of all the metadata keys used by devices in this set.
 
set< string > getAllMetadataForKey (string key)
 Gets a copy of the set of all metadata values used by a particular key.
 
string info ()
 Returns a string containing info about the DeviceSet. More...
 
size_t size ()
 Returns the number of devices in the DeviceSet. More...
 
bool hasSameIds (DeviceSet &devices)
 Returns true if the device sets have the same number of devices and contain the same set of IDs. More...
 
bool hasSameDevices (DeviceSet &devices)
 Returns true if the device sets have the same number of devices and point to the same Devices. More...
 
void clear ()
 Removes all devices from the device set.
 
bool contains (Device *d)
 Checks to see if a device is in the device set. More...
 
bool contains (string id)
 Checks to see if a device is in the device set. More...
 
JSONNode toJSON (string name)
 Saves the device set as a JSON object with the given name. More...
 

Private Member Functions

DeviceSet parseSelector (string selector, bool filter)
 Parses a single selector. More...
 
DeviceSet parseMetadataSelector (string selector, bool filter)
 Processes a metadata selector. More...
 
DeviceSet parseChannelSelector (string selector, bool filter)
 Processes a channel selector. More...
 
DeviceSet parseParameterSelector (string selector, bool filter)
 Processes a parameter selector. More...
 
DeviceSet parseFloatParameter (string param, string op, float val, bool filter, bool eq)
 Processes a float parameter selector. More...
 
void addDevice (Device *device)
 Adds to the set without returning a new copy. More...
 
void removeDevice (Device *device)
 Removes from the set without returning a new copy. More...
 
void addSet (DeviceSet otherSet)
 Adds a set to the current set. More...
 
void removeSet (DeviceSet otherSet)
 Removes a set from the current set. More...
 

Private Attributes

set< Device * > m_workingSet
 Set of devices currently contained in the Deviceset.
 
Rigm_rig
 Pointer to the rig for accessing indexes and devices.
 

Detailed Description

A DeviceSet is a set of devices.

More specifically, a DeviceSet is the set resulting from a particular query or series of filtering operations. These devices can be manupulated by setting properties as a group, further filtering them, adding devices, etc. DeviceSets are returned by the Rig when asking for more than one device. Device sets can be filtered in chains, as each filtering operation will return a new DeviceSet: rig.getDevices("angle", "back", true).remove("area", "3", true) ... etc. Returning a new set after each operation may use more memory, but it does allow for the construction of a query history and saving of that query during any point of its construction. This history is currently not saved, but may in the future be part of this class. Alternately, DeviceSets can be constructed from concise queries: https://github.com/ebshimizu/Lumiverse/wiki/Query-Syntax-Notes

See also
Device

Constructor & Destructor Documentation

Lumiverse::DeviceSet::DeviceSet ( )
inline

Constructs a DeviceSet unassociated with a Rig.

It should be noted that this constructor actually isn't particularly useful. Without a Rig*, the DeviceSet can't really do any sort of queries, though it can store an arbitrary list of deivces.

See also
DeviceSet(Rig*), DeviceSet(const DeviceSet&)
Lumiverse::DeviceSet::DeviceSet ( Rig rig)

Constructs an empty set.

Parameters
rigPointer to a Rig to get devices from.
See also
DeviceSet(Rig*, set<Device *>), select(string), Rig
Lumiverse::DeviceSet::DeviceSet ( Rig rig,
set< Device * >  devices 
)

Constructs a set with the given devices.

Similar to a copy constructor.

Parameters
rigPointer to a Rig to get devices from.
devicesList of Device pointers to initialize the set with.
See also
DeviceSet(Rig*), Device, Rig, select(string)
Lumiverse::DeviceSet::DeviceSet ( const DeviceSet dc)

Copy a DeviceSet.

Parameters
dcDeviceSet to copy data from

Member Function Documentation

DeviceSet Lumiverse::DeviceSet::add ( Device device)

Adds a Device to the set.

Parameters
devicePointer to the Device to add.
Returns
DeviceSet containing its current contents plus the added Device.
DeviceSet Lumiverse::DeviceSet::add ( unsigned int  channel)

Adds Devices in the specified channel to the set.

Parameters
channelThe channel to add to the DeviceSet
Returns
DeviceSet containing its current contents plus the added Devices.
DeviceSet Lumiverse::DeviceSet::add ( unsigned int  lower,
unsigned int  upper 
)

Adds Devices in the specified inclusive channel range to the set.

Parameters
lowerFirst channel in the range (inclusive)
upperLast channel in the range (inclusive)
Returns
DeviceSet containing its current contents plus the added Devices.
DeviceSet Lumiverse::DeviceSet::add ( string  key,
string  val,
bool  isEqual 
)

Adds Devices matching the specified metadata value to the set.

If a Device does not have a value for the key specified, it will not be included in the set even if isEqual is set to false.

Parameters
keyMetadata field to look at
valTarget value of the metadata field
isEqualIf true, the Devices matching the metadata value will be added. If false, devices that don't match the metadata value will be added.
Returns
DeviceSet containing its current contents plus the added Devices.
See also
add(string, regex, bool)
DeviceSet Lumiverse::DeviceSet::add ( string  key,
regex  val,
bool  isEqual 
)

Adds Devices matching the specified metadata value to the set.

Regex version of the normal metadata add. If a Device does not have a value for the key specified, it will not be included in the set even if isEqual is set to false.

Parameters
keyMetadata field to look at
valTarget value of the metadata field. Since this is a std::regex, it is possible to search for metadata using all of the nice regex features you're used to.
isEqualIf true, the Devices matching the metadata value will be added. If false, devices that don't match the metadata value will be added.
Returns
DeviceSet containing its current contents plus the added Devices.
See also
add(string, string, bool)
DeviceSet Lumiverse::DeviceSet::add ( string  key,
LumiverseType val,
function< bool(LumiverseType *a, LumiverseType *b)>  cmp,
bool  isEqual 
)

Adds devices based on a parameter comparison function provided by the caller.

One of the more complicated add functions, this one adds devices based on a user-specified comparison function between two LumiverseType pointers. It is up to the user to make sure these types are the same to ensure a good comparison is made.

Parameters
keyParameter to look at
valTarget parameter value
cmpComparison function
isEqualIf true, the Devices matching the metadata value will be added. If false, devices that don't match the metadata value will be added.
Returns
DeviceSet containing its current contents plus the added Devices.
See also
LumiverseType, LumiverseTypeUtils
DeviceSet Lumiverse::DeviceSet::add ( string  query)

Adds devices based on a query string.

Typically you'd just use the select() function for this.

Parameters
queryQuery string
Returns
DeviceSet containing its current contents plus the added Devices.
DeviceSet Lumiverse::DeviceSet::add ( DeviceSet  set)

Adds devices from another set.

Parameters
setThe other set of devices
void Lumiverse::DeviceSet::addDevice ( Device device)
private

Adds to the set without returning a new copy.

Internal use only.

Parameters
deviceDevice to add to the set
void Lumiverse::DeviceSet::addSet ( DeviceSet  otherSet)
private

Adds a set to the current set.

Internal set opration. Equivalent to a union.

Parameters
otherSetThe set to add to the DeviceSet.
bool Lumiverse::DeviceSet::contains ( Device d)

Checks to see if a device is in the device set.

This version of the contains function takes a pointer and checks to see if the exact same device is in the set. This function is faster than contains(string).

bool Lumiverse::DeviceSet::contains ( string  id)

Checks to see if a device is in the device set.

This version of the contains function takes a device ID and checks if a device with the same id is in the set.

set< string > Lumiverse::DeviceSet::getAllParams ( )

Gets a copy of the set of all the parameters used by devices in this set.

Set means no duplicates

const set<Device *>& Lumiverse::DeviceSet::getDevices ( )
inline

Gets the devices managed by this set.

Returns
Set of Device* contained by the DeviceSet
bool Lumiverse::DeviceSet::hasSameDevices ( DeviceSet devices)

Returns true if the device sets have the same number of devices and point to the same Devices.

This actually just checks to see if the pointers in the set of devices managed by the device set are pointing to the same things.

bool Lumiverse::DeviceSet::hasSameIds ( DeviceSet devices)

Returns true if the device sets have the same number of devices and contain the same set of IDs.

Note that even if this returns true, the device sets could refer to different objects, as they store pointers to the devices they contain. This function is currently very slow.

string Lumiverse::DeviceSet::info ( )

Returns a string containing info about the DeviceSet.

Returns
DeviceSet as a string. String contains the number of devices contained by the set and the IDs of each device in the set.
std::ostream& Lumiverse::DeviceSet::operator<< ( std::ostream &  str)
inline

Override for steam output.

Converts DeviceSet to a string representation and outputs it to a stream.

Returns
ostream object containing the DeviceSet string appended to it.
See also
info()
DeviceSet Lumiverse::DeviceSet::parseChannelSelector ( string  selector,
bool  filter 
)
private

Processes a channel selector.

Helper for parseSelector.

Parameters
selectorQuery string
filterIf true, indicates that devices will be filtered out of the current device set based on the result of the selector. If false, devices will be added based on the selector result.
Returns
DeviceSet containing the result of applying the channel selector to the current set.
See also
parseSelector(string, bool)
DeviceSet Lumiverse::DeviceSet::parseFloatParameter ( string  param,
string  op,
float  val,
bool  filter,
bool  eq 
)
private

Processes a float parameter selector.

Helper for parseParameterSelector.

Parameters
paramParameter name
opEquality operation. One of "<", "<=", ">", ">=, "!=". Defaults to "==" if nothing specified or if invalid option is specified.
valThe value we're testing against
filterIf true, indicates that devices will be filtered out of the current device set based on the result of the selector. If false, devices will be added based on the selector result.
eqIf set to false, this function will add everything that does not satisfy the selector. It essentially inverts the query. For example, if you have @intensity < .50 as the query with eq = false, the returned set will contain @intensity >= .5. This parameter is intended for internal use only.
Returns
DeviceSet containing the result of applying the channel selector to the current set.
See also
parseParameterSelector(string, bool)
DeviceSet Lumiverse::DeviceSet::parseMetadataSelector ( string  selector,
bool  filter 
)
private

Processes a metadata selector.

Helper for parseSelector.

Parameters
selectorQuery string
filterIf true, indicates that devices will be filtered out of the current device set based on the result of the selector. If false, devices will be added based on the selector result.
Returns
DeviceSet containing the result of applying the metadata selector to the current set.
See also
parseSelector(string, bool)
DeviceSet Lumiverse::DeviceSet::parseParameterSelector ( string  selector,
bool  filter 
)
private

Processes a parameter selector.

Helper for parseSelector. This part of the query is a bit difficult to parse due to LumiverseType objects actually being different types (enum, float, etc.).

Parameters
selectorQuery string
filterIf true, indicates that devices will be filtered out of the current device set based on the result of the selector. If false, devices will be added based on the selector result.
Returns
DeviceSet containing the result of applying the parameter selector to the current set.
See also
parseSelector(string, bool), parseFloatParameter(string, string, float, bool, bool)
DeviceSet Lumiverse::DeviceSet::parseSelector ( string  selector,
bool  filter 
)
private

Parses a single selector.

Redirects to appropriate functions. See implementation for details. Boolean flag determines if selected Devices are added or subtracted from the current DeviceSet.

Parameters
selectorQuery string
filterIf true, indicates that devices will be filtered out of the current device set based on the result of the selector. If false, devices will be added based on the selector result.
Returns
DeviceSet containing the result of applying the selector to the current set.
See also
parseMetadataSelector(string, bool), parseChannelSelector(string, bool), parseParameterSelector(string, bool), parseFloatParameter(string, string, float, bool, bool)
DeviceSet Lumiverse::DeviceSet::remove ( Device device)

Removes a device from the set.

Parameters
deviceDevice to remove
Returns
DeviceSet containing its current contents without the specified Device.
DeviceSet Lumiverse::DeviceSet::remove ( unsigned int  channel)

Removes Devices in the specified channel from the set.

Parameters
channelThe channel to remove from the DeviceSet
Returns
DeviceSet containing its current contents without the specified Devices.
DeviceSet Lumiverse::DeviceSet::remove ( unsigned int  lower,
unsigned int  upper 
)

Removes Devices in the specified inclusive channel range from the set.

Parameters
lowerFirst channel in the range (inclusive)
upperLast channel in the range (inclusive)
Returns
DeviceSet containing its current contents without the specified Devices..
DeviceSet Lumiverse::DeviceSet::remove ( string  key,
string  val,
bool  isEqual 
)

Removes Devices matching the specified metadata value to the set.

If a Device does not have a value for the key specified, it will not be removed from the set even if isEqual is set to false.

Parameters
keyMetadata field to look at
valTarget value of the metadata field
isEqualIf true, the Devices matching the metadata value will be removed. If false, devices that don't match the metadata value will be removed.
Returns
DeviceSet containing its current contents without the specified Devices.
See also
remove(string, regex, bool)
DeviceSet Lumiverse::DeviceSet::remove ( string  key,
regex  val,
bool  isEqual 
)

Removes Devices matching the specified metadata value from the set.

Regex version of the normal metadata remove. If a Device does not have a value for the key specified, it will not be removed from the set even if isEqual is set to false.

Parameters
keyMetadata field to look at
valTarget value of the metadata field. Since this is a std::regex, it is possible to search for metadata using all of the nice regex features you're used to.
isEqualIf true, the Devices matching the metadata value will be removed. If false, devices that don't match the metadata value will be removed.
Returns
DeviceSet containing its current contents without the specified Devices.
See also
remove(string, string, bool)
DeviceSet Lumiverse::DeviceSet::remove ( string  key,
LumiverseType val,
function< bool(LumiverseType *a, LumiverseType *b)>  cmp,
bool  isEqual 
)

Removes devices based on a parameter comparison function provided by the caller.

One of the more complicated remove functions, this one removes devices based on a user-specified comparison function between two LumiverseType pointers. It is up to the user to make sure these types are the same to ensure a good comparison is made.

Parameters
keyParameter to look at
valTarget parameter value
cmpComparison function
isEqualIf true, the Devices matching the metadata value will be removed. If false, devices that don't match the metadata value will be removed.
Returns
DeviceSet containing its current contents without the specified Devices.
See also
LumiverseType, LumiverseTypeUtils
DeviceSet Lumiverse::DeviceSet::remove ( string  query)

Removes devices based on a query string.

All Devices matching the query string and are in the DeviceSet, will be removed.

Parameters
queryQuery string
Returns
DeviceSet containing its current contents wihtout the specified Devices.
DeviceSet Lumiverse::DeviceSet::remove ( DeviceSet  set)

Removes devices contained in another set from this set.

Parameters
setSet of devices to remove from this set.
void Lumiverse::DeviceSet::removeDevice ( Device device)
private

Removes from the set without returning a new copy.

Internal use only.

Parameters
deviceDevice to remove from the set.
void Lumiverse::DeviceSet::removeSet ( DeviceSet  otherSet)
private

Removes a set from the current set.

Internal set opration. Equivalent to a set difference.

Parameters
otherSetThe set to remove fromthe DeviceSet.
void Lumiverse::DeviceSet::reset ( )

Resets all the parameters in each Device in the device set.

See also
Device::reset()
DeviceSet Lumiverse::DeviceSet::select ( string  selector)

Get devices matching a query from the Rig.

This is the primary function to select Devices from the Rig. Syntax details can be found here: https://github.com/ebshimizu/Lumiverse/wiki/Query-Syntax-Notes

Parameters
selectorQuery string.
Returns
DeviceSet containing all Device objects matching the selector
void Lumiverse::DeviceSet::setColorRGB ( string  param,
double  r,
double  g,
double  b,
double  weight = 1.0,
RGBColorSpace  cs = sRGB 
)
void Lumiverse::DeviceSet::setColorRGBRaw ( string  param,
double  r,
double  g,
double  b,
double  weight = 1.0 
)

Sets the value of a LumiverseColor parameter.

Not gonna work terribly well if you're mixing fixtures that don't have RGB for some reason in your selection. Proxy for LumiverseColor::setRGBRaw().

See also
LumiverseColor::setRGBRaw(), LumiverseColor, LumiverseType
void Lumiverse::DeviceSet::setMetadata ( string  key,
string  val 
)

Sets the metadata for the given key-value pair for all devices in the DeviceSet.

Parameters
keyMetadata key
valMetadata value
void Lumiverse::DeviceSet::setParam ( string  param,
float  val 
)

Sets the value of a LumiverseFloat parameter on every device in the group.

This function will only set the value of an existing parameter. If the parameter doesn't exist, it will not be created by this function.

Parameters
paramParameter to modify
valValue of the parameter
See also
Device::setParam(string, float)
void Lumiverse::DeviceSet::setParam ( string  param,
string  val,
float  val2 = -1.0f 
)

Sets the value of a LumiverseEnum parameter on every device in the group.

This function will only set the value of an existing parameter. If the parameter doesn't exist, it will not be created by this function.

Parameters
paramParameter to modify
valValue of the enumeration
val2The tweak value of the LumiverseEnum
See also
Device::setParam(string, string, float)
void Lumiverse::DeviceSet::setParam ( string  param,
string  channel,
double  val 
)

Sets the value of a LumiverseColor parameter.

LumiverseColors present a bit of a challenge for group selections. Every light has differen color representations, so not every function will work for every group. This function will call the corresponding set param function for each device, but not every device may react to it.

Parameters
paramParameter name
channelColor channel name
valValue of the color channel
See also
LumiverseColor, LumiverseType
void Lumiverse::DeviceSet::setParam ( string  param,
string  val,
float  val2,
LumiverseEnum::Mode  mode,
LumiverseEnum::InterpolationMode  interpMode 
)

Sets the value of a LumiverseEnum parameter.

See also
Device::setParam()
void Lumiverse::DeviceSet::setParam ( string  param,
double  x,
double  y,
double  weight = 1.0 
)

Sets the value of a LumiverseColor parameter using LumiverseColor::setxy()

x and y are chromaticity coordinates in the xyY color space. Ideally this function would be the unifying function for all devices in a Rig. However, it only works if you know the XYZ values for each color of LED in a light, and it doesn't work with CMY fixtures at the moment.

Parameters
paramParameter name.
xx coordinate
yy coordinate
See also
LumiverseColor, LumiverseType, setParam(string, string, double)
void Lumiverse::DeviceSet::setRGBRaw ( double  r,
double  g,
double  b,
double  weight = 1.0 
)

Sets the value of a LumiverseColor paramter.

Assumes the existence of a RGB "color" parameter.

size_t Lumiverse::DeviceSet::size ( )
inline

Returns the number of devices in the DeviceSet.

Returns
Number of devices in the set.
JSONNode Lumiverse::DeviceSet::toJSON ( string  name)

Saves the device set as a JSON object with the given name.

This serializes to a list of IDs that can be used to reconstruct the DeviceSet if it's given the same Rig as it currently has.

Parameters
nameNode name.

The documentation for this class was generated from the following files: