Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
LoadLookupTable.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace sgui
7{
12template <typename Key,
13 typename Type>
15 std::unordered_map <Key, Type>& table,
16 const std::string& file)
17{
18 // parse from json
19 json j = sgui::loadFromFile (file);
20 std::unordered_map <Key, Type> tableData = j;
21 for (const auto& data : tableData) {
22 table.insert ({data.first, data.second});
23 }
24 return true;
25}
26
28template <typename Key,
29 typename Type>
31 const std::unordered_map <Key, Type>& table,
32 const std::string& file,
33 const bool compact = false)
34{
35 // parse in json
36 json out = table;
37
38 // write in file
39 auto output = std::ofstream (file);
40 if (compact) {
41 output << out << std::endl;
42 } else {
43 output << std::setw (2) << out << std::endl;
44 }
45 output.close ();
46}
47
48} // namespace sgui
nlohmann::json json
Definition LoadJson.h:8
Definition Interpolation.h:16
void saveInFile(const json &out, const std::string &file, const bool compact)
save json to file
Definition LoadJson.cpp:6
json loadFromFile(const std::string &file)
load json from file
Definition LoadJson.cpp:21