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) {
23 return value.IsUInt64() ?
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) {
76 switch (value.GetType()) {
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:
84 return ValueType(value.GetString());
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.
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.