mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 22:56:30 -10:00
* use std::move() for local variables that are copied but not reused Addresses ~140 Coverity "Variable copied when it could be moved" defects across 74 files. Every std::move() targets a local variable whose value is consumed by push_back, emplace, assignment, lambda capture, or a function call and is never read again afterward. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * clang: use std::make_shared * clang: use std::make_unique * address feedback --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
|
|
#include "ProgramVariables.h"
|
|
|
|
namespace actions {
|
|
namespace expression {
|
|
|
|
ProgramVariablesDefinition& ProgramVariablesDefinition::addScope(const SCP_string& name)
|
|
{
|
|
auto scope = std::make_unique<ProgramVariablesDefinition>();
|
|
|
|
auto scopePtr = scope.get();
|
|
|
|
m_scopes.insert(std::make_pair(name, std::move(scope)));
|
|
|
|
return *scopePtr;
|
|
}
|
|
void ProgramVariablesDefinition::addMember(const SCP_string& name, ValueType type)
|
|
{
|
|
m_memberTypes[name] = type;
|
|
}
|
|
ProgramVariablesDefinition* ProgramVariablesDefinition::getScope(const SCP_string& name) const
|
|
{
|
|
const auto iter = m_scopes.find(name);
|
|
|
|
if (iter == m_scopes.cend()) {
|
|
return nullptr;
|
|
}
|
|
|
|
return iter->second.get();
|
|
}
|
|
ValueType ProgramVariablesDefinition::getMemberType(const SCP_string& name) const
|
|
{
|
|
const auto iter = m_memberTypes.find(name);
|
|
|
|
if (iter == m_memberTypes.cend()) {
|
|
return ValueType::Invalid;
|
|
}
|
|
|
|
return iter->second;
|
|
}
|
|
|
|
Value ProgramVariables::getValue(std::initializer_list<const char*> memberPathParts) const
|
|
{
|
|
return getValue<decltype(memberPathParts)>(memberPathParts);
|
|
}
|
|
void ProgramVariables::setValue(std::initializer_list<const char*> memberPathParts, Value value)
|
|
{
|
|
setValue<decltype(memberPathParts)>(memberPathParts, std::move(value));
|
|
}
|
|
Value ProgramVariables::getValue(const SCP_string& fullMemberName) const
|
|
{
|
|
const auto iter = m_values.find(fullMemberName);
|
|
|
|
// This should have been validated earlier
|
|
Assertion(iter != m_values.end(), "Could not find member %s in variables!", fullMemberName.c_str());
|
|
|
|
return iter->second;
|
|
}
|
|
|
|
} // namespace expression
|
|
} // namespace actions
|