LLVM
8.0.1
|
A Value is an JSON value of unknown type. More...
#include "llvm/Support/JSON.h"
Public Types | |
enum | Kind { Null, Boolean, Number, String, Array, Object } |
Public Member Functions | |
Value (const Value &M) | |
Value (Value &&M) | |
Value (std::initializer_list< Value > Elements) | |
Value (json::Array &&Elements) | |
template<typename Elt > | |
Value (const std::vector< Elt > &C) | |
Value (json::Object &&Properties) | |
template<typename Elt > | |
Value (const std::map< std::string, Elt > &C) | |
Value (std::string V) | |
Value (const llvm::SmallVectorImpl< char > &V) | |
Value (const llvm::formatv_object_base &V) | |
Value (StringRef V) | |
Value (const char *V) | |
Value (std::nullptr_t) | |
template<typename T , typename = typename std::enable_if<std::is_same<T, bool>::value>::type, bool = false> | |
Value (T B) | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type, typename = typename std::enable_if<!std::is_same<T, bool>::value>::type> | |
Value (T I) | |
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type, double * = nullptr> | |
Value (T D) | |
template<typename T , typename = typename std::enable_if<std::is_same< Value, decltype(toJSON(*(const T *)nullptr))>::value>, Value * = nullptr> | |
Value (const T &V) | |
Value & | operator= (const Value &M) |
Value & | operator= (Value &&M) |
~Value () | |
Kind | kind () const |
llvm::Optional< std::nullptr_t > | getAsNull () const |
llvm::Optional< bool > | getAsBoolean () const |
llvm::Optional< double > | getAsNumber () const |
llvm::Optional< int64_t > | getAsInteger () const |
llvm::Optional< llvm::StringRef > | getAsString () const |
const json::Object * | getAsObject () const |
json::Object * | getAsObject () |
const json::Array * | getAsArray () const |
json::Array * | getAsArray () |
Friends | |
class | Array |
class | Object |
struct | llvm::format_provider< llvm::json::Value > |
llvm::raw_ostream & | operator<< (llvm::raw_ostream &, const Value &) |
Serializes this Value to JSON, writing it to the provided stream. More... | |
bool | operator== (const Value &, const Value &) |
A Value is an JSON value of unknown type.
They can be copied, but should generally be moved.
=== Composing values ===
You can implicitly construct Values from:
They can also be constructed from object/array helpers:
=== Inspecting values ===
Each Value is one of the JSON kinds: null (nullptr_t) boolean (bool) number (double or int64) string (StringRef) array (json::Array) object (json::Object)
The kind can be queried directly, or implicitly via the typed accessors: if (Optional<StringRef> S = E.getAsString() assert(E.kind() == Value::String);
Array and Object also have typed indexing accessors for easy traversal: Expected<Value> E = parse(R"( {"options": {"font": "sans-serif"}} )"); if (Object* O = E->getAsObject()) if (Object* Opts = O->getObject("options")) if (Optional<StringRef> Font = Opts->getString("font")) assert(Opts->at("font").kind() == Value::String);
=== Converting JSON values to C++ types ===
The convention is to have a deserializer function findable via ADL: fromJSON(const json::Value&, T&)->bool Deserializers are provided for:
For conversion in the other direction, the serializer function is: toJSON(const T&) -> json::Value If this exists, then it also allows constructing Value from T, and can be used to serialize vector<T>, map<string, T>, and Optional<T>.
=== Serialization ===
Values can be serialized to JSON: 1) raw_ostream << Value // Basic formatting. 2) raw_ostream << formatv("{0}", Value) // Basic formatting. 3) raw_ostream << formatv("{0:2}", Value) // Pretty-print with indent 2.
And parsed: Expected<Value> E = json::parse("[1, 2, null]"); assert(E && E->kind() == Value::Array);
llvm::json::Value::Value | ( | std::initializer_list< Value > | Elements | ) |
Definition at line 100 of file JSON.cpp.
References Array, llvm::Intrinsic::memcpy, and Object.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 305 of file JSON.h.
References assert(), llvm::json::fixUTF8(), llvm::json::isUTF8(), and LLVM_UNLIKELY.
|
inline |
|
inline |
|
inline |
Definition at line 316 of file JSON.h.
References assert(), llvm::json::fixUTF8(), llvm::json::isUTF8(), and LLVM_UNLIKELY.
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 347 of file JSON.h.
References T, and llvm::json::toJSON().
|
inline |
Definition at line 433 of file JSON.h.
References LLVM_LIKELY.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 436 of file JSON.h.
References LLVM_LIKELY, and llvm::json::operator<<().
|
inline |
Definition at line 395 of file JSON.h.
References LLVM_LIKELY, and llvm::None.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 408 of file JSON.h.
References D, LLVM_LIKELY, llvm::max(), and llvm::None.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 390 of file JSON.h.
References LLVM_LIKELY, and llvm::None.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 400 of file JSON.h.
References LLVM_LIKELY, and llvm::None.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 427 of file JSON.h.
References LLVM_LIKELY.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 430 of file JSON.h.
References LLVM_LIKELY.
|
inline |
Definition at line 420 of file JSON.h.
References LLVM_LIKELY, and llvm::None.
Referenced by llvm::json::fromJSON(), and llvm::json::operator==().
|
inline |
Definition at line 369 of file JSON.h.
References llvm_unreachable, Number, and llvm::json::Object::Object().
Referenced by llvm::json::operator==().
|
friend |
Definition at line 452 of file JSON.h.
Referenced by llvm::json::operator==(), and Value().
|
friend |
|
friend |
Definition at line 453 of file JSON.h.
Referenced by llvm::json::operator==(), and Value().
|
friend |
Serializes this Value to JSON, writing it to the provided stream.
The formatting is compact (no extra whitespace) and deterministic. For pretty-printing, use the formatv() format_provider below.