Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in 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 |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #ifndef LAYER_DATA_H |
| 29 | #define LAYER_DATA_H |
| 30 | |
| 31 | #include <unordered_map> |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 32 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 33 | |
| 34 | template<typename DATA_T> |
| 35 | DATA_T *get_my_data_ptr(void *data_key, |
| 36 | std::unordered_map<void *, DATA_T*> &layer_data_map) |
| 37 | { |
| 38 | DATA_T *debug_data; |
| 39 | typename std::unordered_map<void *, DATA_T *>::const_iterator got; |
| 40 | |
Courtney Goeltzenleuchter | d97cc72 | 2015-07-05 11:19:03 -0600 | [diff] [blame] | 41 | /* TODO: We probably should lock here, or have caller lock */ |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 42 | got = layer_data_map.find(data_key); |
| 43 | |
| 44 | if ( got == layer_data_map.end() ) { |
| 45 | debug_data = new DATA_T; |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 46 | layer_data_map[(void *) data_key] = debug_data; |
| 47 | } else { |
| 48 | debug_data = got->second; |
| 49 | } |
| 50 | |
| 51 | return debug_data; |
| 52 | } |
| 53 | |
| 54 | #endif // LAYER_DATA_H |
| 55 | |