Exemplo n.º 1
0
void output_element(std::ostream & out, const Element & item, int depth)
{
    switch (item.getType()) {
        case Element::TYPE_INT:
            out << item.Int();
            break;
        case Element::TYPE_FLOAT:
            out << item.Float();
            break;
        case Element::TYPE_STRING:
            out << "\"" << item.String() << "\"";
            break;
        case Element::TYPE_LIST:
            {
                out << "[ ";
                ListType::const_iterator I = item.List().begin();
                ListType::const_iterator Iend = item.List().end();
                for(; I != Iend; ++I) {
                    output_element(out, *I, depth + 1);
                    out << " ";
                }
                out << "]";
            }
            break;
        case Element::TYPE_MAP:
            {
                out << "{" << std::endl;
                MapType::const_iterator I = item.Map().begin();
                MapType::const_iterator Iend = item.Map().end();
                for(; I != Iend; ++I) {
                    out << std::string((depth + 1) * 4, ' ') << I->first << ": ";
                    output_element(out, I->second, depth + 1);
                    out << std::endl;
                }
                out << std::string(depth * 4, ' ') << "}";
                out << std::endl;
            }
            break;
        default:
            out << "(\?\?\?)";
            break;
    }
}