7 #ifndef PXR_BASE_JS_VALUE_H
8 #define PXR_BASE_JS_VALUE_H
21 #include <type_traits>
30 #define JS_VALUE_API_VERSION 2
146 template <
typename T,
147 typename ReturnType =
typename std::conditional<
153 return _Get(static_cast<T*>(
nullptr));
162 template <
typename T>
194 template <
typename T>
196 return _Is(static_cast<T*>(
nullptr));
201 template <
typename T>
220 lhs._value.swap(rhs._value);
224 template <
typename T>
225 struct _InvalidTypeHelper :
public std::false_type { };
230 "Invalid type for JsValue");
236 const std::string& _Get(std::string*)
const {
return GetString(); }
237 bool _Get(
bool*)
const {
return GetBool(); }
238 int _Get(
int*)
const {
return GetInt(); }
239 int64_t _Get(int64_t*)
const {
return GetInt64(); }
240 uint64_t _Get(uint64_t*)
const {
return GetUInt64(); }
241 double _Get(
double*)
const {
return GetReal(); }
246 "Invalid type for JsValue");
252 bool _Is(std::string*)
const {
return IsString(); }
253 bool _Is(
bool*)
const {
return IsBool(); }
254 bool _Is(
int*)
const {
return IsInt(); }
255 bool _Is(int64_t*)
const {
return IsInt(); }
256 bool _Is(uint64_t*)
const {
return IsUInt64(); }
257 bool _Is(
double*)
const {
return IsReal(); }
269 template <enum Type EnumValue>
273 _HolderBase() =
default;
274 ~_HolderBase() =
default;
278 h->_refCount.fetch_add(1, std::memory_order_relaxed);
282 const int rc =
h->_refCount.fetch_sub(1, std::memory_order_release);
284 std::atomic_thread_fence(std::memory_order_acquire);
289 static JS_API void _Delete(
const _HolderBase *) noexcept;
292 mutable std::atomic<
int> _refCount = 1;
295 template <typename> struct _Holder;
296 struct _IsValueEqualVisitor;
313 using _Variant = std::variant<
317 bool, int64_t, double, _JsNull, uint64_t>;
322 template <
typename T>
326 std::vector<T>
result(array.size());
332 template <
typename T>
339 return std::all_of(array.begin(), array.end(),
345 #endif // PXR_BASE_JS_VALUE_H
JS_API int GetInt() const
JS_API int64_t GetInt64() const
JS_API bool IsString() const
Returns true if this value is holding a string type.
JS_API bool IsObject() const
Returns true if this value is holding an object type.
void TfDelegatedCountIncrement(VdfMask::_BitsImpl *p) noexcept
#define PXR_NAMESPACE_OPEN_SCOPE
GLsizei const GLfloat * value
JS_API bool operator!=(const JsValue &other) const
JS_API bool IsArray() const
Returns true if this value is holding an array type.
JS_API double GetReal() const
**But if you need a result
std::vector< JsValue > JsArray
JS_API const std::string & GetString() const
JS_API bool IsInt() const
Returns true if this value is holding an integer type.
GLint GLint GLsizei GLint GLenum GLenum type
JS_API bool IsBool() const
Returns true if this value is holding a boolean type.
JS_API bool operator==(const JsValue &other) const
JS_API JsValue()
Constructs a null value.
std::map< std::string, JsValue > JsObject
GA_API const UT_StringHolder transform
JS_API bool IsNull() const
Returns true if this value is null, false otherwise.
GLfloat GLfloat GLfloat GLfloat h
JS_API Type GetType() const
Returns the type of this value.
JS_API bool IsReal() const
Returns true if this value is holding a real type.
JS_API uint64_t GetUInt64() const
friend void swap(JsValue &lhs, JsValue &rhs)
Swap the value held by lhs with the value held by rhs.
JS_API bool GetBool() const
JS_API const JsArray & GetJsArray() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Type
Type held by this JSON value.
JS_API std::string GetTypeName() const
Returns a display name for the type of this value.
JS_API const JsObject & GetJsObject() const
std::vector< T > GetArrayOf() const
JS_API bool IsUInt64() const
Returns true if this value is holding a 64-bit unsigned integer.
void TfDelegatedCountDecrement(VdfMask::_BitsImpl *p) noexcept