Method: RGeo::Geos::CAPIGeometryMethods#_steal

Defined in:
ext/geos_c_impl/geometry.c

#_steal(orig) ⇒ Object



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'ext/geos_c_impl/geometry.c', line 1019

static VALUE
method_geometry_steal(VALUE self, VALUE orig)
{
  RGeo_GeometryData* self_data;
  const GEOSPreparedGeometry* prep;
  const GEOSGeometry* geom;
  RGeo_GeometryData* orig_data;

  geom = rgeo_get_geos_geometry_safe(orig);
  if (geom) {
    // Clear out any existing value
    self_data = RGEO_GEOMETRY_DATA_PTR(self);
    if (self_data->geom) {
      GEOSGeom_destroy(self_data->geom);
    }
    prep = self_data->prep;
    if (prep && prep != (GEOSPreparedGeometry*)1 &&
        prep != (GEOSPreparedGeometry*)2) {
      GEOSPreparedGeom_destroy(prep);
    }

    // Steal value from orig
    orig_data = RGEO_GEOMETRY_DATA_PTR(orig);
    self_data->geom = orig_data->geom;
    self_data->prep = orig_data->prep;
    self_data->factory = orig_data->factory;
    self_data->klasses = orig_data->klasses;

    // Clear out orig
    orig_data->geom = NULL;
    orig_data->prep = NULL;
    orig_data->factory = Qnil;
    orig_data->klasses = Qnil;
  }
  return self;
}