예제 #1
0
/** Move attached rows to somewhere else in same storage
 *
 * There is a lot of trickery going on here.  The whole point of this
 * code is that moving rows between (compatible!) subviews should not
 * use copying when potentially large memo's and subviews are involved.
 * In that case, the best solution is really to move pointers, not data.
 */
void c4_View::RelocateRows(int from_, int count_, c4_View& dest_, int pos_)
{
  if (count_ < 0)
    count_ = GetSize() - from_;
  if (pos_ < 0)
    pos_ = dest_.GetSize();

  d4_assert(0 <= from_ && from_ <= GetSize());
  d4_assert(0 <= count_ && from_ + count_ <= GetSize());
  d4_assert(0 <= pos_ && pos_ <= dest_.GetSize());

  if (count_ > 0) {
      // the destination must not be inside the source rows
    d4_assert(&dest_ != this || from_ > pos_ || pos_ >= from_ + count_);

      // this test is slow, so do it only as a debug check
    d4_assert(IsCompatibleWith(dest_));

      // make space, swap rows, drop originals
    c4_Row empty;
    dest_.InsertAt(pos_, empty, count_);

      // careful if insert moves origin
    if (&dest_ == this && pos_ <= from_)
      from_ += count_;

    for (int i = 0; i < count_; ++i)
      ((c4_HandlerSeq*) _seq)->ExchangeEntries(from_ + i,
				*(c4_HandlerSeq*) dest_._seq, pos_ + i);

    RemoveAt(from_, count_);
  }
}
예제 #2
0
void CResizer::Verify() {
  int i;

  A(_refSize == _unattached.GetSize());
  A(_refSize == _attached.GetSize());

  for (i = 0; i < _refSize; ++i) {
    A(_refData[i] == _prop(_unattached[i]));
    A(_refData[i] == _prop(_attached[i]));
  }
}
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_);
}
예제 #6
0
파일: persist.cpp 프로젝트: aosm/tcl
void c4_Differ::ApplyDiff(int id_, c4_Column &col_)const {
  d4_assert(0 <= id_ && id_ < _diffs.GetSize());

  c4_View diff = pDiff(_diffs[id_]);
  t4_i32 offset = 0;

  for (int n = 0; n < diff.GetSize(); ++n) {
    c4_RowRef row(diff[n]);
    offset += pKeep(row);

    c4_Bytes data;
    pBytes(row).GetData(data);

    // the following code is a lot like c4_MemoRef::Modify
    const t4_i32 change = pResize(row);
    if (change < 0)
      col_.Shrink(offset,  - change);
    else if (change > 0)
      col_.Grow(offset, change);

    col_.StoreBytes(offset, data);
    offset += data.Size();
  }

  if (offset > col_.ColSize())
    col_.Shrink(offset, offset - col_.ColSize());
}
예제 #7
0
int MkView::asIndex(c4_View &view, Tcl_Obj *obj_, bool mayExceed_) {
  int size = view.GetSize();
  int index;

  if (Tcl_GetIntFromObj(interp, obj_, &index) != TCL_OK) {
    const char *step = Tcl_GetStringFromObj(obj_, 0);
    if (step != 0 && strcmp(step, "end") == 0) {
      index = !mayExceed_ ? size - 1: size;
      Tcl_ResetResult(interp); // clear error
      _error = TCL_OK;
    } else {
      index =  - 1;
    }
  }

  if (mayExceed_) {
    if (index > size)
      Fail("view index is too large");
    else if (index < 0)
      Fail("view index is negative");
  } else if (index < 0 || index >= size)
    Fail("view index is out of range");

  return index;
}
int c4_SliceViewer::GetSize() {
  int n = _limit >= 0 ? _limit : _parent.GetSize();
  if (n < _first)
    n = _first;

  int k = _step < 0 ?  - _step: _step;
  return (n - _first + k - 1) / k;
}
예제 #9
0
파일: persist.cpp 프로젝트: aosm/tcl
void c4_Differ::GetRoot(c4_Bytes &buffer_) {
  int last = _diffs.GetSize() - 1;
  if (last >= 0) {
    c4_Bytes temp;
    c4_View diff = pDiff(_diffs[last]);
    if (diff.GetSize() > 0)
      pBytes(diff[0]).GetData(buffer_);
  }
}
예제 #10
0
파일: persist.cpp 프로젝트: aosm/tcl
void c4_Differ::AddEntry(t4_i32 off_, t4_i32 len_, const c4_Bytes &data_) {
  int n = _temp.GetSize();
  _temp.SetSize(n + 1);
  c4_RowRef r = _temp[n];

  pKeep(r) = (t4_i32)off_;
  pResize(r) = (t4_i32)len_;
  pBytes(r).SetData(data_);
}
예제 #11
0
/// Insert copies of all rows of the specified view
void c4_View::InsertAt(int index_, const c4_View &view_) {
  int n = view_.GetSize();
  if (n > 0) {
    c4_Row empty;

    InsertAt(index_, empty, n);

    for (int i = 0; i < n; ++i)
      SetAt(index_ + i, view_[i]);
  }
}
예제 #12
0
/// Compare two views lexicographically (rows 0..N-1).
int c4_View::Compare(const c4_View &view_)const {
  if (_seq == view_._seq)
    return 0;

  int na = GetSize();
  int nb = view_.GetSize();
  int i;

  for (i = 0; i < na && i < nb; ++i)
    if (GetAt(i) != view_.GetAt(i))
      return GetAt(i) < view_.GetAt(i) ?  - 1:  + 1;

  return na == nb ? 0 : i < na ?  + 1:  - 1;
}
예제 #13
0
파일: persist.cpp 프로젝트: aosm/tcl
void c4_Differ::CreateDiff(int id_, c4_Column &col_) {
  _temp.SetSize(0);
#if 0
  t4_i32 offset = 0;
  t4_i32 savedOff = 0;
  t4_i32 savedLen = 0;

  c4_Strategy *strat = col_.Persist() != 0 ? &col_.Strategy(): 0;

  c4_ColIter iter(col_, 0, col_.ColSize());
  while (iter.Next()) {
    const t4_byte *p = iter.BufLoad();
    if (strat != 0 && strat->_mapStart != 0 && p >= strat->_mapStart && p -
      strat->_mapStart < strat->_dataSize) {
      t4_i32 nextOff = p - strat->_mapStart;
      if (savedLen == 0)
        savedOff = nextOff;
      if (nextOff == savedOff + savedLen) {
        savedLen += iter.BufLen();
        continue;
      }

      if (savedLen > 0)
        AddEntry(savedOff, savedLen, c4_Bytes());

      savedOff = nextOff;
      savedLen = iter.BufLen();
    } else {
      AddEntry(savedOff, savedLen, c4_Bytes(p, iter.BufLen()));
      savedLen = 0;
    }

    offset += iter.BufLen();
  }

  c4_View diff = pDiff(_diffs[id_]);
  if (_temp.GetSize() != diff.GetSize() || _temp != diff)
#else 
    c4_Bytes t1;
  const t4_byte *p = col_.FetchBytes(0, col_.ColSize(), t1, false);
  AddEntry(0, 0, c4_Bytes(p, col_.ColSize()));
#endif 
  pDiff(_diffs[id_]) = _temp;

  pOrig(_diffs[id_]) = col_.Position();
}
예제 #14
0
파일: persist.cpp 프로젝트: aosm/tcl
int c4_Differ::NewDiffID() {
  int n = _diffs.GetSize();
  _diffs.SetSize(n + 1);
  return n;
}
예제 #15
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);
        }
      }
    }
  }
}
예제 #16
0
static int ViewSize(c4_View v) {
  return v.GetSize();
}
예제 #17
0
  return v.GetSize();
}

void TestBasics2() {
  B(b20, Search sorted view, 0) {
    c4_IntProp p1("p1");
    c4_StringProp p2("p2");
    c4_View v1;
    v1.Add(p1[111] + p2["one"]);
    v1.Add(p1[222] + p2["two"]);
    v1.Add(p1[333] + p2["three"]);
    v1.Add(p1[345] + p2["four"]);
    v1.Add(p1[234] + p2["five"]);
    v1.Add(p1[123] + p2["six"]);
    c4_View v2 = v1.Sort();
    A(v2.GetSize() == 6);
    A(p1(v2[0]) == 111);
    A(p1(v2[1]) == 123);
    A(p1(v2[2]) == 222);
    A(p1(v2[3]) == 234);
    A(p1(v2[4]) == 333);
    A(p1(v2[5]) == 345);
    A(v2.Search(p1[123]) == 1);
    A(v2.Search(p1[100]) == 0);
    A(v2.Search(p1[200]) == 2);
    A(v2.Search(p1[400]) == 6);
    c4_View v3 = v1.SortOn(p2);
    A(v3.GetSize() == 6);
    A(p1(v3[0]) == 234);
    A(p1(v3[1]) == 345);
    A(p1(v3[2]) == 111);
예제 #18
0
파일: custom.cpp 프로젝트: SASfit/SASfit
int c4_ProductViewer::GetSize()
{
  return _parent.GetSize() * _argView.GetSize();
}
예제 #19
0
파일: tnotify.cpp 프로젝트: aosm/tcl
// $Id: tnotify.cpp 1230 2007-03-09 15:58:53Z jcw $
// This is part of Metakit, the homepage is http://www.equi4.com/metakit.html

#include "regress.h"

void TestNotify() {
  B(n01, Add to selection, 0) {
    c4_IntProp p1("p1");
    c4_View v1;
    v1.Add(p1[111]);
    v1.Add(p1[222]);
    v1.Add(p1[333]);
    v1.Add(p1[345]);
    v1.Add(p1[234]);
    v1.Add(p1[123]);
    A(v1.GetSize() == 6);
    c4_View v2 = v1.SelectRange(p1[200], p1[333]);
    A(v2.GetSize() == 3);
    A(p1(v2[0]) == 222);
    A(p1(v2[1]) == 333);
    A(p1(v2[2]) == 234);
    v1.Add(p1[300]);
    A(v1.GetSize() == 7);
    A(v2.GetSize() == 4);
    A(p1(v2[0]) == 222);
    A(p1(v2[1]) == 333);
    A(p1(v2[2]) == 234);
    A(p1(v2[3]) == 300);
    v1.Add(p1[199]);
    A(v1.GetSize() == 8);
    A(v2.GetSize() == 4);
예제 #20
0
파일: custom.cpp 프로젝트: SASfit/SASfit
int c4_RemapWithViewer::GetSize()
{
  return _argView.GetSize();
}
예제 #21
0
파일: custom.cpp 프로젝트: SASfit/SASfit
int c4_PairViewer::GetSize()
{
  return _parent.GetSize();
}
예제 #22
0
파일: custom.cpp 프로젝트: SASfit/SASfit
int c4_ConcatViewer::GetSize()
{
  return _parent.GetSize() + _argView.GetSize();
}
예제 #23
0
파일: persist.cpp 프로젝트: aosm/tcl
t4_i32 c4_Differ::BaseOfDiff(int id_) {
  d4_assert(0 <= id_ && id_ < _diffs.GetSize());

  return pOrig(_diffs[id_]);
}
예제 #24
0
파일: custom.cpp 프로젝트: SASfit/SASfit
int c4_RenameViewer::GetSize()
{
  return _parent.GetSize();
}