1 /* Copyright (c) 2015-2016 The Khronos Group Inc. 2 * Copyright (c) 2015-2016 Valve Corporation 3 * Copyright (c) 2015-2016 LunarG, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * Author: Tobin Ehlis <tobin (at) lunarg.com> 18 */ 19 20 #ifndef LAYER_DATA_H 21 #define LAYER_DATA_H 22 23 #include <unordered_map> 24 #include "vk_layer_table.h" 25 26 template <typename DATA_T> DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) { 27 DATA_T *debug_data; 28 typename std::unordered_map<void *, DATA_T *>::const_iterator got; 29 30 /* TODO: We probably should lock here, or have caller lock */ 31 got = layer_data_map.find(data_key); 32 33 if (got == layer_data_map.end()) { 34 debug_data = new DATA_T; 35 layer_data_map[(void *)data_key] = debug_data; 36 } else { 37 debug_data = got->second; 38 } 39 40 return debug_data; 41 } 42 43 #endif // LAYER_DATA_H 44