forked from Return-To-The-Roots/s25client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckedLuaTable.cpp
More file actions
35 lines (30 loc) · 1.24 KB
/
Copy pathCheckedLuaTable.cpp
File metadata and controls
35 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later
#include "CheckedLuaTable.h"
#include "helpers/containerUtils.h"
#include "s25util/Log.h"
#include <boost/algorithm/string/join.hpp>
#include <algorithm>
#include <utility>
CheckedLuaTable::CheckedLuaTable(kaguya::LuaTable luaTable) : table(std::move(luaTable)), checkEnabled(false) {}
// NOLINTNEXTLINE(bugprone-exception-escape)
CheckedLuaTable::~CheckedLuaTable() noexcept(false)
{
if(checkEnabled)
checkUnused();
}
void CheckedLuaTable::checkUnused()
{
checkEnabled = false;
std::vector<std::string> tableKeys = table.keys<std::string>();
helpers::sort(tableKeys);
std::vector<std::string> unusedKeys;
std::set_difference(tableKeys.begin(), tableKeys.end(), accessedKeys_.begin(), accessedKeys_.end(),
std::back_inserter(unusedKeys));
for(const std::string& unusedKey : unusedKeys)
LOG.write("\nERROR: Did not use key '%1%' in a lua table. This is most likely a bug!\n") % unusedKey;
RTTR_Assert(unusedKeys.empty());
if(!unusedKeys.empty())
throw std::runtime_error("Did not use keys " + boost::algorithm::join(unusedKeys, ", ") + " in lua table!");
}