2011-12-06 19:23:05 +05:30
|
|
|
// Copyright (C) 20011 Red Hat, Inc. All rights reserved.
|
|
|
|
//
|
2011-12-06 19:13:56 +05:30
|
|
|
// This file is part of the thin-provisioning-tools source.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is free software: you can redistribute it
|
|
|
|
// and/or modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is distributed in the hope that it will be
|
|
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with thin-provisioning-tools. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|