2012-03-08 18:51:23 +01:00
|
|
|
#include <mapnik/config_error.hpp>
|
2013-07-24 00:59:05 +02:00
|
|
|
#include <mapnik/xml_node.hpp>
|
2012-12-07 05:15:27 +01:00
|
|
|
#include <mapnik/util/conversions.hpp>
|
2012-03-08 18:51:23 +01:00
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
2012-03-12 01:09:26 +01:00
|
|
|
|
|
|
|
config_error::config_error(std::string const& what)
|
2012-12-07 03:46:23 +01:00
|
|
|
: what_(what),
|
|
|
|
line_number_(0),
|
|
|
|
file_(),
|
|
|
|
node_name_(),
|
|
|
|
msg_()
|
2012-03-12 01:09:26 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-07 03:46:23 +01:00
|
|
|
config_error::config_error(std::string const& what,
|
|
|
|
xml_node const& node)
|
|
|
|
: what_(what),
|
|
|
|
line_number_(node.line()),
|
|
|
|
file_(node.filename()),
|
|
|
|
node_name_(node.name()),
|
|
|
|
msg_()
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-07 03:46:23 +01:00
|
|
|
config_error::config_error(std::string const& what,
|
|
|
|
unsigned line_number,
|
|
|
|
std::string const& filename)
|
|
|
|
: what_(what),
|
|
|
|
line_number_(line_number),
|
|
|
|
file_(filename),
|
|
|
|
node_name_(),
|
|
|
|
msg_()
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-13 15:56:11 +01:00
|
|
|
char const* config_error::what() const throw()
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
2012-12-07 05:15:27 +01:00
|
|
|
msg_ = what_;
|
|
|
|
if (!node_name_.empty())
|
|
|
|
{
|
|
|
|
msg_ += " in " + node_name_;
|
|
|
|
}
|
|
|
|
if (line_number_ > 0)
|
|
|
|
{
|
|
|
|
std::string number;
|
|
|
|
if (util::to_string(number,line_number_))
|
|
|
|
{
|
|
|
|
msg_ += " at line " + number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!file_.empty())
|
|
|
|
{
|
|
|
|
msg_ += " of '" + file_ + "'";
|
|
|
|
}
|
2012-03-09 13:26:11 +01:00
|
|
|
return msg_.c_str();
|
2012-03-08 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 15:56:11 +01:00
|
|
|
void config_error::append_context(std::string const& ctx) const
|
|
|
|
{
|
|
|
|
what_ += " " + ctx;
|
|
|
|
}
|
2012-03-12 01:09:26 +01:00
|
|
|
|
|
|
|
void config_error::append_context(std::string const& ctx, xml_node const& node) const
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
2012-03-12 01:09:26 +01:00
|
|
|
append_context(ctx);
|
|
|
|
append_context(node);
|
2012-03-08 18:51:23 +01:00
|
|
|
}
|
2012-03-12 01:09:26 +01:00
|
|
|
|
|
|
|
void config_error::append_context(xml_node const& node) const
|
|
|
|
{
|
|
|
|
if (!line_number_) line_number_ = node.line();
|
|
|
|
if (node_name_.empty()) node_name_ = node.name();
|
|
|
|
if (file_.empty()) file_ = node.filename();
|
|
|
|
}
|
|
|
|
|
2012-03-08 18:51:23 +01:00
|
|
|
}
|