wb_attribute wb_attribute::before() const { pwr_tStatus sts; check(); if (m_adrep == 0) return wb_attribute(); wb_adrep* adrep = m_adrep->prev(&sts); if (EVEN(sts)) return wb_attribute(); wb_attribute a(LDH__SUCCESS, m_orep, adrep); a.m_bix = m_bix; #if 0 // Fix for sub classes if (m_flags & PWR_MASK_SUBCLASS) { a.m_flags |= PWR_MASK_SUBCLASS; a.m_bix = m_bix; if ((m_flags & PWR_MASK_ARRAY) && m_idx != -1) // array element a.m_offset = (m_offset - m_size * m_idx) - adrep->size(); else a.m_offset = m_offset - adrep->size(); } #endif return a; }
wb_attribute wb_attribute::child(const char* name, int idx) const { if (!cdh_tidIsCid( m_tid)) return wb_attribute(); return wb_attribute(*this, idx, name); }
wb_attribute wb_attribute::first(int idx) const { if (!cdh_tidIsCid( m_tid)) return wb_attribute(); return wb_attribute(*this, idx, NULL); }
wb_attribute wb_volume::attribute(wb_object o, wb_attrname aname) { pwr_tStatus sts; if (!o) return wb_attribute(); wb_cdef cd = cdef(o); if (!cd) return wb_attribute(); wb_adrep *adrep = ((wb_cdrep *)cd)->adrep(&sts, aname.attributesAllTrue()); if (ODD(sts)) return wb_attribute(sts, (wb_orep *)o, adrep); return wb_attribute(); }
wb_attribute wb_volume::attribute(wb_name aname) { pwr_tStatus sts; if (!aname) return wb_attribute(); wb_object o = object(aname.name()); if (!o) return wb_attribute(); if (!aname.hasAttribute()) return wb_attribute(LDH__SUCCESS, (wb_orep *)o); wb_cdef cd = cdef(o); if (!cd) return wb_attribute(); wb_adrep *adrep = ((wb_cdrep *)cd)->adrep(&sts, aname.attributesAllTrue()); if (ODD(sts)) { bool shadowed = false; if (aname.hasSuper()) { // Check if shadowed wb_attrname an(aname.attributesAllTrue()); wb_adrep *ad = ((wb_cdrep *)cd)->adrep(&sts, an.name(cdh_mName_attribute)); if (ODD(sts) && ad->offset() != adrep->offset()) { shadowed = true; delete ad; } } wb_attribute a; if (aname.hasAttrIndex(aname.attributes() - 1)) a = wb_attribute(sts, (wb_orep *)o, adrep, aname.attrIndex(aname.attributes() - 1)); else a = wb_attribute(sts, (wb_orep *)o, adrep); a.setShadowed(shadowed); return a; } #if 0 // This only work on one level attributes... TODO wb_adrep *adrep = ((wb_cdrep *)cd)->adrep(&sts, aname.attributesAllTrue()); if (ODD(sts)) { if (aname.hasAttrIndex()) return wb_attribute(sts, (wb_orep *)o, adrep, aname.attrIndex()); else return wb_attribute(sts, (wb_orep *)o, adrep); } #endif return wb_attribute(); }
ldh_sRefInfo *wb_volume::refinfo(wb_object o, ldh_sRefInfo *rp) { int rows; memset(rp, 0, sizeof(*rp)); wb_cdef c = cdef(o); wb_bdef b = c.bdef(pwr_eBix_rt); if (!b) return rp; wb_attribute body = wb_attribute(b.sts(), (wb_orep *)o, b.name()); char *bp = (char *)body.value(0); pwr_tOid oid; pwr_sAttrRef attrref; wb_adef asuper[20]; int scnt = 0; asuper[scnt++] = b.adef(); if (asuper[scnt-1] && asuper[scnt-1].isSuperClass()) { // Count rows rows = 0; while (asuper[scnt-1] && asuper[scnt-1].isSuperClass()) { wb_cdef subc = cdef(asuper[scnt-1].subClass()); wb_bdef subb = subc.bdef(pwr_eBix_rt); rows += subb.nAttribute() - 1; asuper[scnt++] = subb.adef(); } rows += b.nAttribute(); int j = 0; for (int i = scnt - 1; i >= 0; i--) { for (wb_adef a = asuper[i]; a; a = a.next()) { if (a && a.isSuperClass()) continue; switch (a.cid()) { case pwr_eClass_Input: case pwr_eClass_Output: case pwr_eClass_Intern: case pwr_eClass_Param: switch (a.type()) { case pwr_eType_Objid: for (int i = 0; i < a.nElement(); i++) { rp->ObjRef.Total++; oid = *(pwr_tOid *)(bp + a.offset() + i * a.size() / a.nElement()); if (cdh_ObjidIsNotNull(oid)) { rp->ObjRef.Used++; wb_object otst = object(oid); if (!otst) rp->ObjRef.Errors++; } } break; case pwr_eType_AttrRef: for (int i = 0; i < a.nElement(); i++) { rp->ObjRef.Total++; attrref = *(pwr_sAttrRef *)(bp + a.offset() + i * a.size() / a.nElement()); if (cdh_ObjidIsNotNull(attrref.Objid)) { rp->ObjRef.Used++; wb_object otst = object(attrref.Objid); if (!otst) rp->ObjRef.Errors++; } } break; default: ; } break; case pwr_eClass_AttrXRef: // TODO break; case pwr_eClass_ObjXRef: // TODO break; default: ; } } if (j > rows) // Something is wrong break; } } else { rows = b.nAttribute(); for (wb_adef a = b.adef(); a; a = a.next()) { switch (a.cid()) { case pwr_eClass_Input: case pwr_eClass_Output: case pwr_eClass_Intern: case pwr_eClass_Param: switch (a.type()) { case pwr_eType_Objid: for (int i = 0; i < a.nElement(); i++) { rp->ObjRef.Total++; oid = *(pwr_tOid *)(bp + a.offset() + i * a.size() / a.nElement()); if (cdh_ObjidIsNotNull(oid)) { rp->ObjRef.Used++; wb_object otst = object(oid); if (!otst) rp->ObjRef.Errors++; } } break; case pwr_eType_AttrRef: for (int i = 0; i < a.nElement(); i++) { rp->ObjRef.Total++; attrref = *(pwr_sAttrRef *)(bp + a.offset() + i * a.size() / a.nElement()); if (cdh_ObjidIsNotNull(attrref.Objid)) { rp->ObjRef.Used++; wb_object otst = object(attrref.Objid); if (!otst) rp->ObjRef.Errors++; } } break; default: ; } break; case pwr_eClass_AttrXRef: // TODO break; case pwr_eClass_ObjXRef: // TODO break; default: ; } } } #if 0 wb_cdef cd = cdef(o); wb_bdef bd = cd.bdef(pwr_eBix_rt); if (!bd) return rp; wb_attribute body = wb_attribute(bd.sts(), (wb_orep *)o, bd.name()); char *bp = (char *)body.value(0); pwr_tOid oid; pwr_sAttrRef attrref; wb_adef ad = bd.adef(); while (ad) { switch (ad.cid()) { case pwr_eClass_Input: case pwr_eClass_Output: case pwr_eClass_Intern: case pwr_eClass_Param: switch (ad.type()) { case pwr_eType_Objid: for (int i = 0; i < ad.nElement(); i++) { rp->ObjRef.Total++; oid = *(pwr_tOid *)(bp + ad.offset() + i * ad.size() / ad.nElement()); if (cdh_ObjidIsNotNull(oid)) { rp->ObjRef.Used++; wb_object otst = object(oid); if (!otst) rp->ObjRef.Errors++; } } break; case pwr_eType_AttrRef: for (int i = 0; i < ad.nElement(); i++) { rp->ObjRef.Total++; attrref = *(pwr_sAttrRef *)(bp + ad.offset() + i * ad.size() / ad.nElement()); if (cdh_ObjidIsNotNull(attrref.Objid)) { rp->ObjRef.Used++; wb_object otst = object(attrref.Objid); if (!otst) rp->ObjRef.Errors++; } } break; default: ; } break; case pwr_eClass_AttrXRef: // TODO break; case pwr_eClass_ObjXRef: // TODO break; default: ; } ad = ad.next(); } #endif return rp; }
wb_attribute wb_volume::attribute(const pwr_sAttrRef* arp) const { pwr_tStatus sts; int idx; bool subClass = false; wb_orep* orep = 0; wb_cdrep* cdrep = 0; wb_bdrep* bdrep = 0; wb_adrep* adrep = 0; wb_adrep* old; if (arp->Objid.vid == m_vrep->vid()) // This volume orep = m_vrep->object(&sts, arp->Objid); else // Other volume orep = m_vrep->erep()->object(&sts, arp->Objid); if (EVEN(sts)) return wb_attribute(); orep->ref(); if (arp->Flags.b.Object) { wb_attribute a(sts, orep); orep->unref(); return a; } cdrep = new wb_cdrep(*orep); if (EVEN(cdrep->sts())) { orep->unref(); return wb_attribute();} pwr_eBix bix = pwr_eBix_rt; if ( arp->Body) bix = (pwr_eBix)(arp->Body & 7); bdrep = cdrep->bdrep(&sts, bix); delete cdrep; if (EVEN(sts)) { orep->unref(); return wb_attribute(); } // Check if we shall reference the whole object if ((arp->Size == 0 && arp->Offset == 0) || (arp->Offset == 0 && arp->Size == bdrep->size() && bdrep->nAttribute() != 1)) { wb_attribute a(sts, orep); orep->unref(); delete bdrep; return a; } // We need to find a matching attribute adrep = bdrep->adrep(&sts); while (ODD(sts)) { bool newBody = false; while (ODD(sts)) { if (arp->Offset < (adrep->offset() + adrep->rsize())){ if (arp->Size == 0 || adrep->size() == arp->Size) { // Attribute found idx = (adrep->nElement() > 1) ? -1 : 0; wb_attribute a(LDH__SUCCESS, orep, adrep, idx); if (arp->Flags.b.Shadowed) a.setShadowed(true); delete bdrep; orep->unref(); return a; } else if (adrep->flags() & PWR_MASK_ARRAY && adrep->size()/adrep->nElement() == arp->Size) { // Attribute element found idx = (arp->Offset - adrep->offset()) / (adrep->rsize() / adrep->nElement()); wb_attribute a(LDH__SUCCESS, orep, adrep, idx); delete bdrep; orep->unref(); return a; } else if (adrep->flags() & PWR_MASK_CLASS) { // Continue to examine object attribute cdrep = m_vrep->merep()->cdrep(&sts, adrep->subClass()); if (EVEN(sts)) { orep->unref(); delete bdrep; return wb_attribute(); } if (bdrep) delete bdrep; bdrep = cdrep->bdrep(&sts, pwr_eBix_rt); if (EVEN(sts)) { orep->unref(); return wb_attribute(); } subClass = true; delete cdrep; old = adrep; adrep = bdrep->adrep(&sts); if (EVEN(sts)) { orep->unref(); delete old; delete bdrep; return wb_attribute(); } if (old->flags() & PWR_MASK_ARRAY) { idx = (arp->Offset - old->offset()) / (old->size() / old->nElement()); adrep->add(old, idx); } else adrep->add(old); delete old; newBody = true; break; } else { // Missmatch delete bdrep; delete adrep; return wb_attribute(); } } if (newBody) break; old = adrep; adrep = adrep->next(&sts); delete old; } } delete bdrep; orep->unref(); return wb_attribute(); }