24#ifndef PXR_BASE_JS_CONVERTER_H
25#define PXR_BASE_JS_CONVERTER_H
33PXR_NAMESPACE_OPEN_SCOPE
37template <
class ValueType,
class MapType,
bool UseInt64 = true>
39 static ValueType Apply(
const JsValue& value) {
41 ValueType(value.
GetUInt64()) : ValueType(value.GetInt64());
47template <
class ValueType,
class MapType>
48struct Js_ValueToInt<ValueType, MapType, false>
50 static ValueType Apply(
const JsValue& value) {
51 return ValueType(value.
GetInt());
78template <
class ValueType,
class MapType,
bool UseInt64 = true>
81 typedef std::vector<ValueType> VectorType;
87 return _ToValueType(value);
92 static ValueType _ToValueType(
const JsValue& value) {
94 case JsValue::ObjectType:
95 return ValueType(_ObjectToMap(value.
GetJsObject()));
96 case JsValue::ArrayType:
97 return ValueType(_ArrayToVector(value.
GetJsArray()));
98 case JsValue::BoolType:
99 return ValueType(value.
GetBool());
100 case JsValue::StringType:
102 case JsValue::RealType:
103 return ValueType(value.
GetReal());
104 case JsValue::IntType:
105 return Js_ValueToInt<ValueType, MapType, UseInt64>::Apply(value);
106 case JsValue::NullType:
116 static MapType _ObjectToMap(
const JsObject&
object) {
118 for (
const auto& p :
object) {
119 result[p.first] = _ToValueType(p.second);
125 static VectorType _ArrayToVector(
const JsArray& array) {
127 result.reserve(array.size());
128 for (
const auto& value : array) {
129 result.push_back(_ToValueType(value));
138template <
class ValueType,
class MapType>
143PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
A discriminated union type for JSON values.
JS_API const JsArray & GetJsArray() const
Returns the array held by this value.
JS_API bool IsUInt64() const
Returns true if this value is holding a 64-bit unsigned integer.
JS_API Type GetType() const
Returns the type of this value.
JS_API double GetReal() const
Returns the double held by this value.
JS_API uint64_t GetUInt64() const
Returns the 64-bit unsigned integer held by this value.
JS_API const JsObject & GetJsObject() const
Returns the object held by this value.
JS_API bool GetBool() const
Returns the bool held by this value.
JS_API const std::string & GetString() const
Returns the string held by this value.
JS_API int GetInt() const
Returns the integer held by this value.
A helper class that can convert recursive JsValue structures to identical structures using a differen...
static ValueType Convert(const JsValue &value)
Converts the given value recursively to a structure using the value and map types specified by the Va...
ValueType JsConvertToContainerType(const JsValue &value)
Returns value converted recursively to the template and map types given by the ValueType and MapType ...
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.