2012-03-08 18:51:23 +01:00
|
|
|
#include <mapnik/config_error.hpp>
|
|
|
|
#include <mapnik/xml_tree.hpp>
|
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
config_error::config_error(std::string const& what, xml_node const* node, std::string const& filename)
|
2012-03-09 13:26:11 +01:00
|
|
|
: what_( what ), line_number_(0), file_(filename), node_name_(), msg_()
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node_name_ = node->name();
|
|
|
|
line_number_ = node->line();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
config_error::config_error(unsigned line_number, std::string const& filename, std::string const& what)
|
2012-03-09 13:26:11 +01:00
|
|
|
: what_( what ), line_number_(line_number), file_(filename), node_name_(), msg_()
|
2012-03-08 18:51:23 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
char const* config_error::what() const throw()
|
|
|
|
{
|
|
|
|
std::stringstream s;
|
|
|
|
s << file_;
|
|
|
|
if (line_number_ > 0) s << " line " << line_number_;
|
|
|
|
if (!node_name_.empty()) s << " in node "<< node_name_;
|
|
|
|
if (line_number_ > 0 || !file_.empty()) s << ": ";
|
|
|
|
s << what_;
|
2012-03-09 13:26:11 +01:00
|
|
|
msg_ = s.str(); //Avoid returning pointer to dead object
|
|
|
|
return msg_.c_str();
|
2012-03-08 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void config_error::append_context(const std::string & ctx, xml_node const* node, std::string const& filename) const
|
|
|
|
{
|
|
|
|
what_ += " " + ctx;
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
if (!line_number_) line_number_ = node->line();
|
|
|
|
if (node_name_.empty()) node_name_ = node->name();
|
|
|
|
if (file_.empty()) file_ = filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|