[geos-devel] Why WKBConstants is a namespace?

Mateusz Łoskot mateusz at loskot.net
Mon Mar 20 08:05:27 EST 2006


strk at refractions.net wrote:
> On Mon, Mar 20, 2006 at 01:13:32PM +0100, Mateusz Å?oskot wrote:
> 
>>Why WKBConstants is a namespace instead of enum?
> 
> 
> It was a namespace in Java (an interface):
> 
> public interface WKBConstants {
>   int wkbXDR = 0;
>   int wkbNDR = 1;
> 
>   int wkbPoint = 1;
>   int wkbLineString = 2;
>   int wkbPolygon = 3;
>   int wkbMultiPoint = 4;
>   int wkbMultiLineString = 5;
>   int wkbMultiPolygon = 6;
>   int wkbGeometryCollection = 7;
> }
>  
> As you can see an enum won't be able to hold wkbPoint
> and wkbNDR  with the same value.

Why?
AFAIK it will be able.

C++ Standard says in "7.2 Enumeration declarations":

"If the first enumerator has no initializer, the value of
the corresponding constant is zero. An enumerator-definition without an 
initializer gives the enumerator the value
obtained by increasing the value of the previous enumerator by one.

[ Example:
enum { a , b , c =0 };
enum { d , e , f=e +2 };
defines a, c, and d to be zero, b and e to be 1, and f to be 3.
—end example]"

As you can see:
enum { a , b , c =0 };

is equivalent of:

enum { a = 0, b = 0, c = 0 };

> Also, it might grow including flags for dimensionality
> and SRID presence or whatever ends up being a WKB
> constant.

Yes, but those would be placed to separate enums.

It will also provide better type-safety in some cases.

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the geos-devel mailing list