VVISF & VVGL
ISFVal.hpp
Go to the documentation of this file.
1 #ifndef ISFVal_h
2 #define ISFVal_h
3 
4 #include "VVISF_Base.hpp"
5 #include "VVISF_StringUtils.hpp"
6 
14 namespace VVISF
15 {
16 
17 
18 using namespace std;
19 
20 
25 enum ISFValType {
37 };
43 string StringFromISFValType(const ISFValType & n);
50 
51 
52 
57 struct VVISF_EXPORT ISFVal {
58  private:
59  // this union stores the value of an ISFVal (the member of the union used depends on the ISFVal's 'type' member)
60  union ISFValUnion {
61  bool boolVal;
62  int32_t longVal;
63  double floatVal;
64  double pointVal[2];
65  double colorVal[4];
66  };
68  ISFValUnion _val = { false };
69  VVGL::GLBufferRef _imageVal = nullptr; // we store the GLBufferRef as a member of the struct because storing it in the union didn't work out (a variant might work, but that has to wait to c++17)
70 
71  public:
72 
73 
77 
79  // Returns a null-type ISFVal
80  ISFVal();
81  // Returns an ISFVal with the passed type, and the default/unpopulated value for that type.
82  ISFVal(const ISFValType & inType) : _type(inType) {}
83  // Returns an ISFVal of the passed type with the passed bool value.
84  ISFVal(const ISFValType & inType, const bool & inBool);
85  // Returns an ISFVal of the passed type with the passed long value.
86  ISFVal(const ISFValType & inType, const int32_t & inLong);
87  // Returns an ISFVal of the passed type with the passed float value.
88  ISFVal(const ISFValType & inType, const double & inFloat);
89  // Returns an ISFVal of the passed type populated with the two passed values. Works well for 2d points.
90  ISFVal(const ISFValType & inType, const double & inX, const double & inY);
91  ISFVal(const ISFValType & inType, const double * inXY, const size_t inSizeToCopy);
92  // Returns an ISFVal of the passed type populated with the four passed values. Works well for colors.
93  ISFVal(const ISFValType & inType, const double & inR, const double & inG, const double & inB, const double & inA);
94  // Returns an ISFVal of the passed type with the passed image value. Works well for image-, audio-, and audioFFT-type values.
95  ISFVal(const ISFValType & inType, const VVGL::GLBufferRef & inImage);
96 
98 
99 
101 
105 
108  inline ISFValType type() const { return _type; }
110  double getDoubleVal() const;
112  bool getBoolVal() const;
114  int32_t getLongVal() const;
116  inline double * getPointValPtr() { if (_type!=ISFValType_Point2D) return nullptr; return &(_val.pointVal[0]); }
118  inline double getPointValByIndex(const int & inIndex) { if (_type!=ISFValType_Point2D || inIndex<0 || inIndex>1) return 0.; return _val.pointVal[inIndex]; }
120  inline void setPointValByIndex(const int & inIndex, const double & inVal) { if (_type!=ISFValType_Point2D || inIndex<0 || inIndex>1) return; _val.pointVal[inIndex]=inVal; }
122  inline double * getColorValPtr() { if (_type!=ISFValType_Color) return nullptr; return &(_val.colorVal[0]); }
124  inline double getColorValByChannel(const int & inIndex) { if (_type!=ISFValType_Color || inIndex<0 || inIndex>3) return 0.; return _val.colorVal[inIndex]; }
126  inline void setColorValByChannel(const int & inIndex, const double & inVal) { if (_type!=ISFValType_Color || inIndex<0 || inIndex>3) return; _val.colorVal[inIndex]=inVal; }
128  VVGL::GLBufferRef imageBuffer() const;
130  void setImageBuffer(const VVGL::GLBufferRef & n);
132  string getTypeString() const;
134  string getValString() const;
135 
137 
138 
143 
146  inline bool isNullVal() const { return (_type == ISFValType_None); }
148  inline bool isEventVal() const { return (_type == ISFValType_Event); }
150  inline bool isBoolVal() const { return (_type == ISFValType_Bool); }
152  inline bool isLongVal() const { return (_type == ISFValType_Long); }
154  inline bool isFloatVal() const { return (_type == ISFValType_Float); }
156  inline bool isPoint2DVal() const { return (_type == ISFValType_Point2D); }
158  inline bool isColorVal() const { return (_type == ISFValType_Color); }
160  inline bool isCubeVal() const { return (_type == ISFValType_Cube); }
162  inline bool isImageVal() const { return (_type == ISFValType_Image); }
164  inline bool isAudioVal() const { return (_type == ISFValType_Audio); }
166  inline bool isAudioFFTVal() const { return (_type == ISFValType_AudioFFT); }
167 
169 
170  friend ostream & operator<<(ostream & os, const ISFVal & n) { os << VVGL::FmtString("<ISFVal %s/%s>", n.getTypeString().c_str(), n.getValString().c_str()); return os; }
171 };
172 
173 
178 
184 VVISF_EXPORT ISFVal ISFNullVal();
189 VVISF_EXPORT ISFVal ISFEventVal(const bool & n=false);
194 VVISF_EXPORT ISFVal ISFBoolVal(const bool & n);
199 VVISF_EXPORT ISFVal ISFLongVal(const int32_t & n);
204 VVISF_EXPORT ISFVal ISFFloatVal(const double & n);
209 VVISF_EXPORT ISFVal ISFPoint2DVal(const double & inX, const double & inY);
214 VVISF_EXPORT ISFVal ISFColorVal(const double & inR, const double & inG, const double & inB, const double & inA);
219 VVISF_EXPORT ISFVal ISFImageVal(const VVGL::GLBufferRef & n);
220 
222 
223 
224 
225 }
226 
227 
228 #endif /* ISFVal_h */
VVISF_EXPORT ISFVal ISFPoint2DVal(const double &inX, const double &inY)
Creates and returns a 2d point-type ISFVal with the passed point values.
VVISF_EXPORT ISFVal ISFFloatVal(const double &n)
Creates and returns a float-type ISFVal with the passed value.
A boolean choice, sends 1 or 0 to the shader.
Definition: ISFVal.hpp:28
bool isAudioVal() const
Returns true if the receiver is an audio value (image).
Definition: ISFVal.hpp:164
VVISF_EXPORT ISFVal ISFBoolVal(const bool &n)
Creates and returns a boolean-type ISFVal with the passed value.
VVISF_EXPORT ISFVal ISFLongVal(const int32_t &n)
Creates and returns a long-type ISFVal with the passed value.
bool isEventVal() const
Returns true if the receiver is an event value.
Definition: ISFVal.hpp:148
Sends a 2 element vector.
Definition: ISFVal.hpp:31
bool isPoint2DVal() const
Returns true if the receiver is a point2D value.
Definition: ISFVal.hpp:156
STL namespace.
double * getColorValPtr()
Returns a null if the receiver isn&#39;t a color-type object, otherwise it returns a pointer to the four-...
Definition: ISFVal.hpp:122
Definition: ISFAttr.hpp:12
Sends a 4 element vector representing an RGBA color.
Definition: ISFVal.hpp:32
bool isLongVal() const
Returns true if the receiver is a long value.
Definition: ISFVal.hpp:152
string StringFromISFValType(const ISFValType &n)
Returns a string describing the passed value type.
Sends a long- the texture number (like GL_TEXTURE0) to pass to the shader.
Definition: ISFVal.hpp:36
VVISF_EXPORT ISFVal ISFImageVal(const VVGL::GLBufferRef &n)
Creates and returns an image-type ISFVal with the passed buffer.
bool isNullVal() const
Returns true if the receiver is a null value.
Definition: ISFVal.hpp:146
ISFVal describes an ISF value- it has a type (ISFValType) and a type-dependent value. Intended to be immutable.
Definition: ISFVal.hpp:57
ISFValType
Enumerates the different kinds of ISF values.
Definition: ISFVal.hpp:25
bool isCubeVal() const
Returns true if the receiver is a cube texture value.
Definition: ISFVal.hpp:160
VVISF_EXPORT ISFVal ISFColorVal(const double &inR, const double &inG, const double &inB, const double &inA)
Creates and returns a color-type ISFVal with the passed R/G/B/A color values.
string getTypeString() const
Returns a string describing the type of the receiver.
Sends a long.
Definition: ISFVal.hpp:29
double getColorValByChannel(const int &inIndex)
Does nothing if the receiver&#39;s value type isn&#39;t color or the passed index is out of bounds...
Definition: ISFVal.hpp:124
No data/unknown value type.
Definition: ISFVal.hpp:26
bool isBoolVal() const
Returns true if the receiver is a bool value.
Definition: ISFVal.hpp:150
Sends a long- the texture number (like GL_TEXTURE0) of a cubemap texture to pass to the shader...
Definition: ISFVal.hpp:33
double * getPointValPtr()
Returns a null if the receiver isn&#39;t a Point2D-type object, otherwise it returns a pointer to the two...
Definition: ISFVal.hpp:116
bool ISFValTypeUsesImage(const ISFValType &n)
Returns a true if the passed value type uses an image for its value.
Definition: ISFVal.hpp:49
Sends a long- the texture number (like GL_TEXTURE0) to pass to the shader.
Definition: ISFVal.hpp:34
bool isFloatVal() const
Returns true if the receiver is a float value.
Definition: ISFVal.hpp:154
ISFValType type() const
Returns the value type.
Definition: ISFVal.hpp:108
Sends a float.
Definition: ISFVal.hpp:30
bool isAudioFFTVal() const
Returns true if the receiver is an audio fft value (image).
Definition: ISFVal.hpp:166
Sends a long- the texture number (like GL_TEXTURE0) to pass to the shader.
Definition: ISFVal.hpp:35
bool isColorVal() const
Returns true if the receiver is a color value.
Definition: ISFVal.hpp:158
No data, just an event. sends a 1 the next render after the event is received, a 0 any other time it&#39;...
Definition: ISFVal.hpp:27
VVISF_EXPORT ISFVal ISFEventVal(const bool &n=false)
Creates and returns an event-type ISFVal. Events don&#39;t technically have a value- events should send a...
void setColorValByChannel(const int &inIndex, const double &inVal)
Does nothing if the receiver&#39;s value type isn&#39;t color or the passed index is out of bounds...
Definition: ISFVal.hpp:126
string getValString() const
Returns a string describing the value of the receiver.
double getPointValByIndex(const int &inIndex)
Returns 0. if the receiver value type isn&#39;t Point2D or the passed index is out of bounds...
Definition: ISFVal.hpp:118
bool isImageVal() const
Returns true if the receiver is an image value.
Definition: ISFVal.hpp:162
VVISF_EXPORT ISFVal ISFNullVal()
Creates and returns a null-type ISFVal.
void setPointValByIndex(const int &inIndex, const double &inVal)
Does nothing if the receiver&#39;s value type isn&#39;t Point2D or the passed index is out of bounds...
Definition: ISFVal.hpp:120