nixd
Loading...
Searching...
No Matches
JSON.h
Go to the documentation of this file.
1#pragma once
2
3#include "Exception.h"
4
5#include <llvm/ADT/StringRef.h>
6#include <llvm/Support/JSON.h>
7
8#include <exception>
9
10namespace nixd {
11
13public:
14 JSONParseException(llvm::Error E) : LLVMErrorException(std::move(E)) {}
15
16 [[nodiscard]] const char *what() const noexcept override {
17 return "JSON result cannot be parsed";
18 }
19};
20
22public:
23 JSONSchemaException(llvm::Error E) : LLVMErrorException(std::move(E)) {}
24
25 [[nodiscard]] const char *what() const noexcept override {
26 return "JSON schema mismatch";
27 }
28};
29
30llvm::json::Value parse(llvm::StringRef JSON);
31
32template <class T> T fromJSON(const llvm::json::Value &V) {
33 llvm::json::Path::Root R;
34 T Result;
35 if (!fromJSON(V, Result, R))
36 throw JSONSchemaException(R.getError());
37 return Result;
38}
39
40} // namespace nixd
const char * what() const noexcept override
Definition JSON.h:16
JSONParseException(llvm::Error E)
Definition JSON.h:14
JSONSchemaException(llvm::Error E)
Definition JSON.h:23
const char * what() const noexcept override
Definition JSON.h:25
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
llvm::json::Value parse(llvm::StringRef JSON)
Definition JSON.cpp:5