65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// GNU Lesser General Public License v3.0
|
|
// Copyright (c) 2023 Bart Beumer <bart@4beumer.nl>
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify it
|
|
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
|
// the Free Software Foundation.
|
|
//
|
|
#include "bmrshared/ToTupleException.hpp"
|
|
#include <exception>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <utility>
|
|
|
|
namespace bmrshared
|
|
{
|
|
ToTupleException::ToTupleException(std::vector<std::string> keysMissing,
|
|
std::vector<std::string> keysNotUsed,
|
|
std::vector<ParamError> paramErrors)
|
|
: m_keysMissing(std::move(keysMissing))
|
|
, m_keysNotUsed(std::move(keysNotUsed))
|
|
, m_paramErrors(std::move(paramErrors))
|
|
, m_what(GenerateWhat(m_keysMissing, m_keysNotUsed, m_paramErrors))
|
|
{
|
|
}
|
|
|
|
ToTupleException::~ToTupleException() = default;
|
|
|
|
const std::vector<std::string>& ToTupleException::GetKeysMissing() const
|
|
{
|
|
return m_keysMissing;
|
|
}
|
|
|
|
const std::vector<std::string>& ToTupleException::GetKeysNotUsed() const
|
|
{
|
|
return m_keysNotUsed;
|
|
}
|
|
|
|
const char* ToTupleException::what() const noexcept
|
|
{
|
|
return m_what.c_str();
|
|
}
|
|
|
|
std::string ToTupleException::GenerateWhat(const std::vector<std::string>& keysMissing,
|
|
const std::vector<std::string>& keysNotUsed,
|
|
const std::vector<ParamError>& paramErrors)
|
|
{
|
|
std::stringstream ss;
|
|
ss << "Errors while converting to tuple.";
|
|
for (const auto& key : keysMissing)
|
|
{
|
|
ss << "\n - missing: " << key;
|
|
}
|
|
for (const auto& key : keysNotUsed)
|
|
{
|
|
ss << "\n - unused: " << key;
|
|
}
|
|
for (const auto& error : paramErrors)
|
|
{
|
|
ss << "\n - error: " << error.name << " \"" << error.type << "\"";
|
|
}
|
|
return ss.str();
|
|
}
|
|
} // namespace bmrshared
|