summaryrefslogtreecommitdiff
path: root/sql/spatial.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/spatial.cc')
-rw-r--r--sql/spatial.cc44
1 files changed, 26 insertions, 18 deletions
diff --git a/sql/spatial.cc b/sql/spatial.cc
index a23e8ec0d90..2305a8eb97d 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -53,7 +53,7 @@ static Geometry::Class_info **ci_collection_end=
Geometry::ci_collection+Geometry::wkb_last + 1;
Geometry::Class_info::Class_info(const char *name, int type_id,
- void(*create_func)(void *)):
+ create_geom_t create_func):
m_type_id(type_id), m_create_func(create_func)
{
m_name.str= (char *) name;
@@ -62,39 +62,39 @@ Geometry::Class_info::Class_info(const char *name, int type_id,
ci_collection[type_id]= this;
}
-static void create_point(void *buffer)
+static Geometry *create_point(char *buffer)
{
- new(buffer) Gis_point;
+ return new (buffer) Gis_point;
}
-static void create_linestring(void *buffer)
+static Geometry *create_linestring(char *buffer)
{
- new(buffer) Gis_line_string;
+ return new (buffer) Gis_line_string;
}
-static void create_polygon(void *buffer)
+static Geometry *create_polygon(char *buffer)
{
- new(buffer) Gis_polygon;
+ return new (buffer) Gis_polygon;
}
-static void create_multipoint(void *buffer)
+static Geometry *create_multipoint(char *buffer)
{
- new(buffer) Gis_multi_point;
+ return new (buffer) Gis_multi_point;
}
-static void create_multipolygon(void *buffer)
+static Geometry *create_multipolygon(char *buffer)
{
- new(buffer) Gis_multi_polygon;
+ return new (buffer) Gis_multi_polygon;
}
-static void create_multilinestring(void *buffer)
+static Geometry *create_multilinestring(char *buffer)
{
- new(buffer) Gis_multi_line_string;
+ return new (buffer) Gis_multi_line_string;
}
-static void create_geometrycollection(void *buffer)
+static Geometry *create_geometrycollection(char *buffer)
{
- new(buffer) Gis_geometry_collection;
+ return new (buffer) Gis_geometry_collection;
}
@@ -145,6 +145,15 @@ Geometry::Class_info *Geometry::find_class(const char *name, uint32 len)
}
+Geometry *Geometry::create_by_typeid(Geometry_buffer *buffer, int type_id)
+{
+ Class_info *ci;
+ if (!(ci= find_class(type_id)))
+ return NULL;
+ return (*ci->m_create_func)(buffer->data);
+}
+
+
Geometry *Geometry::construct(Geometry_buffer *buffer,
const char *data, uint32 data_len)
{
@@ -153,6 +162,7 @@ Geometry *Geometry::construct(Geometry_buffer *buffer,
if (data_len < SRID_SIZE + WKB_HEADER_SIZE) // < 4 + (1 + 4)
return NULL;
+ /* + 1 to skip the byte order (stored in position SRID_SIZE). */
geom_type= uint4korr(data + SRID_SIZE + 1);
if (!(result= create_by_typeid(buffer, (int) geom_type)))
return NULL;
@@ -177,9 +187,7 @@ Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer,
if (!(ci= find_class(name.str, name.length)) ||
wkt->reserve(1 + 4, 512))
return NULL;
- (*ci->m_create_func)((void *)buffer);
- Geometry *result= (Geometry *)buffer;
-
+ Geometry *result= (*ci->m_create_func)(buffer->data);
wkt->q_append((char) wkb_ndr);
wkt->q_append((uint32) result->get_class_info()->m_type_id);
if (trs->check_next_symbol('(') ||