2011-08-24 15:15:39 +05:30
|
|
|
#include "error_set.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace persistent_data;
|
2011-08-24 18:57:45 +05:30
|
|
|
using namespace std;
|
2011-08-24 15:15:39 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
error_set::error_set(string const &err)
|
2011-08-24 15:15:39 +05:30
|
|
|
: err_(err) {
|
|
|
|
}
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
string const &
|
2011-08-24 15:15:39 +05:30
|
|
|
error_set::get_description() const
|
|
|
|
{
|
|
|
|
return err_;
|
|
|
|
}
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
list<error_set::ptr> const &
|
2011-08-24 15:15:39 +05:30
|
|
|
error_set::get_children() const
|
|
|
|
{
|
|
|
|
return children_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
error_set::add_child(error_set::ptr err)
|
|
|
|
{
|
|
|
|
children_.push_back(err);
|
|
|
|
}
|
|
|
|
|
2011-08-25 19:35:23 +05:30
|
|
|
void
|
|
|
|
error_set::add_child(boost::optional<error_set::ptr> maybe_errs)
|
|
|
|
{
|
|
|
|
if (maybe_errs)
|
|
|
|
children_.push_back(*maybe_errs);
|
|
|
|
}
|
|
|
|
|
2011-08-24 15:15:39 +05:30
|
|
|
void
|
2011-08-24 18:57:45 +05:30
|
|
|
error_set::add_child(string const &err)
|
2011-08-24 15:15:39 +05:30
|
|
|
{
|
|
|
|
error_set::ptr e(new error_set(err));
|
|
|
|
add_child(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
namespace {
|
2011-08-24 18:57:45 +05:30
|
|
|
void indent_by(ostream &out, unsigned indent) {
|
2011-08-24 15:15:39 +05:30
|
|
|
for (unsigned i = 0; i < indent; i++)
|
|
|
|
out << ' ';
|
|
|
|
}
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
void print_errs(ostream &out, error_set::ptr e, unsigned depth, unsigned indent) {
|
2011-08-24 15:15:39 +05:30
|
|
|
if (depth == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
indent_by(out, indent);
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
out << e->get_description() << endl;
|
2011-08-24 15:15:39 +05:30
|
|
|
if (depth > 1) {
|
2011-08-24 18:57:45 +05:30
|
|
|
list<error_set::ptr> const &children = e->get_children();
|
|
|
|
for (list<error_set::ptr>::const_iterator it = children.begin(); it != children.end(); ++it)
|
2011-08-24 15:15:39 +05:30
|
|
|
print_errs(out, *it, depth - 1, indent + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error_selector::error_selector(error_set::ptr errs, unsigned depth)
|
|
|
|
: errs_(errs),
|
|
|
|
depth_(depth)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-24 18:57:45 +05:30
|
|
|
error_selector::print(ostream &out) const
|
2011-08-24 15:15:39 +05:30
|
|
|
{
|
|
|
|
print_errs(out, errs_, depth_, 0);
|
|
|
|
}
|
|
|
|
|
2011-08-24 18:57:45 +05:30
|
|
|
ostream &
|
|
|
|
persistent_data::operator << (ostream &out, error_selector const &errs)
|
2011-08-24 15:15:39 +05:30
|
|
|
{
|
|
|
|
errs.print(out);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|