xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgVariableValue.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _RSGVARIABLEVALUE_HPP
2*35238bceSAndroid Build Coastguard Worker #define _RSGVARIABLEVALUE_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Random Shader Generator
5*35238bceSAndroid Build Coastguard Worker  * ----------------------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Variable Value class.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "rsgDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "rsgVariableType.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "rsgVariable.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include <algorithm>
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace rsg
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker union Scalar
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker     int intVal;
39*35238bceSAndroid Build Coastguard Worker     float floatVal;
40*35238bceSAndroid Build Coastguard Worker     bool boolVal;
41*35238bceSAndroid Build Coastguard Worker 
Scalar(void)42*35238bceSAndroid Build Coastguard Worker     Scalar(void) : intVal(0)
43*35238bceSAndroid Build Coastguard Worker     {
44*35238bceSAndroid Build Coastguard Worker     }
Scalar(float v)45*35238bceSAndroid Build Coastguard Worker     Scalar(float v) : floatVal(v)
46*35238bceSAndroid Build Coastguard Worker     {
47*35238bceSAndroid Build Coastguard Worker     }
Scalar(int v)48*35238bceSAndroid Build Coastguard Worker     Scalar(int v) : intVal(v)
49*35238bceSAndroid Build Coastguard Worker     {
50*35238bceSAndroid Build Coastguard Worker     }
Scalar(bool v)51*35238bceSAndroid Build Coastguard Worker     Scalar(bool v) : boolVal(v)
52*35238bceSAndroid Build Coastguard Worker     {
53*35238bceSAndroid Build Coastguard Worker     }
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker     // Bit-exact compare
operator ==(Scalar other) const56*35238bceSAndroid Build Coastguard Worker     bool operator==(Scalar other) const
57*35238bceSAndroid Build Coastguard Worker     {
58*35238bceSAndroid Build Coastguard Worker         return intVal == other.intVal;
59*35238bceSAndroid Build Coastguard Worker     }
operator !=(Scalar other) const60*35238bceSAndroid Build Coastguard Worker     bool operator!=(Scalar other) const
61*35238bceSAndroid Build Coastguard Worker     {
62*35238bceSAndroid Build Coastguard Worker         return intVal != other.intVal;
63*35238bceSAndroid Build Coastguard Worker     }
64*35238bceSAndroid Build Coastguard Worker 
65*35238bceSAndroid Build Coastguard Worker     template <typename T>
66*35238bceSAndroid Build Coastguard Worker     static Scalar min(void);
67*35238bceSAndroid Build Coastguard Worker     template <typename T>
68*35238bceSAndroid Build Coastguard Worker     static Scalar max(void);
69*35238bceSAndroid Build Coastguard Worker 
70*35238bceSAndroid Build Coastguard Worker     template <typename T>
71*35238bceSAndroid Build Coastguard Worker     T as(void) const;
72*35238bceSAndroid Build Coastguard Worker     template <typename T>
73*35238bceSAndroid Build Coastguard Worker     T &as(void);
74*35238bceSAndroid Build Coastguard Worker };
75*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(sizeof(Scalar) == sizeof(uint32_t));
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker template <>
min(void)78*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::min<float>(void)
79*35238bceSAndroid Build Coastguard Worker {
80*35238bceSAndroid Build Coastguard Worker     return Scalar((int)0xff800000);
81*35238bceSAndroid Build Coastguard Worker }
82*35238bceSAndroid Build Coastguard Worker template <>
max(void)83*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::max<float>(void)
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker     return Scalar((int)0x7f800000);
86*35238bceSAndroid Build Coastguard Worker }
87*35238bceSAndroid Build Coastguard Worker template <>
min(void)88*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::min<int>(void)
89*35238bceSAndroid Build Coastguard Worker {
90*35238bceSAndroid Build Coastguard Worker     return Scalar((int)0x80000000);
91*35238bceSAndroid Build Coastguard Worker }
92*35238bceSAndroid Build Coastguard Worker template <>
max(void)93*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::max<int>(void)
94*35238bceSAndroid Build Coastguard Worker {
95*35238bceSAndroid Build Coastguard Worker     return Scalar((int)0x7fffffff);
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker template <>
min(void)98*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::min<bool>(void)
99*35238bceSAndroid Build Coastguard Worker {
100*35238bceSAndroid Build Coastguard Worker     return Scalar(false);
101*35238bceSAndroid Build Coastguard Worker }
102*35238bceSAndroid Build Coastguard Worker template <>
max(void)103*35238bceSAndroid Build Coastguard Worker inline Scalar Scalar::max<bool>(void)
104*35238bceSAndroid Build Coastguard Worker {
105*35238bceSAndroid Build Coastguard Worker     return Scalar(true);
106*35238bceSAndroid Build Coastguard Worker }
107*35238bceSAndroid Build Coastguard Worker 
108*35238bceSAndroid Build Coastguard Worker template <>
as(void) const109*35238bceSAndroid Build Coastguard Worker inline float Scalar::as<float>(void) const
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker     return floatVal;
112*35238bceSAndroid Build Coastguard Worker }
113*35238bceSAndroid Build Coastguard Worker template <>
as(void)114*35238bceSAndroid Build Coastguard Worker inline float &Scalar::as<float>(void)
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker     return floatVal;
117*35238bceSAndroid Build Coastguard Worker }
118*35238bceSAndroid Build Coastguard Worker template <>
as(void) const119*35238bceSAndroid Build Coastguard Worker inline int Scalar::as<int>(void) const
120*35238bceSAndroid Build Coastguard Worker {
121*35238bceSAndroid Build Coastguard Worker     return intVal;
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker template <>
as(void)124*35238bceSAndroid Build Coastguard Worker inline int &Scalar::as<int>(void)
125*35238bceSAndroid Build Coastguard Worker {
126*35238bceSAndroid Build Coastguard Worker     return intVal;
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker template <>
as(void) const129*35238bceSAndroid Build Coastguard Worker inline bool Scalar::as<bool>(void) const
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker     return boolVal;
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker template <>
as(void)134*35238bceSAndroid Build Coastguard Worker inline bool &Scalar::as<bool>(void)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker     return boolVal;
137*35238bceSAndroid Build Coastguard Worker }
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker template <int Stride>
140*35238bceSAndroid Build Coastguard Worker class StridedValueRead
141*35238bceSAndroid Build Coastguard Worker {
142*35238bceSAndroid Build Coastguard Worker public:
StridedValueRead(const VariableType & type,const Scalar * value)143*35238bceSAndroid Build Coastguard Worker     StridedValueRead(const VariableType &type, const Scalar *value) : m_type(type), m_value(value)
144*35238bceSAndroid Build Coastguard Worker     {
145*35238bceSAndroid Build Coastguard Worker     }
146*35238bceSAndroid Build Coastguard Worker 
getType(void) const147*35238bceSAndroid Build Coastguard Worker     const VariableType &getType(void) const
148*35238bceSAndroid Build Coastguard Worker     {
149*35238bceSAndroid Build Coastguard Worker         return m_type;
150*35238bceSAndroid Build Coastguard Worker     }
getValuePtr(void) const151*35238bceSAndroid Build Coastguard Worker     const Scalar *getValuePtr(void) const
152*35238bceSAndroid Build Coastguard Worker     {
153*35238bceSAndroid Build Coastguard Worker         return m_value;
154*35238bceSAndroid Build Coastguard Worker     }
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker private:
157*35238bceSAndroid Build Coastguard Worker     const VariableType &m_type;
158*35238bceSAndroid Build Coastguard Worker     const Scalar *m_value;
159*35238bceSAndroid Build Coastguard Worker };
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker template <int Stride>
162*35238bceSAndroid Build Coastguard Worker class ConstStridedValueAccess
163*35238bceSAndroid Build Coastguard Worker {
164*35238bceSAndroid Build Coastguard Worker public:
ConstStridedValueAccess(void)165*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess(void) : m_type(DE_NULL), m_value(DE_NULL)
166*35238bceSAndroid Build Coastguard Worker     {
167*35238bceSAndroid Build Coastguard Worker     }
ConstStridedValueAccess(const VariableType & type,const Scalar * valuePtr)168*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess(const VariableType &type, const Scalar *valuePtr)
169*35238bceSAndroid Build Coastguard Worker         : m_type(&type)
170*35238bceSAndroid Build Coastguard Worker         , m_value(const_cast<Scalar *>(valuePtr))
171*35238bceSAndroid Build Coastguard Worker     {
172*35238bceSAndroid Build Coastguard Worker     }
173*35238bceSAndroid Build Coastguard Worker 
getType(void) const174*35238bceSAndroid Build Coastguard Worker     const VariableType &getType(void) const
175*35238bceSAndroid Build Coastguard Worker     {
176*35238bceSAndroid Build Coastguard Worker         return *m_type;
177*35238bceSAndroid Build Coastguard Worker     }
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker     // Read-only access
component(int compNdx) const180*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess component(int compNdx) const
181*35238bceSAndroid Build Coastguard Worker     {
182*35238bceSAndroid Build Coastguard Worker         return ConstStridedValueAccess(getType().getElementType(), m_value + Stride * compNdx);
183*35238bceSAndroid Build Coastguard Worker     }
arrayElement(int elementNdx) const184*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess arrayElement(int elementNdx) const
185*35238bceSAndroid Build Coastguard Worker     {
186*35238bceSAndroid Build Coastguard Worker         return ConstStridedValueAccess(getType().getElementType(),
187*35238bceSAndroid Build Coastguard Worker                                        m_value + Stride * getType().getElementScalarOffset(elementNdx));
188*35238bceSAndroid Build Coastguard Worker     }
member(int memberNdx) const189*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess member(int memberNdx) const
190*35238bceSAndroid Build Coastguard Worker     {
191*35238bceSAndroid Build Coastguard Worker         return ConstStridedValueAccess(getType().getMembers()[memberNdx].getType(),
192*35238bceSAndroid Build Coastguard Worker                                        m_value + Stride * getType().getMemberScalarOffset(memberNdx));
193*35238bceSAndroid Build Coastguard Worker     }
194*35238bceSAndroid Build Coastguard Worker 
asFloat(void) const195*35238bceSAndroid Build Coastguard Worker     float asFloat(void) const
196*35238bceSAndroid Build Coastguard Worker     {
197*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
198*35238bceSAndroid Build Coastguard Worker         return m_value->floatVal;
199*35238bceSAndroid Build Coastguard Worker     }
asInt(void) const200*35238bceSAndroid Build Coastguard Worker     int asInt(void) const
201*35238bceSAndroid Build Coastguard Worker     {
202*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
203*35238bceSAndroid Build Coastguard Worker         return m_value->intVal;
204*35238bceSAndroid Build Coastguard Worker     }
asBool(void) const205*35238bceSAndroid Build Coastguard Worker     bool asBool(void) const
206*35238bceSAndroid Build Coastguard Worker     {
207*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
208*35238bceSAndroid Build Coastguard Worker         return m_value->boolVal;
209*35238bceSAndroid Build Coastguard Worker     }
asScalar(void) const210*35238bceSAndroid Build Coastguard Worker     Scalar asScalar(void) const
211*35238bceSAndroid Build Coastguard Worker     {
212*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
213*35238bceSAndroid Build Coastguard Worker         return *m_value;
214*35238bceSAndroid Build Coastguard Worker     }
215*35238bceSAndroid Build Coastguard Worker 
asFloat(int ndx) const216*35238bceSAndroid Build Coastguard Worker     float asFloat(int ndx) const
217*35238bceSAndroid Build Coastguard Worker     {
218*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
219*35238bceSAndroid Build Coastguard Worker         return m_value[ndx].floatVal;
220*35238bceSAndroid Build Coastguard Worker     }
asInt(int ndx) const221*35238bceSAndroid Build Coastguard Worker     int asInt(int ndx) const
222*35238bceSAndroid Build Coastguard Worker     {
223*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
224*35238bceSAndroid Build Coastguard Worker         return m_value[ndx].intVal;
225*35238bceSAndroid Build Coastguard Worker     }
asBool(int ndx) const226*35238bceSAndroid Build Coastguard Worker     bool asBool(int ndx) const
227*35238bceSAndroid Build Coastguard Worker     {
228*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
229*35238bceSAndroid Build Coastguard Worker         return m_value[ndx].boolVal;
230*35238bceSAndroid Build Coastguard Worker     }
asScalar(int ndx) const231*35238bceSAndroid Build Coastguard Worker     Scalar asScalar(int ndx) const
232*35238bceSAndroid Build Coastguard Worker     {
233*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
234*35238bceSAndroid Build Coastguard Worker         return m_value[ndx];
235*35238bceSAndroid Build Coastguard Worker     }
236*35238bceSAndroid Build Coastguard Worker 
237*35238bceSAndroid Build Coastguard Worker     template <typename T>
as(int ndx) const238*35238bceSAndroid Build Coastguard Worker     T as(int ndx) const
239*35238bceSAndroid Build Coastguard Worker     {
240*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
241*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx].template as<T>();
242*35238bceSAndroid Build Coastguard Worker     }
243*35238bceSAndroid Build Coastguard Worker 
244*35238bceSAndroid Build Coastguard Worker     // For assignment: b = a.value()
value(void) const245*35238bceSAndroid Build Coastguard Worker     StridedValueRead<Stride> value(void) const
246*35238bceSAndroid Build Coastguard Worker     {
247*35238bceSAndroid Build Coastguard Worker         return StridedValueRead<Stride>(getType(), m_value);
248*35238bceSAndroid Build Coastguard Worker     }
249*35238bceSAndroid Build Coastguard Worker 
250*35238bceSAndroid Build Coastguard Worker protected:
251*35238bceSAndroid Build Coastguard Worker     const VariableType *m_type;
252*35238bceSAndroid Build Coastguard Worker     Scalar
253*35238bceSAndroid Build Coastguard Worker         *m_value; // \note Non-const internal pointer is used so that ValueAccess can extend this class with RW access
254*35238bceSAndroid Build Coastguard Worker };
255*35238bceSAndroid Build Coastguard Worker 
256*35238bceSAndroid Build Coastguard Worker template <int Stride>
257*35238bceSAndroid Build Coastguard Worker class StridedValueAccess : public ConstStridedValueAccess<Stride>
258*35238bceSAndroid Build Coastguard Worker {
259*35238bceSAndroid Build Coastguard Worker public:
StridedValueAccess(void)260*35238bceSAndroid Build Coastguard Worker     StridedValueAccess(void)
261*35238bceSAndroid Build Coastguard Worker     {
262*35238bceSAndroid Build Coastguard Worker     }
StridedValueAccess(const VariableType & type,Scalar * valuePtr)263*35238bceSAndroid Build Coastguard Worker     StridedValueAccess(const VariableType &type, Scalar *valuePtr) : ConstStridedValueAccess<Stride>(type, valuePtr)
264*35238bceSAndroid Build Coastguard Worker     {
265*35238bceSAndroid Build Coastguard Worker     }
266*35238bceSAndroid Build Coastguard Worker 
267*35238bceSAndroid Build Coastguard Worker     // Read-write access
component(int compNdx)268*35238bceSAndroid Build Coastguard Worker     StridedValueAccess component(int compNdx)
269*35238bceSAndroid Build Coastguard Worker     {
270*35238bceSAndroid Build Coastguard Worker         return StridedValueAccess(this->getType().getElementType(), this->m_value + Stride * compNdx);
271*35238bceSAndroid Build Coastguard Worker     }
arrayElement(int elementNdx)272*35238bceSAndroid Build Coastguard Worker     StridedValueAccess arrayElement(int elementNdx)
273*35238bceSAndroid Build Coastguard Worker     {
274*35238bceSAndroid Build Coastguard Worker         return StridedValueAccess(this->getType().getElementType(),
275*35238bceSAndroid Build Coastguard Worker                                   this->m_value + Stride * this->getType().getElementScalarOffset(elementNdx));
276*35238bceSAndroid Build Coastguard Worker     }
member(int memberNdx)277*35238bceSAndroid Build Coastguard Worker     StridedValueAccess member(int memberNdx)
278*35238bceSAndroid Build Coastguard Worker     {
279*35238bceSAndroid Build Coastguard Worker         return StridedValueAccess(this->getType().getMembers()[memberNdx].getType(),
280*35238bceSAndroid Build Coastguard Worker                                   this->m_value + Stride * this->getType().getMemberScalarOffset(memberNdx));
281*35238bceSAndroid Build Coastguard Worker     }
282*35238bceSAndroid Build Coastguard Worker 
asFloat(void)283*35238bceSAndroid Build Coastguard Worker     float &asFloat(void)
284*35238bceSAndroid Build Coastguard Worker     {
285*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
286*35238bceSAndroid Build Coastguard Worker         return this->m_value->floatVal;
287*35238bceSAndroid Build Coastguard Worker     }
asInt(void)288*35238bceSAndroid Build Coastguard Worker     int &asInt(void)
289*35238bceSAndroid Build Coastguard Worker     {
290*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
291*35238bceSAndroid Build Coastguard Worker         return this->m_value->intVal;
292*35238bceSAndroid Build Coastguard Worker     }
asBool(void)293*35238bceSAndroid Build Coastguard Worker     bool &asBool(void)
294*35238bceSAndroid Build Coastguard Worker     {
295*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
296*35238bceSAndroid Build Coastguard Worker         return this->m_value->boolVal;
297*35238bceSAndroid Build Coastguard Worker     }
asScalar(void)298*35238bceSAndroid Build Coastguard Worker     Scalar &asScalar(void)
299*35238bceSAndroid Build Coastguard Worker     {
300*35238bceSAndroid Build Coastguard Worker         DE_STATIC_ASSERT(Stride == 1);
301*35238bceSAndroid Build Coastguard Worker         return *this->m_value;
302*35238bceSAndroid Build Coastguard Worker     }
303*35238bceSAndroid Build Coastguard Worker 
asFloat(int ndx)304*35238bceSAndroid Build Coastguard Worker     float &asFloat(int ndx)
305*35238bceSAndroid Build Coastguard Worker     {
306*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
307*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx].floatVal;
308*35238bceSAndroid Build Coastguard Worker     }
asInt(int ndx)309*35238bceSAndroid Build Coastguard Worker     int &asInt(int ndx)
310*35238bceSAndroid Build Coastguard Worker     {
311*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
312*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx].intVal;
313*35238bceSAndroid Build Coastguard Worker     }
asBool(int ndx)314*35238bceSAndroid Build Coastguard Worker     bool &asBool(int ndx)
315*35238bceSAndroid Build Coastguard Worker     {
316*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
317*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx].boolVal;
318*35238bceSAndroid Build Coastguard Worker     }
asScalar(int ndx)319*35238bceSAndroid Build Coastguard Worker     Scalar &asScalar(int ndx)
320*35238bceSAndroid Build Coastguard Worker     {
321*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
322*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx];
323*35238bceSAndroid Build Coastguard Worker     }
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker     template <typename T>
as(int ndx)326*35238bceSAndroid Build Coastguard Worker     T &as(int ndx)
327*35238bceSAndroid Build Coastguard Worker     {
328*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(de::inBounds(ndx, 0, Stride));
329*35238bceSAndroid Build Coastguard Worker         return this->m_value[ndx].template as<T>();
330*35238bceSAndroid Build Coastguard Worker     }
331*35238bceSAndroid Build Coastguard Worker 
332*35238bceSAndroid Build Coastguard Worker     template <int SrcStride>
333*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(const StridedValueRead<SrcStride> &value);
334*35238bceSAndroid Build Coastguard Worker 
335*35238bceSAndroid Build Coastguard Worker     // Helpers, work only in Stride == 1 case
336*35238bceSAndroid Build Coastguard Worker     template <int Size>
337*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(const tcu::Vector<float, Size> &vec);
operator =(float floatVal)338*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(float floatVal)
339*35238bceSAndroid Build Coastguard Worker     {
340*35238bceSAndroid Build Coastguard Worker         asFloat() = floatVal;
341*35238bceSAndroid Build Coastguard Worker         return *this;
342*35238bceSAndroid Build Coastguard Worker     }
operator =(int intVal)343*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(int intVal)
344*35238bceSAndroid Build Coastguard Worker     {
345*35238bceSAndroid Build Coastguard Worker         asInt() = intVal;
346*35238bceSAndroid Build Coastguard Worker         return *this;
347*35238bceSAndroid Build Coastguard Worker     }
operator =(bool boolVal)348*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(bool boolVal)
349*35238bceSAndroid Build Coastguard Worker     {
350*35238bceSAndroid Build Coastguard Worker         asBool() = boolVal;
351*35238bceSAndroid Build Coastguard Worker         return *this;
352*35238bceSAndroid Build Coastguard Worker     }
operator =(Scalar val)353*35238bceSAndroid Build Coastguard Worker     StridedValueAccess &operator=(Scalar val)
354*35238bceSAndroid Build Coastguard Worker     {
355*35238bceSAndroid Build Coastguard Worker         asScalar() = val;
356*35238bceSAndroid Build Coastguard Worker         return *this;
357*35238bceSAndroid Build Coastguard Worker     }
358*35238bceSAndroid Build Coastguard Worker };
359*35238bceSAndroid Build Coastguard Worker 
360*35238bceSAndroid Build Coastguard Worker template <int Stride>
361*35238bceSAndroid Build Coastguard Worker template <int SrcStride>
operator =(const StridedValueRead<SrcStride> & valueRead)362*35238bceSAndroid Build Coastguard Worker StridedValueAccess<Stride> &StridedValueAccess<Stride>::operator=(const StridedValueRead<SrcStride> &valueRead)
363*35238bceSAndroid Build Coastguard Worker {
364*35238bceSAndroid Build Coastguard Worker     DE_STATIC_ASSERT(SrcStride == Stride || SrcStride == 1);
365*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(this->getType() == valueRead.getType());
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker     int scalarSize = this->getType().getScalarSize();
368*35238bceSAndroid Build Coastguard Worker 
369*35238bceSAndroid Build Coastguard Worker     if (scalarSize == 0)
370*35238bceSAndroid Build Coastguard Worker         return *this; // Happens when void value range is copied
371*35238bceSAndroid Build Coastguard Worker 
372*35238bceSAndroid Build Coastguard Worker     if (Stride == SrcStride)
373*35238bceSAndroid Build Coastguard Worker         std::copy(valueRead.getValuePtr(), valueRead.getValuePtr() + scalarSize * Stride, this->m_value);
374*35238bceSAndroid Build Coastguard Worker     else
375*35238bceSAndroid Build Coastguard Worker     {
376*35238bceSAndroid Build Coastguard Worker         for (int scalarNdx = 0; scalarNdx < scalarSize; scalarNdx++)
377*35238bceSAndroid Build Coastguard Worker             std::fill(this->m_value + scalarNdx * Stride, this->m_value + (scalarNdx + 1) * Stride,
378*35238bceSAndroid Build Coastguard Worker                       valueRead.getValuePtr()[scalarNdx]);
379*35238bceSAndroid Build Coastguard Worker     }
380*35238bceSAndroid Build Coastguard Worker 
381*35238bceSAndroid Build Coastguard Worker     return *this;
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker 
384*35238bceSAndroid Build Coastguard Worker template <int Stride>
385*35238bceSAndroid Build Coastguard Worker template <int Size>
operator =(const tcu::Vector<float,Size> & vec)386*35238bceSAndroid Build Coastguard Worker StridedValueAccess<Stride> &StridedValueAccess<Stride>::operator=(const tcu::Vector<float, Size> &vec)
387*35238bceSAndroid Build Coastguard Worker {
388*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(this->getType() == VariableType(VariableType::TYPE_FLOAT, Size));
389*35238bceSAndroid Build Coastguard Worker     for (int comp = 0; comp < 4; comp++)
390*35238bceSAndroid Build Coastguard Worker         component(comp).asFloat() = vec.getPtr()[comp];
391*35238bceSAndroid Build Coastguard Worker 
392*35238bceSAndroid Build Coastguard Worker     return *this;
393*35238bceSAndroid Build Coastguard Worker }
394*35238bceSAndroid Build Coastguard Worker 
395*35238bceSAndroid Build Coastguard Worker // Typedefs for stride == 1 case
396*35238bceSAndroid Build Coastguard Worker typedef ConstStridedValueAccess<1> ConstValueAccess;
397*35238bceSAndroid Build Coastguard Worker typedef StridedValueAccess<1> ValueAccess;
398*35238bceSAndroid Build Coastguard Worker 
399*35238bceSAndroid Build Coastguard Worker class ConstValueRangeAccess
400*35238bceSAndroid Build Coastguard Worker {
401*35238bceSAndroid Build Coastguard Worker public:
ConstValueRangeAccess(void)402*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess(void) : m_type(DE_NULL), m_min(DE_NULL), m_max(DE_NULL)
403*35238bceSAndroid Build Coastguard Worker     {
404*35238bceSAndroid Build Coastguard Worker     }
ConstValueRangeAccess(const VariableType & type,const Scalar * minVal,const Scalar * maxVal)405*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess(const VariableType &type, const Scalar *minVal, const Scalar *maxVal)
406*35238bceSAndroid Build Coastguard Worker         : m_type(&type)
407*35238bceSAndroid Build Coastguard Worker         , m_min(const_cast<Scalar *>(minVal))
408*35238bceSAndroid Build Coastguard Worker         , m_max(const_cast<Scalar *>(maxVal))
409*35238bceSAndroid Build Coastguard Worker     {
410*35238bceSAndroid Build Coastguard Worker     }
411*35238bceSAndroid Build Coastguard Worker 
getType(void) const412*35238bceSAndroid Build Coastguard Worker     const VariableType &getType(void) const
413*35238bceSAndroid Build Coastguard Worker     {
414*35238bceSAndroid Build Coastguard Worker         return *m_type;
415*35238bceSAndroid Build Coastguard Worker     }
getMin(void) const416*35238bceSAndroid Build Coastguard Worker     ConstValueAccess getMin(void) const
417*35238bceSAndroid Build Coastguard Worker     {
418*35238bceSAndroid Build Coastguard Worker         return ConstValueAccess(*m_type, m_min);
419*35238bceSAndroid Build Coastguard Worker     }
getMax(void) const420*35238bceSAndroid Build Coastguard Worker     ConstValueAccess getMax(void) const
421*35238bceSAndroid Build Coastguard Worker     {
422*35238bceSAndroid Build Coastguard Worker         return ConstValueAccess(*m_type, m_max);
423*35238bceSAndroid Build Coastguard Worker     }
424*35238bceSAndroid Build Coastguard Worker 
425*35238bceSAndroid Build Coastguard Worker     // Read-only access
426*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess component(int compNdx) const;
427*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess arrayElement(int elementNdx) const;
428*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess member(int memberNdx) const;
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker     // Set operations - tests condition for all elements
431*35238bceSAndroid Build Coastguard Worker     bool intersects(const ConstValueRangeAccess &other) const;
432*35238bceSAndroid Build Coastguard Worker     bool isSupersetOf(const ConstValueRangeAccess &other) const;
433*35238bceSAndroid Build Coastguard Worker     bool isSubsetOf(const ConstValueRangeAccess &other) const;
434*35238bceSAndroid Build Coastguard Worker 
435*35238bceSAndroid Build Coastguard Worker protected:
436*35238bceSAndroid Build Coastguard Worker     const VariableType *m_type;
437*35238bceSAndroid Build Coastguard Worker     Scalar *m_min; // \note See note in ConstValueAccess
438*35238bceSAndroid Build Coastguard Worker     Scalar *m_max;
439*35238bceSAndroid Build Coastguard Worker };
440*35238bceSAndroid Build Coastguard Worker 
component(int compNdx) const441*35238bceSAndroid Build Coastguard Worker inline ConstValueRangeAccess ConstValueRangeAccess::component(int compNdx) const
442*35238bceSAndroid Build Coastguard Worker {
443*35238bceSAndroid Build Coastguard Worker     return ConstValueRangeAccess(m_type->getElementType(), m_min + compNdx, m_max + compNdx);
444*35238bceSAndroid Build Coastguard Worker }
445*35238bceSAndroid Build Coastguard Worker 
arrayElement(int elementNdx) const446*35238bceSAndroid Build Coastguard Worker inline ConstValueRangeAccess ConstValueRangeAccess::arrayElement(int elementNdx) const
447*35238bceSAndroid Build Coastguard Worker {
448*35238bceSAndroid Build Coastguard Worker     int offset = m_type->getElementScalarOffset(elementNdx);
449*35238bceSAndroid Build Coastguard Worker     return ConstValueRangeAccess(m_type->getElementType(), m_min + offset, m_max + offset);
450*35238bceSAndroid Build Coastguard Worker }
451*35238bceSAndroid Build Coastguard Worker 
member(int memberNdx) const452*35238bceSAndroid Build Coastguard Worker inline ConstValueRangeAccess ConstValueRangeAccess::member(int memberNdx) const
453*35238bceSAndroid Build Coastguard Worker {
454*35238bceSAndroid Build Coastguard Worker     int offset = m_type->getMemberScalarOffset(memberNdx);
455*35238bceSAndroid Build Coastguard Worker     return ConstValueRangeAccess(m_type->getMembers()[memberNdx].getType(), m_min + offset, m_max + offset);
456*35238bceSAndroid Build Coastguard Worker }
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker class ValueRangeAccess : public ConstValueRangeAccess
459*35238bceSAndroid Build Coastguard Worker {
460*35238bceSAndroid Build Coastguard Worker public:
ValueRangeAccess(const VariableType & type,Scalar * minVal,Scalar * maxVal)461*35238bceSAndroid Build Coastguard Worker     ValueRangeAccess(const VariableType &type, Scalar *minVal, Scalar *maxVal)
462*35238bceSAndroid Build Coastguard Worker         : ConstValueRangeAccess(type, minVal, maxVal)
463*35238bceSAndroid Build Coastguard Worker     {
464*35238bceSAndroid Build Coastguard Worker     }
465*35238bceSAndroid Build Coastguard Worker 
466*35238bceSAndroid Build Coastguard Worker     // Read-write access
getMin(void)467*35238bceSAndroid Build Coastguard Worker     ValueAccess getMin(void)
468*35238bceSAndroid Build Coastguard Worker     {
469*35238bceSAndroid Build Coastguard Worker         return ValueAccess(*m_type, m_min);
470*35238bceSAndroid Build Coastguard Worker     }
getMax(void)471*35238bceSAndroid Build Coastguard Worker     ValueAccess getMax(void)
472*35238bceSAndroid Build Coastguard Worker     {
473*35238bceSAndroid Build Coastguard Worker         return ValueAccess(*m_type, m_max);
474*35238bceSAndroid Build Coastguard Worker     }
475*35238bceSAndroid Build Coastguard Worker 
476*35238bceSAndroid Build Coastguard Worker     ValueRangeAccess component(int compNdx);
477*35238bceSAndroid Build Coastguard Worker     ValueRangeAccess arrayElement(int elementNdx);
478*35238bceSAndroid Build Coastguard Worker     ValueRangeAccess member(int memberNdx);
479*35238bceSAndroid Build Coastguard Worker };
480*35238bceSAndroid Build Coastguard Worker 
component(int compNdx)481*35238bceSAndroid Build Coastguard Worker inline ValueRangeAccess ValueRangeAccess::component(int compNdx)
482*35238bceSAndroid Build Coastguard Worker {
483*35238bceSAndroid Build Coastguard Worker     return ValueRangeAccess(m_type->getElementType(), m_min + compNdx, m_max + compNdx);
484*35238bceSAndroid Build Coastguard Worker }
485*35238bceSAndroid Build Coastguard Worker 
arrayElement(int elementNdx)486*35238bceSAndroid Build Coastguard Worker inline ValueRangeAccess ValueRangeAccess::arrayElement(int elementNdx)
487*35238bceSAndroid Build Coastguard Worker {
488*35238bceSAndroid Build Coastguard Worker     int offset = m_type->getElementScalarOffset(elementNdx);
489*35238bceSAndroid Build Coastguard Worker     return ValueRangeAccess(m_type->getElementType(), m_min + offset, m_max + offset);
490*35238bceSAndroid Build Coastguard Worker }
491*35238bceSAndroid Build Coastguard Worker 
member(int memberNdx)492*35238bceSAndroid Build Coastguard Worker inline ValueRangeAccess ValueRangeAccess::member(int memberNdx)
493*35238bceSAndroid Build Coastguard Worker {
494*35238bceSAndroid Build Coastguard Worker     int offset = m_type->getMemberScalarOffset(memberNdx);
495*35238bceSAndroid Build Coastguard Worker     return ValueRangeAccess(m_type->getMembers()[memberNdx].getType(), m_min + offset, m_max + offset);
496*35238bceSAndroid Build Coastguard Worker }
497*35238bceSAndroid Build Coastguard Worker 
498*35238bceSAndroid Build Coastguard Worker class ValueRange
499*35238bceSAndroid Build Coastguard Worker {
500*35238bceSAndroid Build Coastguard Worker public:
501*35238bceSAndroid Build Coastguard Worker     ValueRange(const VariableType &type);
502*35238bceSAndroid Build Coastguard Worker     ValueRange(const VariableType &type, const ConstValueAccess &minVal, const ConstValueAccess &maxVal);
503*35238bceSAndroid Build Coastguard Worker     ValueRange(const VariableType &type, const Scalar *minVal, const Scalar *maxVal);
504*35238bceSAndroid Build Coastguard Worker     ValueRange(ConstValueRangeAccess other);
505*35238bceSAndroid Build Coastguard Worker     ~ValueRange(void);
506*35238bceSAndroid Build Coastguard Worker 
getType(void) const507*35238bceSAndroid Build Coastguard Worker     const VariableType &getType(void) const
508*35238bceSAndroid Build Coastguard Worker     {
509*35238bceSAndroid Build Coastguard Worker         return m_type;
510*35238bceSAndroid Build Coastguard Worker     }
511*35238bceSAndroid Build Coastguard Worker 
getMin(void)512*35238bceSAndroid Build Coastguard Worker     ValueAccess getMin(void)
513*35238bceSAndroid Build Coastguard Worker     {
514*35238bceSAndroid Build Coastguard Worker         return ValueAccess(m_type, getMinPtr());
515*35238bceSAndroid Build Coastguard Worker     }
getMax(void)516*35238bceSAndroid Build Coastguard Worker     ValueAccess getMax(void)
517*35238bceSAndroid Build Coastguard Worker     {
518*35238bceSAndroid Build Coastguard Worker         return ValueAccess(m_type, getMaxPtr());
519*35238bceSAndroid Build Coastguard Worker     }
520*35238bceSAndroid Build Coastguard Worker 
getMin(void) const521*35238bceSAndroid Build Coastguard Worker     ConstValueAccess getMin(void) const
522*35238bceSAndroid Build Coastguard Worker     {
523*35238bceSAndroid Build Coastguard Worker         return ConstValueAccess(m_type, getMinPtr());
524*35238bceSAndroid Build Coastguard Worker     }
getMax(void) const525*35238bceSAndroid Build Coastguard Worker     ConstValueAccess getMax(void) const
526*35238bceSAndroid Build Coastguard Worker     {
527*35238bceSAndroid Build Coastguard Worker         return ConstValueAccess(m_type, getMaxPtr());
528*35238bceSAndroid Build Coastguard Worker     }
529*35238bceSAndroid Build Coastguard Worker 
asAccess(void)530*35238bceSAndroid Build Coastguard Worker     ValueRangeAccess asAccess(void)
531*35238bceSAndroid Build Coastguard Worker     {
532*35238bceSAndroid Build Coastguard Worker         return ValueRangeAccess(m_type, getMinPtr(), getMaxPtr());
533*35238bceSAndroid Build Coastguard Worker     }
asAccess(void) const534*35238bceSAndroid Build Coastguard Worker     ConstValueRangeAccess asAccess(void) const
535*35238bceSAndroid Build Coastguard Worker     {
536*35238bceSAndroid Build Coastguard Worker         return ConstValueRangeAccess(m_type, getMinPtr(), getMaxPtr());
537*35238bceSAndroid Build Coastguard Worker     }
538*35238bceSAndroid Build Coastguard Worker 
operator ConstValueRangeAccess(void) const539*35238bceSAndroid Build Coastguard Worker     operator ConstValueRangeAccess(void) const
540*35238bceSAndroid Build Coastguard Worker     {
541*35238bceSAndroid Build Coastguard Worker         return asAccess();
542*35238bceSAndroid Build Coastguard Worker     }
operator ValueRangeAccess(void)543*35238bceSAndroid Build Coastguard Worker     operator ValueRangeAccess(void)
544*35238bceSAndroid Build Coastguard Worker     {
545*35238bceSAndroid Build Coastguard Worker         return asAccess();
546*35238bceSAndroid Build Coastguard Worker     }
547*35238bceSAndroid Build Coastguard Worker 
548*35238bceSAndroid Build Coastguard Worker     static void computeIntersection(ValueRangeAccess dst, const ConstValueRangeAccess &a,
549*35238bceSAndroid Build Coastguard Worker                                     const ConstValueRangeAccess &b);
550*35238bceSAndroid Build Coastguard Worker     static void computeIntersection(ValueRange &dst, const ConstValueRangeAccess &a, const ConstValueRangeAccess &b);
551*35238bceSAndroid Build Coastguard Worker 
552*35238bceSAndroid Build Coastguard Worker private:
getMinPtr(void) const553*35238bceSAndroid Build Coastguard Worker     const Scalar *getMinPtr(void) const
554*35238bceSAndroid Build Coastguard Worker     {
555*35238bceSAndroid Build Coastguard Worker         return m_min.empty() ? DE_NULL : &m_min[0];
556*35238bceSAndroid Build Coastguard Worker     }
getMaxPtr(void) const557*35238bceSAndroid Build Coastguard Worker     const Scalar *getMaxPtr(void) const
558*35238bceSAndroid Build Coastguard Worker     {
559*35238bceSAndroid Build Coastguard Worker         return m_max.empty() ? DE_NULL : &m_max[0];
560*35238bceSAndroid Build Coastguard Worker     }
561*35238bceSAndroid Build Coastguard Worker 
getMinPtr(void)562*35238bceSAndroid Build Coastguard Worker     Scalar *getMinPtr(void)
563*35238bceSAndroid Build Coastguard Worker     {
564*35238bceSAndroid Build Coastguard Worker         return m_min.empty() ? DE_NULL : &m_min[0];
565*35238bceSAndroid Build Coastguard Worker     }
getMaxPtr(void)566*35238bceSAndroid Build Coastguard Worker     Scalar *getMaxPtr(void)
567*35238bceSAndroid Build Coastguard Worker     {
568*35238bceSAndroid Build Coastguard Worker         return m_max.empty() ? DE_NULL : &m_max[0];
569*35238bceSAndroid Build Coastguard Worker     }
570*35238bceSAndroid Build Coastguard Worker 
571*35238bceSAndroid Build Coastguard Worker     VariableType m_type;
572*35238bceSAndroid Build Coastguard Worker     std::vector<Scalar> m_min;
573*35238bceSAndroid Build Coastguard Worker     std::vector<Scalar> m_max;
574*35238bceSAndroid Build Coastguard Worker };
575*35238bceSAndroid Build Coastguard Worker 
576*35238bceSAndroid Build Coastguard Worker template <int Stride>
577*35238bceSAndroid Build Coastguard Worker class ValueStorage
578*35238bceSAndroid Build Coastguard Worker {
579*35238bceSAndroid Build Coastguard Worker public:
580*35238bceSAndroid Build Coastguard Worker     ValueStorage(void);
581*35238bceSAndroid Build Coastguard Worker     ValueStorage(const VariableType &type);
582*35238bceSAndroid Build Coastguard Worker 
583*35238bceSAndroid Build Coastguard Worker     void setStorage(const VariableType &type);
584*35238bceSAndroid Build Coastguard Worker 
getValue(const VariableType & type)585*35238bceSAndroid Build Coastguard Worker     StridedValueAccess<Stride> getValue(const VariableType &type)
586*35238bceSAndroid Build Coastguard Worker     {
587*35238bceSAndroid Build Coastguard Worker         return StridedValueAccess<Stride>(type, &m_value[0]);
588*35238bceSAndroid Build Coastguard Worker     }
getValue(const VariableType & type) const589*35238bceSAndroid Build Coastguard Worker     ConstStridedValueAccess<Stride> getValue(const VariableType &type) const
590*35238bceSAndroid Build Coastguard Worker     {
591*35238bceSAndroid Build Coastguard Worker         return ConstStridedValueAccess<Stride>(type, &m_value[0]);
592*35238bceSAndroid Build Coastguard Worker     }
593*35238bceSAndroid Build Coastguard Worker 
594*35238bceSAndroid Build Coastguard Worker private:
595*35238bceSAndroid Build Coastguard Worker     ValueStorage(const ValueStorage &other);
596*35238bceSAndroid Build Coastguard Worker     ValueStorage operator=(const ValueStorage &other);
597*35238bceSAndroid Build Coastguard Worker 
598*35238bceSAndroid Build Coastguard Worker     std::vector<Scalar> m_value;
599*35238bceSAndroid Build Coastguard Worker };
600*35238bceSAndroid Build Coastguard Worker 
601*35238bceSAndroid Build Coastguard Worker template <int Stride>
ValueStorage(void)602*35238bceSAndroid Build Coastguard Worker ValueStorage<Stride>::ValueStorage(void)
603*35238bceSAndroid Build Coastguard Worker {
604*35238bceSAndroid Build Coastguard Worker }
605*35238bceSAndroid Build Coastguard Worker 
606*35238bceSAndroid Build Coastguard Worker template <int Stride>
ValueStorage(const VariableType & type)607*35238bceSAndroid Build Coastguard Worker ValueStorage<Stride>::ValueStorage(const VariableType &type)
608*35238bceSAndroid Build Coastguard Worker {
609*35238bceSAndroid Build Coastguard Worker     setStorage(type);
610*35238bceSAndroid Build Coastguard Worker }
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker template <int Stride>
setStorage(const VariableType & type)613*35238bceSAndroid Build Coastguard Worker void ValueStorage<Stride>::setStorage(const VariableType &type)
614*35238bceSAndroid Build Coastguard Worker {
615*35238bceSAndroid Build Coastguard Worker     m_value.resize(type.getScalarSize() * Stride);
616*35238bceSAndroid Build Coastguard Worker }
617*35238bceSAndroid Build Coastguard Worker 
618*35238bceSAndroid Build Coastguard Worker class VariableValue
619*35238bceSAndroid Build Coastguard Worker {
620*35238bceSAndroid Build Coastguard Worker public:
VariableValue(const Variable * variable)621*35238bceSAndroid Build Coastguard Worker     VariableValue(const Variable *variable) : m_variable(variable), m_storage(m_variable->getType())
622*35238bceSAndroid Build Coastguard Worker     {
623*35238bceSAndroid Build Coastguard Worker     }
~VariableValue(void)624*35238bceSAndroid Build Coastguard Worker     ~VariableValue(void)
625*35238bceSAndroid Build Coastguard Worker     {
626*35238bceSAndroid Build Coastguard Worker     }
627*35238bceSAndroid Build Coastguard Worker 
getVariable(void) const628*35238bceSAndroid Build Coastguard Worker     const Variable *getVariable(void) const
629*35238bceSAndroid Build Coastguard Worker     {
630*35238bceSAndroid Build Coastguard Worker         return m_variable;
631*35238bceSAndroid Build Coastguard Worker     }
getValue(void)632*35238bceSAndroid Build Coastguard Worker     ValueAccess getValue(void)
633*35238bceSAndroid Build Coastguard Worker     {
634*35238bceSAndroid Build Coastguard Worker         return m_storage.getValue(m_variable->getType());
635*35238bceSAndroid Build Coastguard Worker     }
getValue(void) const636*35238bceSAndroid Build Coastguard Worker     ConstValueAccess getValue(void) const
637*35238bceSAndroid Build Coastguard Worker     {
638*35238bceSAndroid Build Coastguard Worker         return m_storage.getValue(m_variable->getType());
639*35238bceSAndroid Build Coastguard Worker     }
640*35238bceSAndroid Build Coastguard Worker 
641*35238bceSAndroid Build Coastguard Worker     VariableValue(const VariableValue &other);
642*35238bceSAndroid Build Coastguard Worker     VariableValue &operator=(const VariableValue &other);
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker private:
getType(void) const645*35238bceSAndroid Build Coastguard Worker     const VariableType &getType(void) const
646*35238bceSAndroid Build Coastguard Worker     {
647*35238bceSAndroid Build Coastguard Worker         return m_variable->getType();
648*35238bceSAndroid Build Coastguard Worker     }
649*35238bceSAndroid Build Coastguard Worker 
650*35238bceSAndroid Build Coastguard Worker     const Variable *m_variable;
651*35238bceSAndroid Build Coastguard Worker     ValueStorage<1> m_storage;
652*35238bceSAndroid Build Coastguard Worker };
653*35238bceSAndroid Build Coastguard Worker 
654*35238bceSAndroid Build Coastguard Worker } // namespace rsg
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker #endif // _RSGVARIABLEVALUE_HPP
657