LLVM  8.0.1
Public Member Functions | List of all members
llvm::json::ObjectMapper Class Reference

Helper for mapping JSON objects onto protocol structs. More...

#include "llvm/Support/JSON.h"

Public Member Functions

 ObjectMapper (const Value &E)
 
 operator bool ()
 True if the expression is an object. More...
 
template<typename T >
bool map (StringRef Prop, T &Out)
 Maps a property to a field, if it exists. More...
 
template<typename T >
bool map (StringRef Prop, llvm::Optional< T > &Out)
 Maps a property to a field, if it exists. More...
 

Detailed Description

Helper for mapping JSON objects onto protocol structs.

Example:

bool fromJSON(const Value &E, MyStruct &R) {
if (!O || !O.map("mandatory_field", R.MandatoryField))
return false;
O.map("optional_field", R.OptionalField);
return true;
}

Definition at line 652 of file JSON.h.

Constructor & Destructor Documentation

◆ ObjectMapper()

llvm::json::ObjectMapper::ObjectMapper ( const Value E)
inline

Definition at line 654 of file JSON.h.

Member Function Documentation

◆ map() [1/2]

template<typename T >
bool llvm::json::ObjectMapper::map ( StringRef  Prop,
T Out 
)
inline

Maps a property to a field, if it exists.

Definition at line 661 of file JSON.h.

References assert(), E, llvm::json::fromJSON(), and llvm::RISCVFenceField::O.

◆ map() [2/2]

template<typename T >
bool llvm::json::ObjectMapper::map ( StringRef  Prop,
llvm::Optional< T > &  Out 
)
inline

Maps a property to a field, if it exists.

(Optional requires special handling, because missing keys are OK).

Definition at line 670 of file JSON.h.

References assert(), E, llvm::json::fromJSON(), llvm::None, llvm::RISCVFenceField::O, and llvm::json::parse().

◆ operator bool()

llvm::json::ObjectMapper::operator bool ( )
inline

True if the expression is an object.

Must be checked before calling map().

Definition at line 658 of file JSON.h.

References llvm::RISCVFenceField::O.


The documentation for this class was generated from the following file: