Re: D bindings for Shapefile C Library

2014-01-29 Thread Rikki Cattermole

On Wednesday, 29 January 2014 at 06:55:17 UTC, evilrat wrote:
On Wednesday, 29 January 2014 at 05:12:45 UTC, Rikki Cattermole 
wrote:


For simple static bindings, it looks fine. You'll probably 
have fun getting it to work on Windows 32 bit though. Thank 
you OMF.


what fun? using (coff)implib once? come on, that's not that 
hard at all...


the only fun is when lib export only constants which is rare.


I'm just referring to it being messier than it needs to be. This 
is a little pet peeve of mine.


Re: D bindings for Shapefile C Library

2014-01-29 Thread Sönke Ludwig

Am 29.01.2014 05:24, schrieb Craig Dillabaugh:

I've created bindings for the C Shapefile Library.  Shapefiles
are a format used commonly in vector based Geographic Information
Systems, often for data interchange. It is a pretty simple
library and it is my first effort at creating such bindings.

https://github.com/craig-dillabaugh/shplib.d

I've looked in Demios and code.dlang.org to see what the standard
setup for such bindings is, and while most are similar there
doesn't seem to be an accepted layout.  If anyone has a moment to
spare I would be happy if someone could have a look to see if
there are any obvious improvements that should be made.

I plan to run a few more tests on my bindings, and once those all
work, I hope to add this to code.dlang.org.


There are only two possible improvements that I can see:

 - The C folder may be better off in the root folder of the project,
   because it doesn't fit with the D sources from a build process point
   of view. In practice it doesn't really hurt either, so your mileage
   may vary.

 - Usually I try to include .lib files for the library bindings on
   Windows, since it greatly simplifies the setup process, which is
   usually trivial on Linux.

Other than that I'd recommend to use a version scheme for the git 
tags/branches that matches the version scheme of the C library (probably 
excluding the patch version, which should be reserved for the binding 
itself). Unfortunately the Deimos bindings use neither branches, nor 
version tags.


Re: D bindings for Shapefile C Library

2014-01-29 Thread Craig Dillabaugh
On Wednesday, 29 January 2014 at 14:09:20 UTC, Gary Willoughby 
wrote:
On Wednesday, 29 January 2014 at 04:24:36 UTC, Craig Dillabaugh 
wrote:

I've created bindings for the C Shapefile Library.  Shapefiles
are a format used commonly in vector based Geographic 
Information

Systems, often for data interchange. It is a pretty simple
library and it is my first effort at creating such bindings.

https://github.com/craig-dillabaugh/shplib.d

I've looked in Demios and code.dlang.org to see what the 
standard

setup for such bindings is, and while most are similar there
doesn't seem to be an accepted layout.  If anyone has a moment 
to

spare I would be happy if someone could have a look to see if
there are any obvious improvements that should be made.

I plan to run a few more tests on my bindings, and once those 
all

work, I hope to add this to code.dlang.org.


This is how i'm doing it:

https://github.com/nomad-software/tcltk

This is a binding for Tcl/Tk libs. I've included windows dll 
import libraries in various formats (for different environments 
and compilers) to make the build process easier. I've also kept 
the c headers in the source folder but excluded them in the 
package.json file (just in case). I've added one version (the 
same as the c sources) for when the bindings supported an older 
version but the latest version is in master.


Thanks. I've had a few requests to generate .lib files so I will 
see about that.  I don't do very much development on Windows, but 
this should be good practice for me.


Re: D bindings for Shapefile C Library

2014-01-29 Thread Gary Willoughby

A few things i tend to do when porting headers:

1). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L267


'const char *filename' should usually be translated to 
'const(char)* filename',

'const double * padfX' = 'const(double)* padfX'
etc..

Reference:
http://forum.dlang.org/thread/qvjjzoxoufxnxzoky...@forum.dlang.org

2). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L275


Underscores on identifiers that match keywords are usually added 
to the end.


Reference:
http://dlang.org/dstyle.html

3). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L263
longs/ulongs tend to be substituted for c_long/c_ulong from 
core.stdc.config.


Reference:
http://dlang.org/interfaceToC.html

4). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L721

I tend to add const to all char* types as above.

In general, add 'nothrow' to all functions and move the '*' to be 
part of the type. e.g.:
'const(char)* text' instead of 'const(char) *text', this is my 
own personal preference though. :p


Re: D bindings for Shapefile C Library

2014-01-29 Thread Craig Dillabaugh
On Wednesday, 29 January 2014 at 14:34:56 UTC, Gary Willoughby 
wrote:

A few things i tend to do when porting headers:

1). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L267


'const char *filename' should usually be translated to 
'const(char)* filename',

'const double * padfX' = 'const(double)* padfX'
etc..

Reference:
http://forum.dlang.org/thread/qvjjzoxoufxnxzoky...@forum.dlang.org

2). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L275


Underscores on identifiers that match keywords are usually 
added to the end.


Reference:
http://dlang.org/dstyle.html

3). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L263
longs/ulongs tend to be substituted for c_long/c_ulong from 
core.stdc.config.


Reference:
http://dlang.org/interfaceToC.html

4). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L721

I tend to add const to all char* types as above.

In general, add 'nothrow' to all functions and move the '*' to 
be part of the type. e.g.:
'const(char)* text' instead of 'const(char) *text', this is my 
own personal preference though. :p


Thanks very much.


Re: D bindings for Shapefile C Library

2014-01-29 Thread Craig Dillabaugh

On Wednesday, 29 January 2014 at 05:26:31 UTC, Suliman wrote:
Big thanks! Could you provide simple example of usage this lib. 
I
have not experience in usage bindings, but I would like to try 
to

write some tiny app to working with shp files.


Not sure what sort of help you need, and what platform?

First thing I would suggest though is to get your hands on some 
Shapefile data.  You can get some free stuff here (there is lots 
of free Shapefile data floating around out there):


http://download.geofabrik.de/

Note that a Shapefile is actually a collection of files (.shp, 
.shx, .dbf, .prj) sharing the same base name. You need all the 
files in the same location and then if you access 'building' the 
library will need the files building.shp, building.shx, 
building.dbf (I think the .prj is optional).


To actually build The Shapefile library you can download it form 
here:


http://shapelib.maptools.org/

I build an static library on linux ( libshp.a ) and then, because 
I was lazy and libshp is small I just copied that into my test 
directory and built a test program with the following command:


dmd -gc shapetest.d shapefil.d libshp.a

Where shapetest.d is my test program, shapefil.d is my binding, 
and libshp.a is the library.


My shapetest.d is currently a bit of a mess, but I can put it on 
gitHub in a day or two if you would like.





Re: D bindings for Shapefile C Library

2014-01-28 Thread Suliman

Big thanks! Could you provide simple example of usage this lib. I
have not experience in usage bindings, but I would like to try to
write some tiny app to working with shp files.


Re: D bindings for Shapefile C Library

2014-01-28 Thread evilrat
On Wednesday, 29 January 2014 at 05:12:45 UTC, Rikki Cattermole 
wrote:


For simple static bindings, it looks fine. You'll probably have 
fun getting it to work on Windows 32 bit though. Thank you OMF.


what fun? using (coff)implib once? come on, that's not that hard 
at all...


the only fun is when lib export only constants which is rare.