Example #1
0
bool c4_JoinViewer::GetItem(int row_, int col_, c4_Bytes& buf_)
{
  c4_View v = _parent;

  int o = 0;
  int r = _offset.GetAt(row_);

  if (r < 0)
  {
    o = ~r;
    if (o == 0)
      return false; // if this is a null row in an outer join
    r -= o;
  }

  if (col_ >= v.NumProperties())
  {
    v = _argView;
    r = _o;

    col_ = v.FindProperty(_template.NthProperty(col_));
    if (col_ < 0)
      return false; // if second view doesn't have all properties
  }

  return v.GetItem(r, col_, buf_);
}
Example #2
0
bool PyViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  const c4_Property &prop = _template.NthProperty(col_);
  if (_byPos) {
    PWOSequence item(_data[row_]);
    PyRowRef::setFromPython(_tempRow, prop, item[col_]);
    return prop(_tempRow).GetData(buf_);
  }
  PyObject *item = _data[row_];
  if (PyInstance_Check(item)) {
    PyObject *attr = PyObject_GetAttrString(item, (char*)prop.Name());
    PyRowRef::setFromPython(_tempRow, prop, attr);
    return prop(_tempRow).GetData(buf_);
  }
  if (PyDict_Check(item)) {
    PyObject *attr = PyDict_GetItemString(item, (char*)prop.Name());
    PyRowRef::setFromPython(_tempRow, prop, attr);
    return prop(_tempRow).GetData(buf_);
  }
  if (_template.NumProperties() == 1) {
    PyRowRef::setFromPython(_tempRow, prop, _data[row_]);
    return prop(_tempRow).GetData(buf_);
  }
  Fail(PyExc_ValueError, "Object has no usable attributes");
  return false;
  // create a row with just this single property value
  // this detour handles dicts and objects, because makeRow does
  /*  c4_Row one;
  PyView v (prop); // nasty, stack-based temp to get at makeRow
  v.makeRow(one, _data[row_]);
  return prop (one).GetData(buf_); */
}
bool c4_RemapWithViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  const c4_Property &map = _argView.NthProperty(0);
  d4_assert(map.Type() == 'I');

  row_ = ((const c4_IntProp &)map)(_argView[row_]);

  return _parent.GetItem(row_, col_, buf_);
}
bool c4_PairViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  c4_View v = _parent;

  if (col_ >= v.NumProperties()) {
    v = _argView;
    col_ = v.FindProperty(_template.NthProperty(col_).GetId());
    d4_assert(col_ >= 0);
  }

  return v.GetItem(row_, col_, buf_);
}
bool c4_ConcatViewer::SetItem(int row_, int col_, const c4_Bytes &buf_) {
  c4_View v = _parent;

  if (row_ >= _parent.GetSize()) {
    v = _argView;
    row_ -= _parent.GetSize();
    col_ = v.FindProperty(_parent.NthProperty(col_).GetId());
    d4_assert(col_ >= 0);
  }

  v.SetItem(row_, col_, buf_);
  return true;
}
bool c4_ConcatViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  c4_View v = _parent;

  if (row_ >= _parent.GetSize()) {
    v = _argView;
    row_ -= _parent.GetSize();
    col_ = v.FindProperty(_parent.NthProperty(col_).GetId());

    if (col_ < 0)
      return false;
  }

  return v.GetItem(row_, col_, buf_);
}
bool c4_ProductViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  c4_View v = _parent;

  if (col_ < v.NumProperties()) {
    row_ /= _argView.GetSize();
  } else {
    v = _argView;
    row_ %= _argView.GetSize();
    col_ = v.FindProperty(_template.NthProperty(col_).GetId());

    d4_assert(col_ >= 0);
  }

  return v.GetItem(row_, col_, buf_);
}
Example #8
0
bool PyViewer::SetItem(int row_, int col_, const c4_Bytes &buf_) {
  const c4_Property &prop = _template.NthProperty(col_);
  c4_Row one;
  prop(one).SetData(buf_);

  PyRowRef r(one); // careful, stack-based temp
  PyObject *item = r.asPython(prop);

  if (_byPos) {
    PWOSequence item(_data[row_]);
    item[col_] = item;
  } else if (PyDict_Check((PyObject*)_data))
    PyDict_SetItemString(_data, (char*)prop.Name(), item);
  else
    PyObject_SetAttrString(_data, (char*)prop.Name(), item);

  Py_DECREF(item);
  return true;
}
bool c4_JoinPropViewer::GetItem(int row_, int col_, c4_Bytes &buf_) {
  c4_View v = _parent;
  int r = _base.GetAt(row_);

  if (col_ >= _subPos)
  if (col_ >= _subPos + _subWidth) {
    col_ -= _subWidth - 1;
  } else {
    v = _sub(_parent[r]);
    r = _offset.GetAt(row_);
    if (r < 0)
      return false;
    // if this is a null row in an outer join

    col_ = v.FindProperty(_template.NthProperty(col_).GetId());
    if (col_ < 0)
      return false;
    // if subview doesn't have all properties
  }

  return v.GetItem(r, col_, buf_);
}
Example #10
0
static void ViewDisplay(const c4_View& v_, int l_ =0)
{
  c4_String types;
  bool hasData = false, hasSubs = false;

    // display header info and collect all data types
  printf("%*s VIEW %5d rows =", l_, "", v_.GetSize());
  for (int n = 0; n < v_.NumProperties(); ++n)
  {
    c4_Property prop = v_.NthProperty(n);
    char t = prop.Type();

    printf(" %s:%c", (const char*) prop.Name(), t);
    
    types += t;
  
    if (t == 'V')
      hasSubs = true;
    else
      hasData = true;
  }
  printf("\n");

  for (int j = 0; j < v_.GetSize(); ++j)
  {
    if (hasData)  // data properties are all shown on the same line
    {
      printf("%*s %4d:", l_, "", j);
      c4_RowRef r = v_[j];
      c4_Bytes data;

      for (int k = 0; k < types.GetLength(); ++k)
      {
        c4_Property p = v_.NthProperty(k);

        switch (types[k])
        {
        case 'I':
          printf(" %ld", (long) ((c4_IntProp&) p) (r));
          break;

#if !q4_TINY
        case 'F':
          printf(" %g", (double) ((c4_FloatProp&) p) (r));
          break;

        case 'D':
          printf(" %.12g", (double) ((c4_DoubleProp&) p) (r));
          break;
#endif

        case 'S':
          printf(" '%s'", (const char*) ((c4_StringProp&) p) (r));
          break;

        case 'M': // backward compatibility
        case 'B':
          (p (r)).GetData(data);
          printf(" (%db)", data.Size());
          break;

        default:
          if (types[k] != 'V')
            printf(" (%c?)", types[k]);
        }
      }

      printf("\n");
    }

    if (hasSubs)  // subviews are then shown, each as a separate block
    {
      for (int k = 0; k < types.GetLength(); ++k)
      {
        if (types[k] == 'V')
        {
          c4_Property prop = v_.NthProperty(k);

          printf("%*s %4d: subview '%s'\n", l_, "", j,
              (const char*) prop.Name());

          c4_ViewProp& vp = (c4_ViewProp&) prop;
          
          ViewDisplay(vp (v_[j]), l_ + 2);
        }
      }
    }
  }
}