Files
spark/src/lib/config/ConfigErrorCollector.cpp
T
2017-08-07 17:21:12 -04:00

73 lines
2.0 KiB
C++
Executable File

#include "ConfigErrorCollector.h"
#include <string>
namespace bts {
namespace config {
namespace internal {
ConfigErrorCollector::ConfigErrorCollector(IConfigLog& log, const char* file):
_log(log),
_file(file),
_errors()
{
}
inline std::string format(const std::string& file, int line, int column, const std::string& message)
{
std::stringstream buffer;
buffer << file.c_str() << ":" << line+1 << ":" << column+1 << ": error: " << message;
return buffer.str();
}
void ConfigErrorCollector::AddError(int line, int column, const std::string& message)
{
_errors.push_back(format(_file, line, column, message));
}
void ConfigErrorCollector::AddWarning(int line, int column, const std::string& message)
{
_log.warning(format(_file, line, column, message));
}
// For debugging purposes
void ConfigErrorCollector::AddError(
const std::string& , // File name in which the error occurred.
const std::string& , // Full name of the erroneous element.
const proto::Message* , // Descriptor of the erroneous element.
ErrorLocation , // One of the location constants, above.
const std::string& // Human-readable error message.
)
{
//_log.warning(format(filename, 0, 0, message));
}
// For debugging purposes
void ConfigErrorCollector::AddWarning(
const std::string& , // File name in which the error occurred.
const std::string& , // Full name of the erroneous element.
const proto::Message* , // Descriptor of the erroneous element.
ErrorLocation , // One of the location constants, above.
const std::string& // Human-readable error message.
)
{
//_log.warning(format(filename, 0, 0, message));
}
std::string ConfigErrorCollector::ToString()
{
if (_errors.size() == 0) return "";
std::string error = _errors.front();
for (size_t x = 1; x < _errors.size(); x++)
{
error += '\n';
error += _errors[x];
}
return error;
}
}}}//namespace