Lumiverse  2.5
A framework for creating lighting control applications
LumiverseEnum.h
Go to the documentation of this file.
1 
4 #ifndef _LUMIVERSEENUM_
5 #define _LUMIVERSEENUM_
6 
7 #pragma once
8 
9 #include "../LumiverseType.h"
10 #include <map>
11 #include <memory>
12 #include <mutex>
13 #include <vector>
14 
15 namespace Lumiverse {
44  {
45  public:
56  enum Mode {
60  };
61 
72  SNAP,
80  };
81 
92  LumiverseEnum(Mode mode = CENTER, int rangeMax = 255, InterpolationMode interpMode = SMOOTH_WITHIN_OPTION);
93 
105  LumiverseEnum(map<string, int> keys, Mode mode = CENTER, int rangeMax = 255, string def = "", InterpolationMode interpMode = SMOOTH_WITHIN_OPTION);
106 
120  LumiverseEnum(map<string, int> keys, string mode, string interpMode, int rangeMax = 255, string def = "");
121 
127 
132  LumiverseEnum(const LumiverseEnum& other);
133 
142 
146  ~LumiverseEnum();
147 
152  virtual string getTypeName() { return "enum"; }
153 
157  virtual void reset();
158 
159  // Returns this object as a JSON node
160  virtual JSONNode toJSON(string name);
161 
167  virtual string asString();
168 
176  void addVal(string name, int start);
177 
185  void removeVal(string name);
186 
195  bool setVal(string name);
196 
206  bool setVal(string name, float tweak);
207 
215  bool setVal(string name, float tweak, Mode enumMode, InterpolationMode interpMode);
216 
224  bool setVal(float val);
225 
232  void setTweak(float tweak);
233 
242  void setDefault(string name) { m_default = name; }
243 
248  string getVal() { return m_active; }
249 
253  int getValIndex() { return m_nameToStart[m_active]; }
254 
259  float getTweak() { return m_tweak; }
260 
265  string getDefault() { return m_default; }
266 
271  void setMode(Mode mode) { m_mode = mode; }
272 
277  Mode getMode() { return m_mode; }
278 
284 
290 
294  int getRangeMax() { return m_rangeMax; }
295 
301  void setRangeMax(int newMax) { m_rangeMax = newMax; }
302 
316  shared_ptr<LumiverseType> lerp(LumiverseEnum* rhs, float t);
317 
323  float getRangeVal();
324 
329 
336  float asPercent();
337 
338  // Operator overrides woo
339  void operator=(string name);
340  void operator=(const LumiverseEnum& val);
341 
345  virtual bool isDefault();
346 
352  vector<string> getVals();
353 
357  const map<string, int>& getValsToStart() { return m_nameToStart; }
358 
362  const map<int, string>& getStartToVals() { return m_startToName; }
363 
370  int getHighestStartValue();
371 
375  int getLowestStartValue();
376 
377  private:
384  void init(map<string, int> keys, string active, Mode mode, string def,
385  float tweak, int rangeMax, InterpolationMode interpMode);
386 
401  void init(map<string, int> keys, string active, Mode mode, string def,
402  float tweak, int rangeMax, InterpolationMode interpMode, map<int, string> vals);
403 
407  void setTweakWithMode();
408 
415  string modeAsString();
416 
424  Mode stringToMode(string input);
425 
432  string interpModeAsString();
433 
443 
445  string m_active;
446 
448  string m_default;
449 
455  map<string, int> m_nameToStart;
456 
458  map<int, string> m_startToName;
459 
462 
465 
473  float m_tweak;
474 
482 
486  };
487 
488  // Ops time
489 
496  inline bool operator==(LumiverseEnum& a, LumiverseEnum& b) {
497  if (a.getTypeName() != "enum" || b.getTypeName() != "enum")
498  return false;
499 
500  return (a.getVal() == b.getVal() && a.getTweak() == b.getTweak());
501  }
502 
503  inline bool operator!=(LumiverseEnum& a, LumiverseEnum& b) {
504  return !(a == b);
505  }
506 
513  inline bool operator<(LumiverseEnum& a, LumiverseEnum& b) {
514  if (a.getTypeName() != "enum" || b.getTypeName() != "enum")
515  return false;
516 
517  return a.getRangeVal() < b.getRangeVal();
518  }
519 
521  inline bool operator>(LumiverseEnum& a, LumiverseEnum& b) {
522  return b < a;
523  }
524 
526  inline bool operator<=(LumiverseEnum& a, LumiverseEnum& b) {
527  return !(a > b);
528  }
529 
531  inline bool operator>=(LumiverseEnum& a, LumiverseEnum& b) {
532  return !(a < b);
533  }
534 
535  // Arithmetic overrides will be a little complicated or non-existant as an enum.
536 }
537 
538 #endif
float asPercent()
Gets the value of the enum in terms of a percentage.
Definition: LumiverseEnum.cpp:308
Definition: LumiverseEnum.h:79
Defines an enumeration in Lumiverse.
Definition: LumiverseEnum.h:43
void setInterpMode(InterpolationMode mode)
Sets the interpolation mode.
Definition: LumiverseEnum.h:283
InterpolationMode stringToInterpMode(string input)
Converts a string to an interpolation mode.
Definition: LumiverseEnum.cpp:372
int m_rangeMax
Maximum value for the enumeration range.
Definition: LumiverseEnum.h:481
Definition: LumiverseEnum.h:72
Definition: LumiverseEnum.h:58
float m_tweak
Tweak determines where in the range we are.
Definition: LumiverseEnum.h:473
void setTweak(float tweak)
Tweaks the value of the enum.
Definition: LumiverseEnum.cpp:204
This class is a wapper around a variety of different possible data types that might be needed by a De...
Definition: LumiverseType.h:33
map< int, string > m_startToName
Maps the start of a range to the name of the enumeration option.
Definition: LumiverseEnum.h:458
map< string, int > m_nameToStart
Map of the name of the enumeration option to the start of the range.
Definition: LumiverseEnum.h:455
void setDefault(string name)
Sets the default value of the enumeration.
Definition: LumiverseEnum.h:242
Mode getMode()
Returns the mode.
Definition: LumiverseEnum.h:277
void setRangeMax(int newMax)
Sets the maximum numeric value this LumiverseEnum can take.
Definition: LumiverseEnum.h:301
int getLowestStartValue()
Gets the lowest start value for an enumeration option.
Definition: LumiverseEnum.cpp:300
float getTweak()
Gets the tweak value for the enumeration.
Definition: LumiverseEnum.h:259
Definition: LumiverseEnum.h:59
string modeAsString()
Returns the current mode as a string.
Definition: LumiverseEnum.cpp:331
float getRangeVal()
Returns the exact value in the range given the active parameter and the tweak value.
Definition: LumiverseEnum.cpp:210
InterpolationMode
Sets the interpolation mode when transitioning between two LumiverseEnums.
Definition: LumiverseEnum.h:71
virtual bool isDefault()
Returns true if the current value of the enumeration is equal to the default.
Definition: LumiverseEnum.cpp:276
virtual void reset()
Resets the enum to default.
Definition: LumiverseEnum.cpp:88
string getVal()
Gets the current state of the enumeration.
Definition: LumiverseEnum.h:248
vector< string > getVals()
Gets a list of all the possible values the enumeration can take.
Definition: LumiverseEnum.cpp:284
void setValAsPercent(float val)
Sets the value of the LumiverseFloat proportionally.
Definition: LumiverseEnum.h:328
virtual string getTypeName()
Says that this object is an enum.
Definition: LumiverseEnum.h:152
Definition: LumiverseEnum.h:57
InterpolationMode getInterpMode()
Returns the interpolation mode.
Definition: LumiverseEnum.h:289
~LumiverseEnum()
Destructor fun times.
Definition: LumiverseEnum.cpp:84
shared_ptr< LumiverseType > lerp(LumiverseEnum *rhs, float t)
Does a linear interpolation based on the interpolation mode.
Definition: LumiverseEnum.cpp:226
const map< int, string > & getStartToVals()
Returns a reference to the map of range starts to values.
Definition: LumiverseEnum.h:362
void removeVal(string name)
Removes an option from the enumeration.
Definition: LumiverseEnum.cpp:131
string interpModeAsString()
Returns the interpolation mode as a string.
Definition: LumiverseEnum.cpp:357
bool setVal(string name)
Sets the value of the enumeration.
Definition: LumiverseEnum.cpp:139
Mode
When you select an enumeration, mode determines where in the range the calculated value will fall...
Definition: LumiverseEnum.h:56
int getValIndex()
Gets the first value in the active range.
Definition: LumiverseEnum.h:253
int getRangeMax()
Returns the maximum numeric value this LumiverseEnum can take.
Definition: LumiverseEnum.h:294
string getDefault()
Gets the default value.
Definition: LumiverseEnum.h:265
string m_active
The active enumeration option.
Definition: LumiverseEnum.h:445
void setMode(Mode mode)
Sets the mode.
Definition: LumiverseEnum.h:271
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
virtual JSONNode toJSON(string name)
Converts the type to a JSON object with the specified name.
Definition: LumiverseEnum.cpp:92
void setTweakWithMode()
Sets the tweak value based on the mode.
Definition: LumiverseEnum.cpp:313
mutex m_enumMapMutex
Protects the access of the m_nameToStart and m_startToName maps during assignment and read (can't mod...
Definition: LumiverseEnum.h:485
void init(map< string, int > keys, string active, Mode mode, string def, float tweak, int rangeMax, InterpolationMode interpMode)
Initializes the enumeration. Called from constructors.
Definition: LumiverseEnum.cpp:55
string m_default
The default option for the enumeration.
Definition: LumiverseEnum.h:448
void addVal(string name, int start)
Adds an option to the enumeration.
Definition: LumiverseEnum.cpp:121
Mode stringToMode(string input)
Converts a string to a mode.
Definition: LumiverseEnum.cpp:346
LumiverseEnum(Mode mode=CENTER, int rangeMax=255, InterpolationMode interpMode=SMOOTH_WITHIN_OPTION)
Constructs an enumeration with nothing in it.
Definition: LumiverseEnum.cpp:4
int getHighestStartValue()
Gets the highest start value for an enumeration option.
Definition: LumiverseEnum.cpp:292
Mode m_mode
Enumeration mode.
Definition: LumiverseEnum.h:461
const map< string, int > & getValsToStart()
Returns a reference to the map of values to the start of their range.
Definition: LumiverseEnum.h:357
InterpolationMode m_interpMode
Interpolation mode.
Definition: LumiverseEnum.h:464
virtual string asString()
Returns the current enumeration value as a string.
Definition: LumiverseEnum.cpp:115