예제 #1
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_); */
}
예제 #2
0
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
}
예제 #3
0
파일: custom.cpp 프로젝트: SASfit/SASfit
bool c4_GroupByViewer::GetItem(int row_, int col_, c4_Bytes& buf_)
{
  if (col_ < _keys.NumProperties())
    return _sorted.GetItem(_map.GetAt(row_), col_, buf_);

  d4_assert(col_ == _keys.NumProperties());
  
  t4_i32 count;
  switch (_result.Type())
  {
    case 'I': count = _map.GetAt(row_ + 1) - _map.GetAt(row_);
          buf_ = c4_Bytes (&count, sizeof count, true);
          break;
    case 'V': _temp = _sorted.Slice(_map.GetAt(row_), _map.GetAt(row_ + 1))
                .ProjectWithout(_keys);
          buf_ = c4_Bytes (&_temp, sizeof _temp, true);
          break;
    default:  d4_assert(0);
  }

  return true;
}
예제 #4
0
파일: dump.cpp 프로젝트: Johannes13/kitgen
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);
        }
      }
    }
  }
}