• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKSSTORE_HPP
2 #define _VKSSTORE_HPP
3 
4 /*-------------------------------------------------------------------------
5  * Vulkan CTS Framework
6  * --------------------
7  *
8  * Copyright (c) 2021 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *-------------------------------------------------------------------------*/
23 
24 #include "vksCommon.hpp"
25 
26 #include <mutex>
27 #include <map>
28 
29 namespace vksc_server
30 {
31 
32 struct Store
33 {
Getvksc_server::Store34 	bool Get (const string& path, vector<u8>& content, bool removeAfter)
35 	{
36 		std::lock_guard<std::mutex> lock(FileMapMutex);
37 
38 		auto it = FileMap.find(path);
39 		if (it != FileMap.end())
40 		{
41 			if (removeAfter)
42 			{
43 				content = std::move(it->second);
44 				FileMap.erase(it);
45 			}
46 			else
47 			{
48 				content = it->second;
49 			}
50 			return true;
51 		}
52 		return false;
53 	}
54 
Setvksc_server::Store55 	bool Set (const string& uniqueFilename, const vector<u8>& content)
56 	{
57 		std::lock_guard<std::mutex> lock(FileMapMutex);
58 		FileMap[uniqueFilename] = std::move(content);
59 		return true;
60 	}
61 
62 private:
63 	std::map<string, vector<u8>> FileMap;
64 	std::mutex FileMapMutex;
65 };
66 
67 }
68 
69 #endif // _VKSSTORE_HPP
70