Changeset 808


Ignore:
Timestamp:
Oct 29, 2007 1:16:24 PM (14 years ago)
Author:
dkearney
Message:

allow the user to create a new empty rappture library object in c++ and python bindings. this is useful when you want to create new xml files.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/Rappture/PyRpLibrary.cc

    r795 r808  
    9595    int retVal = 1;
    9696
    97     if (!PyArg_ParseTuple(args, "O", &inObj)) {
     97    if (!PyArg_ParseTuple(args, "|O", &inObj)) {
    9898        PyErr_Format(PyExc_TypeError,
    99             "library() takes 1 argument, a file name or a Rappture Library Object");
     99            "library() takes at most 1 argument, a file name or a Rappture Library Object");
    100100        return -1;
    101101    }
    102102
    103     if (PyString_Check(inObj)) {
    104         filename = PyString_AsString(inObj);
    105         if (filename == NULL) {
    106             PyErr_Format(PyExc_ValueError,"a file name is required");
    107         }
    108         self->lib = new RpLibrary(std::string(filename));
    109     }
    110     else if (RpLibraryObject_IsValid(inObj)) {
    111         self->lib = new RpLibrary( *(RpLibraryObject_AsLibrary(inObj)) );
    112     }
    113     else if (RpLibraryObject_Check(inObj)) {
     103    if (inObj != NULL) {
     104        if (PyString_Check(inObj)) {
     105            filename = PyString_AsString(inObj);
     106            if (filename == NULL) {
     107                PyErr_Format(PyExc_ValueError,"a file name is required");
     108            }
     109            self->lib = new RpLibrary(std::string(filename));
     110        }
     111        else if (RpLibraryObject_IsValid(inObj)) {
     112            self->lib = new RpLibrary( *(RpLibraryObject_AsLibrary(inObj)) );
     113        }
     114        else if (RpLibraryObject_Check(inObj)) {
     115            self->lib = new RpLibrary();
     116        }
     117        else {
     118            PyErr_Format(PyExc_TypeError,"unrecognized object type");
     119            return -1;
     120        }
     121    }
     122    else {
    114123        self->lib = new RpLibrary();
    115     }
    116     else {
    117         PyErr_Format(PyExc_TypeError,"unrecognized object type");
    118         return -1;
    119124    }
    120125
  • trunk/src/core/RpLibrary.cc

    r788 r808  
    100100    else {
    101101        // create a new xml (from an empty file)
     102        freeTree = 1;
     103        tree = scew_tree_create();
     104        root = scew_tree_add_root(tree, "run");
    102105    }
    103106}
Note: See TracChangeset for help on using the changeset viewer.