bool c4_View::IsCompatibleWith(const c4_View& dest_) const { // can't determine table without handlers (and can't be a table) if (NumProperties() == 0 || dest_.NumProperties() == 0) return false; c4_Sequence* s1 = _seq; c4_Sequence* s2 = dest_._seq; c4_HandlerSeq* h1 = (c4_HandlerSeq*) s1->HandlerContext(0); c4_HandlerSeq* h2 = (c4_HandlerSeq*) s2->HandlerContext(0); // both must be real handler views, not derived ones if (h1 != s1 || h2 != s2) return false; // both must not contain any temporary handlers if (s1->NumHandlers() != h1->NumFields() || s2->NumHandlers() != h2->NumFields()) return false; // both must be in the same storage if (h1->Persist() == 0 || h1->Persist() != h2->Persist()) return false; // both must have the same structure (is this expensive?) c4_String d1 = h1->Definition().Description(true); c4_String d2 = h1->Definition().Description(true); return d1 == d2; // ignores all names }
/** Constructs a new view with the same structure but no data * * Structural information can only be maintain for the top level, * subviews will be included but without any properties themselves. */ c4_View c4_View::Clone()const { c4_View view; for (int i = 0; i < NumProperties(); ++i) view._seq->PropIndex(NthProperty(i)); return view; }
PyObject *PyView::properties() { int n = NumProperties(); PWOMapping rslt; for (int i = 0; i < n; i++) { PyProperty *item = new PyProperty(NthProperty(i)); rslt.setItem(item->Name(), item); Py_DECREF(item); } return rslt.disOwn(); }
void PyView::makeRow(c4_Row& tmp, PyObject* o, bool useDefaults) { for (int i=0; i < NumProperties(); i++) { const c4_Property& prop = NthProperty(i); PyObject* attr = 0; if (o) { if (PyDict_Check(o)) { attr = PyDict_GetItemString(o, (char *)prop.Name()); Py_XINCREF(attr); } else if (PySequence_Check(o)) { attr = PySequence_GetItem(o, i); } else { attr = PyObject_GetAttrString(o, (char *)prop.Name()); if (attr == 0 && i == 0 && NumProperties() == 1) { PyErr_Clear(); attr = o; Py_XINCREF(attr); } } } if (attr) { try { PyRowRef::setFromPython(tmp, prop, attr); } catch (...) { Py_DECREF(attr); throw; } Py_DECREF(attr); } else { PyErr_Clear(); if (useDefaults) PyRowRef::setDefault(tmp, prop); } } if (!useDefaults) if (tmp.Container().NumProperties() == 0) Fail(PyExc_ValueError, "Object has no usable attributes"); }
/** Find the index of a property, given its name * @return 0-based column index * @retval -1 property not present in this view */ int c4_View::FindPropIndexByName(const char *name_ ///< property name (case insensitive) )const { // use a slow linear scan to find the untyped property by name for (int i = 0; i < NumProperties(); ++i) { c4_String s = NthProperty(i).Name(); if (s.CompareNoCase(name_) == 0) return i; } return - 1; }
PyObject* PyView::structure() { int n = NumProperties(); // PyObject* list=PyList_New(n); // for (int i = 0; i < n; i++) // PyList_SET_ITEM(list, i, new PyProperty(NthProperty(i))); // return list; PWOList rslt(n); for (int i = 0; i < n; i++) { PyProperty *prop = new PyProperty(NthProperty(i)); rslt.setItem(i, prop); } return rslt.disOwn(); }