static PyObject *Revision_is_transient(Revision *self) { PyObject *result = xorn_revision_is_transient(self->rev) ? Py_True : Py_False; Py_INCREF(result); return result; }
PyObject *Revision_copy_object( Revision *self, PyObject *args, PyObject *kwds) { PyObject *rev_arg = NULL, *ob_arg = NULL; static char *kwlist[] = { "rev", "ob", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!O!:Revision.copy_object", kwlist, &RevisionType, &rev_arg, &ObjectType, &ob_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); if (!xorn_object_exists_in_revision(((Revision *)rev_arg)->rev, ((Object *)ob_arg)->ob)) { PyErr_SetString(PyExc_KeyError, "Object does not exist in source revision"); return NULL; } xorn_object_t ob = xorn_copy_object( self->rev, ((Revision *)rev_arg)->rev, ((Object *)ob_arg)->ob); return ob ? build_object(ob) : PyErr_NoMemory(); }
static int Revision_settransient( Revision *self, PyObject *value, void *closure) { if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete transient attribute"); return -1; } if (value == Py_False) { xorn_finalize_revision(self->rev); return 0; } if (value == Py_True) { if (xorn_revision_is_transient(self->rev)) return 0; PyErr_SetString(PyExc_ValueError, "Cannot make revision transient again"); return -1; } PyErr_SetString(PyExc_TypeError, "transient attribute must be bool"); return -1; }
static PyObject *Revision_delete_object( Revision *self, PyObject *args, PyObject *kwds) { PyObject *ob_arg = NULL; static char *kwlist[] = { "ob", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!:Revision.delete_object", kwlist, &ObjectType, &ob_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); if (!xorn_object_exists_in_revision(self->rev, ((Object *)ob_arg)->ob)) { PyErr_SetString(PyExc_KeyError, "Object does not exist"); return NULL; } xorn_delete_object(self->rev, ((Object *)ob_arg)->ob); Py_INCREF(Py_None); return Py_None; }
static PyObject *Revision_add_object( Revision *self, PyObject *args, PyObject *kwds) { PyObject *data_arg = NULL; static char *kwlist[] = { "data", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O:Revision.add_object", kwlist, &data_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_obtype_t type = xorn_obtype_none; const void *data = NULL; if (prepare_data(data_arg, &type, &data) == -1) { char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Revision.add_object() argument 'data' (pos 1) " "must be of xorn.storage object type, not %.50s", data_arg->ob_type->tp_name); PyErr_SetString(PyExc_TypeError, buf); return NULL; } xorn_object_t ob = xorn_add_object(self->rev, type, data); if (ob == NULL) return PyErr_NoMemory(); return build_object(ob); }
int main(void) { xorn_revision_t rev0, rev1, rev2; xorn_object_t ob; memset(&line_data, 0, sizeof line_data); line_data.pos.x = 0; line_data.pos.y = 1; line_data.size.x = 3; line_data.size.y = 2; line_data.color = 3; line_data.line.width = 1; memset(&box_data, 0, sizeof box_data); box_data.pos.x = 1; box_data.pos.y = 1; box_data.size.x = 2; box_data.size.y = 2; box_data.color = 3; box_data.line.width = 1; rev0 = xorn_new_revision(NULL); assert(rev0 != NULL); assert(xorn_revision_is_transient(rev0) == true); xorn_finalize_revision(rev0); assert(xorn_revision_is_transient(rev0) == false); rev1 = xorn_new_revision(rev0); assert(rev1 != NULL); assert(xorn_revision_is_transient(rev1) == true); ob = xornsch_add_line(rev1, &line_data, NULL); assert(ob != NULL); xorn_finalize_revision(rev1); assert(xorn_revision_is_transient(rev1) == false); try_modify(rev1, ob, false); rev2 = xorn_new_revision(rev1); assert(rev2 != NULL); assert(xorn_revision_is_transient(rev2) == true); try_modify(rev2, ob, true); xorn_finalize_revision(rev2); assert(xorn_revision_is_transient(rev2) == false); xorn_free_revision(rev2); xorn_free_revision(rev1); xorn_free_revision(rev0); return 0; }
static PyObject *Revision_delete_objects( Revision *self, PyObject *args, PyObject *kwds) { PyObject *sel_arg = NULL; static char *kwlist[] = { "sel", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!:Revision.delete_objects", kwlist, &SelectionType, &sel_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_delete_selected_objects(self->rev, ((Selection *)sel_arg)->sel); Py_INCREF(Py_None); return Py_None; }
static PyObject *Revision_copy_objects( Revision *self, PyObject *args, PyObject *kwds) { PyObject *rev_arg = NULL, *sel_arg = NULL; static char *kwlist[] = { "rev", "sel", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!O!:Revision.copy_objects", kwlist, &RevisionType, &rev_arg, &SelectionType, &sel_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_selection_t sel = xorn_copy_objects( self->rev, ((Revision *)rev_arg)->rev, ((Selection *)sel_arg)->sel); return sel ? build_selection(sel) : PyErr_NoMemory(); }
static PyObject *Revision_relocate_object( Revision *self, PyObject *args, PyObject *kwds) { PyObject *ob_arg = NULL, *attach_to_arg = NULL, *insert_before_arg = NULL; static char *kwlist[] = { "ob", "attach_to", "insert_before", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!OO:Revision.relocate_object", kwlist, &ObjectType, &ob_arg, &attach_to_arg, &insert_before_arg)) return NULL; if (attach_to_arg != Py_None && !PyObject_TypeCheck(attach_to_arg, &ObjectType)) { char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Revision.relocate_object() argument 2 " "must be %.50s or None, not %.50s", ObjectType.tp_name, attach_to_arg->ob_type->tp_name); PyErr_SetString(PyExc_TypeError, buf); return NULL; } if (insert_before_arg != Py_None && !PyObject_TypeCheck(insert_before_arg, &ObjectType)) { char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Revision.relocate_object() argument 3 " "must be %.50s or None, not %.50s", ObjectType.tp_name, insert_before_arg->ob_type->tp_name); PyErr_SetString(PyExc_TypeError, buf); return NULL; } if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_obtype_t ob_type = xorn_get_object_type( self->rev, ((Object *)ob_arg)->ob); if (ob_type == xorn_obtype_none) { PyErr_SetString(PyExc_KeyError, "Object does not exist"); return NULL; } if (attach_to_arg != Py_None) { if (ob_type != xornsch_obtype_text) { PyErr_SetString(PyExc_ValueError, "Only text objects can be attached"); return NULL; } switch (xorn_get_object_type(self->rev, ((Object *)attach_to_arg)->ob)) { case xorn_obtype_none: PyErr_SetString(PyExc_KeyError, "Parent object does not exist"); return NULL; case xornsch_obtype_net: case xornsch_obtype_component: break; default: PyErr_SetString(PyExc_ValueError, "Can only attach to net and " "component objects"); return NULL; } } if (insert_before_arg != Py_None) { xorn_object_t attached_to; if (xorn_get_object_location( self->rev, ((Object *)insert_before_arg)->ob, &attached_to, NULL) == -1) { PyErr_SetString(PyExc_KeyError, "Reference object does not exist"); return NULL; } if (attached_to != (attach_to_arg == Py_None ? NULL : ((Object *)attach_to_arg)->ob)) { PyErr_SetString(PyExc_ValueError, "Invalid reference object"); return NULL; } } if (xorn_relocate_object(self->rev, ((Object *)ob_arg)->ob, attach_to_arg == Py_None ? NULL : ((Object *)attach_to_arg)->ob, insert_before_arg == Py_None ? NULL : ((Object *)insert_before_arg)->ob) == -1) return PyErr_NoMemory(); Py_INCREF(Py_None); return Py_None; }
static PyObject *Revision_set_object_data( Revision *self, PyObject *args, PyObject *kwds) { PyObject *ob_arg = NULL, *data_arg = NULL; static char *kwlist[] = { "ob", "data", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!O:Revision.set_object_data", kwlist, &ObjectType, &ob_arg, &data_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_obtype_t type = xorn_obtype_none; const void *data = NULL; if (prepare_data(data_arg, &type, &data) == -1) { char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Revision.set_object_data() argument 'data' (pos 2) " "must be of xorn.storage object type, not %.50s", data_arg->ob_type->tp_name); PyErr_SetString(PyExc_TypeError, buf); return NULL; } if (type != xornsch_obtype_text) { xorn_object_t attached_to; if (xorn_get_object_location(self->rev, ((Object *)ob_arg)->ob, &attached_to, NULL) != -1 && attached_to != NULL) { PyErr_SetString(PyExc_ValueError, "Cannot set attached object to " "something other than text"); return NULL; } } if (type != xornsch_obtype_net && type != xornsch_obtype_component) { size_t count; if (xorn_get_objects_attached_to( self->rev, ((Object *)ob_arg)->ob, NULL, &count) != -1 && count != 0) { PyErr_SetString( PyExc_ValueError, "Cannot set object with attached objects to " "something other than net or component"); return NULL; } } if (xorn_set_object_data(self->rev, ((Object *)ob_arg)->ob, type, data) == -1) return PyErr_NoMemory(); Py_INCREF(Py_None); return Py_None; }