blob: c41b653fea221fdadd171a893b8d4812b40825c0 [file] [log] [blame]
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -06001/*
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -06004 *
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 Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Tobin Ehlis <tobin@lunarg.com>
24 *
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060025 */
26
27#ifndef LAYER_DATA_H
28#define LAYER_DATA_H
29
30#include <unordered_map>
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060031#include "vk_layer_table.h"
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060032
33template<typename DATA_T>
34DATA_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 Goeltzenleuchterdb9a96f2015-07-05 11:19:03 -060040 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060041 got = layer_data_map.find(data_key);
42
43 if ( got == layer_data_map.end() ) {
44 debug_data = new DATA_T;
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060045 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