First we discuss copying the instance itself. There are two copy methods which are implemented for most geometry classes.
We could use the superclass method to copy our Rot2d instances, this would copy the surface but not axis and curve. Therefore we have implemented these two method, too.
ROT2D *rot2d_hardcopy() { ROT2D *self, *copy; self = (ROT2D *)START_METHOD(G_INSTANCE); ASSURE(self, "", END_METHOD(NULL)); /* * First we call "hardcopy" on the superclass Triang2d to copy * the coordinate and connectivity lists. */ ASSURE(copy = (ROT2D *)GRAPE(self, "^hardcopy")(), "rot2d_hardcopy: can't copy superclass", END_METHOD(NULL)); /* * The superclass method has called "new-instance", therefore we * have these default curves, but we don't need them. We delete * them and reset the pointer to be sure it is valid. */ GRAPE(copy->curve, "delete")(); copy->curve = NULL; GRAPE(copy->axis, "delete")(); copy->axis = NULL; /* * Now if there is a curve it is copied by calling "hardcopy" * and assigning the result to the curve of the copy. The * result is checked to see if we really got a copy. */ if(self->curve) ASSURE(copy->curve = (TRIANG1D *)GRAPE(self->curve, "hardcopy")(), "rot2d_hardcopy: can't copy curve", { GRAPE(copy, "delete")(); END_METHOD(NULL); }); /* * Same for the axis. */ if(self->axis) ASSURE(copy->axis = (TRIANG1D *)GRAPE(self->axis, "hardcopy")(), "rot2d_hardcopy: can't copy axis", { GRAPE(copy, "delete")(); END_METHOD(NULL); }); /* * The other values only have to be copied. */ copy->angle = self->angle; copy->discr = self->discr; copy->current = self->current; END_METHOD(copy); } ROT2D *rot2d_softcopy(ROT2D *copy) { ROT2D *self; self = (ROT2D *)START_METHOD(G_INSTANCE); ASSURE(self, "", END_METHOD(NULL)); /* * First call "softcopy" on the superclass Triang2d. This will create * a new instance if necessary and copy the lists. */ ASSURE(copy = (ROT2D *)GRAPE(self, "^softcopy")(copy), "rot2d_softcopy: can't copy superclass", END_METHOD(NULL)); /* * Now we copy the curve. Since we might use the default curves memory * of the copy we delete it only if the original instance has no curve. */ if(self->curve) { copy->curve = (TRIANG1D *)GRAPE(self->curve, "softcopy")(copy->curve); ASSURE(copy->curve, "rot2d_softcopy: can't copy curve", { GRAPE(copy, "delete")(); END_METHOD(NULL); }); } else { GRAPE(copy->curve, "delete")(); copy->curve = NULL; } /* * Same for the axis. */ if(self->axis) { copy->axis = (TRIANG1D *)GRAPE(self->axis, "softcopy")(copy->axis); ASSURE(copy->axis, "rot2d_softcopy: can't copy axis", { GRAPE(copy, "delete")(); END_METHOD(NULL); }); } else { GRAPE(copy->axis, "delete")(); copy->axis = NULL; } /* * The other values only have to be copied. */ copy->angle = self->angle; copy->discr = self->discr; copy->current = self->current; END_METHOD(copy); }
Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.