nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
include
nixd
Support
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
10
namespace
nixd
{
11
12
class
JSONParseException
:
public
LLVMErrorException
{
13
public
:
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
21
class
JSONSchemaException
:
public
LLVMErrorException
{
22
public
:
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
30
llvm::json::Value
parse
(llvm::StringRef JSON);
31
32
template
<
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
Exception.h
nixd::JSONParseException::what
const char * what() const noexcept override
Definition
JSON.h:16
nixd::JSONParseException::JSONParseException
JSONParseException(llvm::Error E)
Definition
JSON.h:14
nixd::JSONSchemaException
Definition
JSON.h:21
nixd::JSONSchemaException::JSONSchemaException
JSONSchemaException(llvm::Error E)
Definition
JSON.h:23
nixd::JSONSchemaException::what
const char * what() const noexcept override
Definition
JSON.h:25
nixd::LLVMErrorException::LLVMErrorException
LLVMErrorException(llvm::Error E)
Definition
Exception.h:13
nixd
Definition
CommandLine/Configuration.h:9
nixd::fromJSON
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
nixd::parse
llvm::json::Value parse(llvm::StringRef JSON)
Definition
JSON.cpp:5
Generated by
1.17.0