1 /* 2 Copyright (c) 2015-2021 The Khronos Group Inc. 3 Copyright (c) 2015-2021 Valve Corporation 4 Copyright (c) 2015-2021 LunarG, Inc. 5 6 Permission is hereby granted, free of charge, to any person obtaining a copy 7 of this software and associated documentation files (the "Software"), to deal 8 in the Software without restriction, including without limitation the rights 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 copies of the Software, and to permit persons to whom the Software is 11 furnished to do so, subject to the following conditions: 12 13 The above copyright notice and this permission notice shall be included in 14 all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 THE SOFTWARE. 23 */ 24 25 #pragma once 26 27 #include <stddef.h> 28 29 #include <vulkan/vulkan_core.h> 30 31 #include <cJSON.h> 32 33 // Forward decls 34 struct loader_instance; 35 struct loader_string_list; 36 37 // Read a JSON file into a buffer. 38 // 39 // @return - A pointer to a cJSON object representing the JSON parse tree. 40 // This returned buffer should be freed by caller. 41 TEST_FUNCTION_EXPORT VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json); 42 43 // Given a cJSON object, find the string associated with the key and puts an pre-allocated string into out_string. 44 // Length is given by out_str_len, and this function truncates the string with a null terminator if it the provided space isn't 45 // large enough. 46 VkResult loader_parse_json_string_to_existing_str(cJSON *object, const char *key, size_t out_str_len, char *out_string); 47 48 // Given a cJSON object, find the string associated with the key and puts an allocated string into out_string. 49 // It is the callers responsibility to free out_string. 50 VkResult loader_parse_json_string(cJSON *object, const char *key, char **out_string); 51 52 // Given a cJSON object, find the array of strings associated with they key and writes the count into out_count and data into 53 // out_array_of_strings. It is the callers responsibility to free out_array_of_strings. 54 VkResult loader_parse_json_array_of_strings(const struct loader_instance *inst, cJSON *object, const char *key, 55 struct loader_string_list *string_list); 56