blob: 263603b121321575b0874c66e3efdbf632d05a1c [file] [log] [blame]
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -06001/*
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 Ehlis56d204a2015-07-03 10:15:26 -060032#include "vk_layer_table.h"
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060033
34template<typename DATA_T>
35DATA_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 Goeltzenleuchterd97cc722015-07-05 11:19:03 -060041 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060042 got = layer_data_map.find(data_key);
43
44 if ( got == layer_data_map.end() ) {
45 debug_data = new DATA_T;
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060046 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