File:  [CENS] / python / pyGiNaC / test4 / test_archive.cpp
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Fri Aug 17 08:50:34 2001 UTC (16 years, 3 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

#include <ginac/ginac.h>
using namespace GiNaC;
using namespace std;

static void my_print2(const archive_node & n)
{
    string class_name;
    n.find_string("class", class_name);
    cout << class_name << "(";

    archive_node::propinfovector p;
    n.get_properties(p);

    unsigned num = p.size();
    for (unsigned i=0; i<num; i++) {
        const string &name = p[i].name;
        if (name == "class")
            continue;
        cout << name << "=";

        unsigned count = p[i].count;
        if (count > 1)
            cout << "{";

        for (unsigned j=0; j<count; j++) {
            switch (p[i].type) {
                case archive_node::PTYPE_BOOL: {
                    bool x;
                    n.find_bool(name, x);
                    cout << (x ? "true" : "false");
                    break;
                }
                case archive_node::PTYPE_UNSIGNED: {
                    unsigned x;
                    n.find_unsigned(name, x);
                    cout << x;
                    break;
                }
                case archive_node::PTYPE_STRING: {
                    string x;
                    n.find_string(name, x);
		    cout << "len=" << x.length() << std::endl;
                    cout << '\"' << x << '\"';

		    n.printraw(cout);
                    break;
                }
                case archive_node::PTYPE_NODE: {
                    const archive_node &x = n.find_ex_node(name, j);
                    my_print2(x);
                    break;
                }
            }

            if (j != count-1)
                cout << ",";
        }

        if (count > 1)
            cout << "}";

        if (i != num-1)
            cout << ",";
    }

    cout << ")";
}

int main(void)
{
    ex e = pow(200, 500);
    archive ar(e, "e");
    const archive_node &n = ar.get_top_node(0);
    n.printraw(cout);
    cout << endl;
    string x;
    n.find_string("number", x);
    cout << x << endl;
    cout << "length=" << x.length() << endl;
    return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>