mapnik/src/config_error.cpp

56 lines
1.4 KiB
C++
Raw Normal View History

2012-03-08 18:51:23 +01:00
#include <mapnik/config_error.hpp>
#include <mapnik/xml_tree.hpp>
namespace mapnik
{
2012-03-12 01:09:26 +01:00
config_error::config_error(std::string const& what)
: what_(what), line_number_(0), file_(), node_name_(), msg_()
{
}
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-03-12 01:09:26 +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
{
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
}
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
}