]> git.saurik.com Git - apple/dyld.git/blob - dyld3/JSONReader.h
dyld-832.7.1.tar.gz
[apple/dyld.git] / dyld3 / JSONReader.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26 #ifndef __JSON_READER_H__
27 #define __JSON_READER_H__
28
29 #include "JSON.h"
30
31 class Diagnostics;
32
33 namespace dyld3 {
34 namespace json {
35
36 Node readJSON(Diagnostics& diags, const char* filePath);
37 Node readJSON(Diagnostics& diags, const void* contents, size_t length);
38
39 // Given a map node, returns the node representing the given value.
40 // If it is missing, returns a sentinel node and sets an error on the diagnostic
41 const Node& getRequiredValue(Diagnostics& diags, const Node& node, const char* key);
42
43 // Given a map node, returns the node representing the given value.
44 // If it is missing, return nullptr.
45 const Node* getOptionalValue(Diagnostics& diags, const Node& node, const char* key);
46
47 // Parses an int from the given node, or throws an error if its not an integer payload
48 uint64_t parseRequiredInt(Diagnostics& diags, const Node& node);
49
50 // Parses a bool from the given node, or throws an error if its not a boolean payload
51 bool parseRequiredBool(Diagnostics& diags, const Node& node);
52
53 // Parses a string from the given node, or throws an error if its not a string payload
54 const std::string& parseRequiredString(Diagnostics& diags, const Node& node);
55
56
57 } // namespace json
58 } // namespace dyld3
59
60
61 #endif // __JSON_READER_H__