Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Tobin Ehlis <tobin@lunarg.com> |
| 24 | * |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef LAYER_DATA_H |
| 28 | #define LAYER_DATA_H |
| 29 | |
| 30 | #include <unordered_map> |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 31 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 32 | |
| 33 | template<typename DATA_T> |
| 34 | DATA_T *get_my_data_ptr(void *data_key, |
| 35 | std::unordered_map<void *, DATA_T*> &layer_data_map) |
| 36 | { |
| 37 | DATA_T *debug_data; |
| 38 | typename std::unordered_map<void *, DATA_T *>::const_iterator got; |
| 39 | |
Courtney Goeltzenleuchter | db9a96f | 2015-07-05 11:19:03 -0600 | [diff] [blame] | 40 | /* TODO: We probably should lock here, or have caller lock */ |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 41 | got = layer_data_map.find(data_key); |
| 42 | |
| 43 | if ( got == layer_data_map.end() ) { |
| 44 | debug_data = new DATA_T; |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 45 | layer_data_map[(void *) data_key] = debug_data; |
| 46 | } else { |
| 47 | debug_data = got->second; |
| 48 | } |
| 49 | |
| 50 | return debug_data; |
| 51 | } |
| 52 | |
| 53 | #endif // LAYER_DATA_H |
| 54 | |