Example #1
0
/** 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;
}
Example #2
0
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();
}
Example #3
0
/** 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;
}
Example #4
0
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();
}
Example #5
0
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");
}
Example #6
0
File: store.cpp Project: aosm/tcl
/// Get or set a named view in this storage object
c4_ViewRef c4_Storage::View(const char *name_) {
  /*
  The easy solution would seem to be:

  c4_ViewProp prop (name_);
  return prop (Contents());

  But this does not work, because the return value would point to
  an object allocated on the stack.

  Instead, make sure the view *has* such a property, and use the
  one inside the c4_Handler for it (since this will stay around).
   */

  //  int n = _root->PropIndex(c4_ViewProp (name_));

  c4_ViewProp prop(name_);
  int n = AddProperty(prop);
  d4_assert(n >= 0);

  // the following is an expression of the form "property (rowref)"
  return NthProperty(n)(GetAt(0));
}
Example #7
0
/// Set a single data item in a generic way
void c4_View::SetItem(int row_, int col_, const c4_Bytes& buf_) const
{
  const c4_Property& prop = NthProperty(col_);
  prop (GetAt(row_)).SetData(buf_);
}
Example #8
0
/** Get a single data item in a generic way
 *
 * This can be used to access view data in a generalized way.
 * Useful for c4_CustomViewers which are based on other views.
 * @return true if the item is non-empty
 */
bool c4_View::GetItem(int row_, int col_, c4_Bytes& buf_) const
{
  const c4_Property& prop = NthProperty(col_);
  return prop (GetAt(row_)).GetData(buf_);
}