void ClassInstanceData::read(char *& st, char *& k) { BasicData::read(st, k); // updates k if (strcmp(k, "type")) wrong_keyword(k, "type"); cl = BrowserClass::read_ref(st, 0); read_keyword(st, "attributes"); while (strcmp(k = read_keyword(st), "end")) { BrowserAttribute * a = BrowserAttribute::read(st, k, 0, TRUE); attributes.append(SlotAttr(a, read_string(st))); } read_keyword(st, "relations"); while (strcmp(k = read_keyword(st), "end")) { RelationData * r = RelationData::read_ref(st, TRUE, k); relations.append(SlotRel(TRUE, r, BrowserClassInstance::read_ref(st))); } k = read_keyword(st); }
void ClassInstanceData::read_attributes(char *& st, char *& k) { while (strcmp(k = read_keyword(st), "end") && strcmp(k, "xyz")) { // very old version BrowserAttribute * a = BrowserAttribute::read(st, k, 0, FALSE); QString s = read_string(st); if (a != 0) attributes.append(SlotAttr(a, s)); } check(); }
bool ClassInstanceData::tool_cmd(ToolCom * com, const char * args, BrowserNode * bn, const QString & comment) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!bn->is_writable() && !root_permission()) com->write_ack(FALSE); else { switch ((unsigned char) args[-1]) { case setTypeCmd: set_class((BrowserClass *) com->get_id(args)); break; case setAttributeCmd: { BrowserAttribute * at = (BrowserAttribute *) com->get_id(args); bool find = FALSE; Q3ValueList<SlotAttr>::Iterator it_attr; for (it_attr = attributes.begin(); it_attr != attributes.end(); ++it_attr) { SlotAttr & slot_attr = *it_attr; if (slot_attr.att == at) { find = TRUE; if (*args == 0) // remove it attributes.remove(it_attr); else // replace it slot_attr.value = args; break; } } if (! find) { // add it Q3PtrList<BrowserClass> l; cl->get_all_parents(l); l.append(cl); if (at->deletedp() || (l.findRef((BrowserClass *) at->parent()) == -1)) { // illegal com->write_ack(FALSE); return TRUE; } attributes.append(SlotAttr(at, args)); } } break; case addRelationCmd: if (! change_rel(com, args, TRUE)) return TRUE; break; case removeRelationCmd: if (! change_rel(com, args, FALSE)) return TRUE; break; default: return BasicData::tool_cmd(com, args, bn, comment); } // ok case bn->modified(); modified(); com->write_ack(TRUE); } } else { switch ((unsigned char) args[-1]) { case attributesCmd: if (args[0] == 0) { com->write_unsigned(attributes.count()); Q3ValueList<SlotAttr>::Iterator it; for (it = attributes.begin(); it != attributes.end(); ++it) { const SlotAttr & slot = *it; slot.att->write_id(com); com->write_string(slot.value); } } else { // get all available attributes BrowserNodeList l; BrowserNode * bn; cl->get_attrs(l); com->write_unsigned(l.count()); for (bn = l.first(); bn != 0; bn = l.next()) bn->write_id(com); } break; case relationsCmd: { BrowserClassInstance * other = (BrowserClassInstance *) com->get_id(args); if (other == 0) { com->write_unsigned(relations.count()); Q3ValueList<SlotRel>::Iterator it; for (it = relations.begin(); it != relations.end(); ++it) { const SlotRel & slot = *it; ((slot.is_a) ? slot.rel->get_start() : slot.rel->get_end()) ->write_id(com); slot.value->write_id(com); } } else { // get all available relations Q3PtrList<BrowserRelation> l; BrowserRelation * r; cl->get_rels(((ClassInstanceData *)other->get_data())->cl, l); com->write_unsigned(l.count()); for (r = l.first(); r != 0; r = l.next()) r->write_id(com); } } break; default: return BasicData::tool_cmd(com, args, bn, comment); } } return TRUE; }