@@ -171,6 +171,9 @@ ParamValue::ParamValue(string_view name, TypeDesc type, string_view value)
171171 } else if (type == TypeDesc::STRING) {
172172 ustring s (value);
173173 init (name, type, 1 , &s);
174+ } else if (type == TypeDesc::USTRINGHASH) {
175+ ustringhash s (value);
176+ init (name, type, 1 , &s);
174177 }
175178}
176179
@@ -187,40 +190,11 @@ ParamValue::get_int(int defaultval) const
187190int
188191ParamValue::get_int_indexed (int index, int defaultval) const
189192{
190- #if 1 && OIIO_VERSION >= 20101
191193 int val = defaultval;
192194 convert_type (type ().elementtype (),
193195 (const char *)data () + index * type ().basesize (), TypeInt,
194196 &val);
195197 return val;
196- #else
197- int base = type().basetype;
198- if (base == TypeDesc::INT)
199- return get<int>(index);
200- if (base == TypeDesc::UINT)
201- return (int)get<unsigned int>(index);
202- if (base == TypeDesc::INT16)
203- return get<short>(index);
204- if (base == TypeDesc::UINT16)
205- return get<unsigned short>(index);
206- if (base == TypeDesc::INT8)
207- return get<char>(index);
208- if (base == TypeDesc::UINT8)
209- return get<unsigned char>(index);
210- if (base == TypeDesc::INT64)
211- return get<long long>(index);
212- if (base == TypeDesc::UINT64)
213- return get<unsigned long long>(index);
214- if (base == TypeDesc::STRING) {
215- // Only succeed for a string if it exactly holds something that
216- // exactly parses to an int value.
217- string_view str = get<ustring>(index);
218- int val = defaultval;
219- if (Strutil::parse_int(str, val) && str.empty())
220- return val;
221- }
222- return defaultval; // Some nonstandard type, fail
223- #endif
224198}
225199
226200
@@ -236,54 +210,11 @@ ParamValue::get_float(float defaultval) const
236210float
237211ParamValue::get_float_indexed (int index, float defaultval) const
238212{
239- #if 1 && OIIO_VERSION >= 20101
240213 float val = defaultval;
241214 convert_type (type ().elementtype (),
242215 (const char *)data () + index * type ().basesize (), TypeFloat,
243216 &val);
244217 return val;
245- #else
246- int base = type().basetype;
247- if (base == TypeDesc::FLOAT)
248- return get<float>(index);
249- if (base == TypeDesc::HALF)
250- return get<half>(index);
251- if (base == TypeDesc::DOUBLE)
252- return get<double>(index);
253- if (base == TypeDesc::INT) {
254- if (type().aggregate == TypeDesc::VEC2
255- && type().vecsemantics == TypeDesc::RATIONAL) {
256- int num = get<int>(2 * index + 0);
257- int den = get<int>(2 * index + 1);
258- return den ? float(num) / float(den) : 0.0f;
259- }
260- return get<int>(index);
261- }
262- if (base == TypeDesc::UINT)
263- return get<unsigned int>(index);
264- if (base == TypeDesc::INT16)
265- return get<short>(index);
266- if (base == TypeDesc::UINT16)
267- return get<unsigned short>(index);
268- if (base == TypeDesc::INT8)
269- return get<char>(index);
270- if (base == TypeDesc::UINT8)
271- return get<unsigned char>(index);
272- if (base == TypeDesc::INT64)
273- return get<long long>(index);
274- if (base == TypeDesc::UINT64)
275- return get<unsigned long long>(index);
276- if (base == TypeDesc::STRING) {
277- // Only succeed for a string if it exactly holds something
278- // that exactly parses to a float value.
279- string_view str = get<ustring>(index);
280- float val = defaultval;
281- if (Strutil::parse_float(str, val) && str.empty())
282- return val;
283- }
284-
285- return defaultval;
286- #endif
287218}
288219
289220
@@ -400,6 +331,8 @@ ParamValue::get_string_indexed(int index) const
400331 } else if (element.basetype == TypeDesc::PTR) {
401332 out += " ptr " ;
402333 formatType<void *>(*this , index, index + 1 , " {:p}" , out);
334+ } else if (element.basetype == TypeDesc::USTRINGHASH) {
335+ return get<ustringhash>(index).string ();
403336 } else {
404337 out += Strutil::fmt::format (
405338 " <unknown data type> (base {:d}, agg {:d} vec {:d})" ,
@@ -417,6 +350,8 @@ ParamValue::get_ustring(int maxsize) const
417350 // super inexpensive.
418351 if (type () == TypeDesc::STRING)
419352 return get<ustring>();
353+ if (type () == TypeDesc::USTRINGHASH)
354+ return ustring (get<ustringhash>());
420355 return ustring (get_string (maxsize));
421356}
422357
@@ -429,6 +364,8 @@ ParamValue::get_ustring_indexed(int index) const
429364 // super inexpensive.
430365 if (type () == TypeDesc::STRING)
431366 return get<ustring>(index);
367+ if (type () == TypeDesc::USTRINGHASH)
368+ return ustring (get<ustringhash>());
432369 return ustring (get_string_indexed (index));
433370}
434371
0 commit comments