7#ifndef PXR_BASE_JS_CONVERTER_H
8#define PXR_BASE_JS_CONVERTER_H
16PXR_NAMESPACE_OPEN_SCOPE
20template <
class ValueType,
class MapType,
bool UseInt64 = true>
22 static ValueType Apply(
const JsValue& value) {
24 ValueType(value.
GetUInt64()) : ValueType(value.GetInt64());
30template <
class ValueType,
class MapType>
31struct Js_ValueToInt<ValueType, MapType, false>
33 static ValueType Apply(
const JsValue& value) {
34 return ValueType(value.
GetInt());
61template <
class ValueType,
class MapType,
bool UseInt64 = true>
64 typedef std::vector<ValueType> VectorType;
70 return _ToValueType(value);
75 static ValueType _ToValueType(
const JsValue& value) {
77 case JsValue::ObjectType:
78 return ValueType(_ObjectToMap(value.
GetJsObject()));
79 case JsValue::ArrayType:
80 return ValueType(_ArrayToVector(value.
GetJsArray()));
81 case JsValue::BoolType:
82 return ValueType(value.
GetBool());
83 case JsValue::StringType:
85 case JsValue::RealType:
86 return ValueType(value.
GetReal());
87 case JsValue::IntType:
88 return Js_ValueToInt<ValueType, MapType, UseInt64>::Apply(value);
89 case JsValue::NullType:
99 static MapType _ObjectToMap(
const JsObject&
object) {
101 for (
const auto& p :
object) {
102 result[p.first] = _ToValueType(p.second);
108 static VectorType _ArrayToVector(
const JsArray& array) {
110 result.reserve(array.size());
111 for (
const auto& value : array) {
112 result.push_back(_ToValueType(value));
121template <
class ValueType,
class MapType>
126PXR_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.