25 #ifndef PXR_BASE_JS_JSON_H
26 #define PXR_BASE_JS_JSON_H
139 template<
class K,
class V>
141 _WriteObjectFields(std::forward<K>(k), std::forward<V>(
v));
154 template <
class Container>
157 for (
const auto& i : c) {
165 template <
class Container,
class ItemWriteFn>
168 for (
const auto& i : c) {
176 template <
class Iterator,
class ItemWriteFn>
178 const Iterator&
begin,
const Iterator&
end,
const ItemWriteFn&
f) {
180 for (Iterator i = begin; i !=
end; ++i) {
189 template<
class ...T>
191 static_assert(
sizeof...(
T) %2 == 0,
192 "Arguments must come in key value pairs");
194 _WriteObjectFields(std::forward<T>(
f)...);
203 JS_API bool _String(
const char*
s,
size_t len);
204 JS_API bool _Key(
const char*
s,
size_t len);
206 template <
class KeyType,
class T>
207 auto _WriteObjectFields(KeyType&& key,
T&&
v)
208 -> decltype(
WriteValue(std::forward<T>(
v)),
void()) {
209 WriteKey(std::forward<KeyType>(key));
213 template <
class KeyType,
class T>
214 auto _WriteObjectFields(KeyType&& key,
T&&
v)
215 -> decltype(
v(std::declval<JsWriter&>()),
void()) {
216 WriteKey(std::forward<KeyType>(key));
220 template<
class Key0,
class T0,
class ...T>
221 void _WriteObjectFields(Key0&& key0, T0&& f0,
T&&...
f){
222 _WriteObjectFields(std::forward<Key0>(key0), std::forward<T0>(f0));
223 _WriteObjectFields(std::forward<T>(
f)...);
227 std::unique_ptr<_Impl> _impl;
235 #endif // PXR_BASE_JS_JSON_H
JS_API void JsWriteToStream(const JsValue &value, std::ostream &ostr)
GLsizei const GLchar *const * string
JS_API bool WriteValue(std::nullptr_t)
Write a null value.
void WriteObject(T &&...f)
JS_API bool BeginArray()
Write the start of an array.
JsWriter & operator=(const JsWriter &)=delete
void WriteKeyValue(K &&k, V &&v)
Convenience function to write an object key and value.
void WriteArray(const Container &c)
Convenience function to write an array of values.
JS_API bool EndObject()
Write the end of an object.
JS_API JsWriter(std::ostream &ostr, Style style=Style::Compact)
JS_API bool BeginObject()
Write the start of an object.
JS_API ~JsWriter()
Destructor.
bool WriteKey(const char(&s)[N])
Write a string literal object key.
GLboolean GLboolean GLboolean b
bool WriteValue(const char(&s)[N])
Write a string value.
JS_API bool WriteKey(const std::string &)
Write an object key.
JS_API bool EndArray()
Write the end of an array.
void WriteArray(const Container &c, const ItemWriteFn &f)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
void WriteArray(const Iterator &begin, const Iterator &end, const ItemWriteFn &f)
#define PXR_NAMESPACE_CLOSE_SCOPE
JS_API void JsWriteValue(JsWriter *writer, const JsValue &value)
Write a json value.
GA_API const UT_StringHolder N
JS_API JsValue JsParseString(const std::string &data, JsParseError *error=0)
JS_API JsValue JsParseStream(std::istream &istr, JsParseError *error=0)
GLenum GLenum GLsizei void GLsizei void * column
JS_API std::string JsWriteToString(const JsValue &value)
Convert the JsValue value to JSON and return it as a string.
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.