コード例 #1
0
ファイル: BrowserNode.cpp プロジェクト: SciBoy/douml
void BrowserNode::delete_it() {
  if (! deletedp()) {
    if (UndefinedNodePackage == 0) {
      // not during a read
      QString warning;
    
      if (!delete_internal(warning)) {
	warning = full_name() + TR(" cannot be deleted because :") + warning;
	
	warn(warning);
      }
      else {
	// mark modified to not delete the associated file(s)
	// on exit if no save was done before
	is_modified = TRUE;
      }
      
      if (BrowserSearchDialog::get() != 0)
	BrowserSearchDialog::get()->update();
      
      if (ReferenceDialog::get() != 0)
	ReferenceDialog::get()->update();
    }
    else {
      // during a read : no check
      is_deleted = TRUE;
      if (is_marked) {
	marked_list.removeRef(this);
	is_marked = FALSE;
      }
      if (is_writable())
	package_modified();
      
      if (get_data() != 0)
	get_data()->delete_it();
      
      // delete the sub elts
      Q3ListViewItem * child;
      
      for (child = firstChild(); child != 0; child = child->nextSibling())
	if (! ((BrowserNode *) child)->deletedp())
	  ((BrowserNode *) child)->delete_it();
      
      setOpen(FALSE);      
      must_be_deleted();
    }
  }
}
コード例 #2
0
ファイル: radix.c プロジェクト: schlosna/Haywire
void* rxt_delete(char *key, rxt_node *root)
{
    rxt_node *parent, *grandparent;
    rxt_node *n = get_internal(key, root);
    void *v;
    char *newkey = NULL;
    if (!n) return NULL; // nonexistent

    v = n->value;

    // remove both the node and the parent inner node
    // XXX TODO FIXME Still somewhat broken. Figure out.
    parent = n->parent;
    grandparent = parent->parent;

    if (!grandparent) {
        if (parent->left == n) {
            return delete_internal(n, parent->right);
        } else if (parent->right == n) {
            return delete_internal(n, parent->left);
        } else if (parent->value == n) {
            parent->value = NULL;
            parent->color = 0;
            parent->pos = 0;
        } else
            printf("something very wrong when removing w/o gp!\n");

        free(n);
        return v;
    }

    // properly move around pointers and shit
    // TODO ascii art
    if (grandparent->left == n->parent) {
        newkey = grandparent->right->key; // not sure if this is correct
        if (parent->left == n) {
            grandparent->left = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->left = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->left\n");
    } else if (grandparent->right == n->parent) {
        newkey = grandparent->left->key;
        if (parent->left == n ) {
            grandparent->right = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->right = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->right\n");
    } else
        printf("something very wrong: grandparent does not possess child\n");

    reset_key(n->key, newkey, grandparent);
    parent->left = NULL;
    parent->right = NULL;
    free(parent);
    free(n); // we don't dynamically allocate node

    return v;
}