示例#1
0
bool wb_session::castAttribute(pwr_sAttrRef* arp, pwr_tCid cid)
{
  wb_attribute a = attribute(arp);
  if (!a)
    return a.sts();

  if (!(a.flags() & PWR_MASK_CASTATTR)) {
    m_sts = 0;
    return false;
  }

  wb_cdef c = cdef(cid);
  // if ( c.size( pwr_eBix_rt) != a.size()) {
  //  m_sts = 0;
  //  return false;
  //}

  // pwr_tTid tid = a.tid();

  pwr_tCastId castid;
  if (cid == a.originalTid())
    castid = pwr_cNClassId;
  else
    castid = cid;

  pwr_sAttrRef cast_aref = cdh_ArefToCastAref(arp);
  wb_attribute cast_a = attribute(&cast_aref);
  if (!cast_a)
    return cast_a.sts();

  try {
    writeAttribute(cast_a, &castid);
  } catch (wb_error& e) {
    m_sts = e.sts();
    return false;
  }

  void* body = calloc(1, c.size(pwr_eBix_rt));
  c.attrTemplateBody(&m_sts, pwr_eBix_rt, body, a);

  try {
    writeAttribute(a, body);
  } catch (wb_error& e) {
    m_sts = e.sts();
    return false;
  }

  return true;
}
示例#2
0
void
wb_dbs::cidInsert(pwr_tStatus *sts, pwr_tCid cid, pwr_sAttrRef *arp, sCentry **cep)
{
  *cep = (sCentry*)tree_Insert(sts, m_class_th, &cid);
  if ( !arp)
    return;

  if (*sts == TREE__INSERTED) {
    // Insert depending classes
    pwr_tCid *lst;
    pwr_sAttrRef *arlst;
    sCentry *entry;
    int cnt;
    pwr_tStatus lsts;
    pwr_sAttrRef aref;
    pwr_sAttrRef cast_aref;
    pwr_tCid cast_cid;

    m_v->merep()->classDependency( &lsts, cid, &lst, &arlst, &cnt);
    for ( int i = 0; i < cnt; i++) {
      aref = cdh_ArefAdd( arp, &arlst[i]);
      cidInsert(&lsts, lst[i], &aref, &entry);

      if ( aref.Flags.b.CastAttr) {
	cast_aref = cdh_ArefToCastAref( &aref);

	wb_volume v(m_v);
	wb_attribute a = v.attribute( &cast_aref);
	if ( a) {
	  a.value( &cast_cid);
	  if ( cast_cid != pwr_cNCid) {
	    wb_cdef cd = v.cdef( cast_cid);
	    if ( cd)
	      cidInsert(&lsts, cast_cid, 0, &entry);
	    else
	      printf("** Invalid cast class %s\n", cdh_ObjidToString( 0, aref.Objid, 1));
	  }
	}
      }
    }
    free(lst);
    free(arlst);
  }
  else if ( !(cdh_CidToVid(cid) == 1 && cdh_CidToVid(cid) == 2)) {
    // Check class of casted attribute for every instance
    pwr_tCid *lst;
    pwr_sAttrRef *arlst;
    sCentry *entry;
    int cnt;
    pwr_tStatus lsts;
    pwr_sAttrRef aref;
    pwr_sAttrRef cast_aref;
    pwr_tCid cast_cid;

    m_v->merep()->classDependency( &lsts, cid, &lst, &arlst, &cnt);
    for ( int i = 0; i < cnt; i++) {
      aref = cdh_ArefAdd( arp, &arlst[i]);

      if ( aref.Flags.b.CastAttr) {
	cast_aref = cdh_ArefToCastAref( &aref);

	wb_volume v(m_v);
	wb_attribute a = v.attribute( &cast_aref);
	if ( a) {
	  a.value( &cast_cid);
	  if ( cast_cid != pwr_cNCid) {
	    wb_cdef cd = v.cdef( cast_cid);
	    if ( cd)
	      cidInsert(&lsts, cast_cid, 0, &entry);
	    else
	      printf("** Invalid cast class %s\n", cdh_ObjidToString( 0, aref.Objid, 1));
	  }
	}
      }
    }
    free(lst);
    free(arlst);
  }
}