Re: UI Library

2022-05-19 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote:
I need to write a piece of software to track and categorize 
some purchases. It's the kind of thing I could probably write 
in a couple of hours in C#/Java + html/css/javascript. However, 
something keeps drawing me to D and as this is a simple 
application, it would be a good one to get back in after almost 
a year hiatus.


[...]


Maybe you can use minigui from arsd

https://github.com/adamdruppe/arsd


Re: Bug in std.json or my problem

2020-04-22 Thread Craig Dillabaugh via Digitalmars-d-learn
On Wednesday, 22 April 2020 at 18:35:49 UTC, CraigDillabaugh 
wrote:

On Wednesday, 22 April 2020 at 18:23:48 UTC, Anonymouse wrote:
On Wednesday, 22 April 2020 at 17:48:18 UTC, Craig Dillabaugh 
wrote:

clip


File an issue if you have the time, maybe it will get 
attention. Unreported bugs can only be fixed by accident.


I thought it might be worth filing a bug, but wanted to confirm 
if others thought this was actually a bug.  I had encountered 
an identical issue with vibe-d years ago.


Thanks for the feedback.


After some digging it appears there is already a fix for this 
(though a bit old) … maybe I am the only person who cares about 
std.json after all :o)


https://github.com/dlang/phobos/pull/5005/commits/e7d8fb83d2510b252cd8cfd2b744310de6fa84e5



Bug in std.json or my problem

2020-04-22 Thread Craig Dillabaugh via Digitalmars-d-learn
So perhaps I am the only person in the world using std.json, but 
I was wondering

if the following code should work.

=
import std.json;
import std.conv;
import std.stdio;

struct Person {
string name;
float income;

this (string name, float income) {
this.name = name;
this.income = income;
}

this(JSONValue js) {
this.name = to!string(js["name"]);
/* This next line crashes with .. JSONValue is not 
floating type.

 *  to!float( js["income"].toString()) works.
 */
this.income = js["income"].floating;
}

JSONValue toJSON() {
JSONValue json;
json["name"] = JSONValue(this.name);
json["income"] = JSONValue(this.income);
return json;
}
}


int main(string[] argv) {
Person bob = Person("Bob", 0.0);

string bob_json = bob.toJSON().toString();

Person sonofbob = Person(parseJSON(bob_json));

writeln(sonofbob.toJSON().toPrettyString());

return 0;
}
===

The crash is caused because the 'income' field with value 0.0 is
output as 0 (rather than 0.0) and when it is read this is 
interpreted

as an integer.

Shouldn't this work?


Re: How the hell to split multiple delims?

2020-02-15 Thread Craig Dillabaugh via Digitalmars-d-learn

On Saturday, 15 February 2020 at 11:32:42 UTC, AlphaPurned wrote:
I've tried 10 different ways with split and splitter, I've used 
all the stuff that people have said online but nothing works. I 
always get a template mismatch error.


Why is something so easy to do so hard in D?

auto toks = std.regex.split(l, Regex("s"));
auto toks = std.regex.splitter(l, Regex("s"));
auto toks = std.regex.splitter(l, ctRegex!r"\.");


I had the same problem myself recently, and almost ended up here 
to ask the same question as you but stumbled across the following 
(ugly) solution without using regexs.


char[] line = "Split this by#space or#sign."

auto parts = line.splitter!(a => a=='#' | a==' ').array;






Re: To learn D

2019-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 5 July 2019 at 12:00:15 UTC, Binarydepth wrote:
I've considering learning full D. I remembered that D is not 
recommended as a first language, So I read time ago.


So my question, is learning C and Python a good intro before 
learning D?


TY


Ali's book is targeted at beginners (see link below).  I don't 
see why D wouldn't make a good first language.  If your objective 
is to learn D, then I don't think learning C or Python is going 
to be help that much.  Obviously if you know C/Python you can 
learn D more quickly, but I doubt the effort is worth it if D is 
the ultimate goal.


http://ddili.org/ders/d.en/index.html


Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Craig Dillabaugh via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 03:25:05 UTC, rikki cattermole 
wrote:

On 06/02/2018 8:46 PM, Craig Dillabaugh wrote:

On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote:

[...]

clip

[...]

clip

[...]


Wouldn't it be more accurate to say OO is not the correct tool 
for every job rather than it is "outdated".  How would one 
write a GUI library with chains and CTFE?


But you could with signatures and structs instead ;)


I am not sure how this would work ... would this actually be a 
good idea, or are you just saying that technically it would be 
possible?


Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Craig Dillabaugh via Digitalmars-d-learn

On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote:
On Tue, Feb 06, 2018 at 06:33:02PM +, Ralph Doncaster via 
Digitalmars-d-learn wrote:

clip


OO is outdated.  D uses the range-based idiom with UFCS for 
chaining operations in a way that doesn't require you to write 
loops yourself. For example:


import std.array;
import std.algorithm;
import std.conv;
import std.range;

// No need to use .toStringz unless you're interfacing with C
auto hex = "deadbeef";// let compiler infer the type for you

	auto bytes = hex.chunks(2)	// lazily iterate over `hex` by 
digit pairs

   .map!(s => s.to!ubyte(16))// convert each pair to a ubyte
   .array;  // make an array out of it

// Do whatever you wish with the ubyte[] array.
writefln("%(%02X %)", bytes);


clip

T


Wouldn't it be more accurate to say OO is not the correct tool 
for every job rather than it is "outdated".  How would one write 
a GUI library with chains and CTFE?


Second, while 'auto' is nice, for learning examples I think 
putting the type there is actually more helpful to someone trying 
to understand what is happening. If you know the type why not 
just write it ... its not like using auto saves you any work in 
most cases. I understand that its nice in templates and for 
ranges and the like, but for basic types I don't see any 
advantage to using it.





Re: Object oriented programming and interfaces

2017-12-04 Thread Craig Dillabaugh via Digitalmars-d-learn

On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote:

Hi!

I defined an interface:

interface Medoid {
float distance( Medoid other );
uint id() const @property;
}

and a class implementing that interface:

class Item : Medoid {
float distance( Item i ) {...}
uint id() const @property {...}
}

The compiler says:
Error: class Item interface function 'float distance(Medoid 
other)' is not implemented


Is there a way to implement the Item.distance() member function 
taking any object whose class is Item?


Interfaces are expected to implement static or final functions. 
See #6 at:


https://dlang.org/spec/interface.html

interface Medoid {
static float distance( Medoid other );
uint id() const @property;
}


class Item : Medoid {
static float distance( Item i ) { return 0.0f; }
uint id() const @property { return 1; }
}


Re: Help with an algorithm!

2017-06-15 Thread CRAIG DILLABAUGH via Digitalmars-d-learn

On Thursday, 15 June 2017 at 13:41:07 UTC, MGW wrote:
On Thursday, 15 June 2017 at 13:16:24 UTC, CRAIG DILLABAUGH 
wrote:


The purpose - search of changes in file system.
Sorting is a slow operation as well as hashing. Creation of a 
tree, is equally in sorting.

So far the best result:

string[] rez;

foreach(str; m2) {
bool fFind; int j;
foreach(int i, s; m1) {
if(str == s) { fFind = true; j = i; break; }
}
if(!fFind) { rez ~= str; }
else   {m1[j] = m1[$-1]; m1.length = m1.length - 1; }
}

//  rez => rezult

How to parallel on thred?


radix sort is O(N) time, which is as fast as you can hope. But 
given your specific problem domain (the strings are paths) an 
initial radix sort step likely won't gain you much, as everything 
is going to be sorted into a small subset of the buckets. So I 
guess you can scrap that idea.


Knowing that your strings are actually file paths I think 
building some sort of tree structure over M1 wouldn't be 
unreasonable. You say go two or three levels deep on your 
directory structure (ie nodes are labelled with directory name) 
and use that to split M1 into buckets. If some bucket has too 
many entries you could apply this recursively. Since you are only 
building a constant number of levels and the number of nodes is 
not likely to be too large you should do much better than N log N 
* c time for this step.


Then you search with the elements of M2. You should be able to do 
this in a multi-threaded way since once built, your data 
structure on M1 is read-only you could just split M2 over X 
threads and search. I am not an expert in this regard though, so 
perhaps someone better informed than I can chime in.


Since strings will tend to have long common prefix's Ivan's Trie 
idea would also work well.








Re: Help with an algorithm!

2017-06-15 Thread CRAIG DILLABAUGH via Digitalmars-d-learn

On Thursday, 15 June 2017 at 11:48:54 UTC, Ivan Kazmenko wrote:

On Thursday, 15 June 2017 at 06:06:01 UTC, MGW wrote:
There are two arrays of string [] mas1, mas2; Size of each 
about 5M lines. By the size they different, but lines in both 
match for 95%. It is necessary to find all lines in an array 
of mas2 which differ from mas1. The principal criterion - 
speed. There are the 8th core processor and it is good to 
involve a multithreading.


The approaches which come to mind are:


clip

taking constant time.

Ivan Kazmenko.


As a follow up to this, if your alphabet is reasonably small 
perhaps could run radix sort based on the first few characters to 
split your arrays up into smaller subsets, and then use one of 
Ivan's suggestions within each subset.  Subset searches could be 
easily run in parallel.


Re: Check of point inside/outside polygon

2016-07-27 Thread CRAIG DILLABAUGH via Digitalmars-d-learn

On Wednesday, 27 July 2016 at 14:56:13 UTC, Suliman wrote:

On Wednesday, 27 July 2016 at 12:47:14 UTC, chmike wrote:

On Wednesday, 27 July 2016 at 09:39:18 UTC, Suliman wrote:

clip


Sorry, its my issue I am thinging about polygons, but for me 
would be enought points.
The problem is next. I am writhing geo portal where user can 
draw shape. I need to get users images that user shape cross. 
But as temporal solution it would be enough to detect if image 
central point inside this polygon (I know its coordinates).


I can do its on DB level, but I would like to use SQLite that 
do bot have geometry support. So i am looking for any solution. 
I can use gdal but its _very_ heavy


So when you say you want polygon intersection, is one of the 
polygons you are interested in the shape of the images (ie. 
roughly a rectangle)?


If this is the case then you can likely just take the bounding 
rectangle (easily calculated) of your polygon and check if that 
intersects the bounding rectangle for the the image and that 
should work 95% of the time.




Re: Check of point inside/outside polygon

2016-07-27 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 27 July 2016 at 09:39:18 UTC, Suliman wrote:

On Wednesday, 27 July 2016 at 08:40:15 UTC, chmike wrote:
The algorithm is to draw a horizontal (or vertical) half line 
starting at your point and count the number of polygon edges 
crossed by the line. If that number is even, the point is 
outside the polygon, if it's odd, the point is inside.


Let (x,y) be the point to test and (x1,y1)(x2,y2) the end 
points on each segment. Let n be the number of crossing that 
you initialize to 0. (x1,y1)(x2,y2) are also the corners of 
the rectangle enclosing the segment.


You then have to examine each segment one after the other. The 
nice thing is that there are only two cases to consider.
1. When the point is on the left side of the rectangle 
enclosing the segment.

2. When the point is inside the rectangle enclosing

if (y1 <= y2)
{
if ((y1 <= y) && (y2 >= y))
{
   if ((x1 < x) && (x2 < x))
   {
  // case 1 : point on the left of the rectangle
  ++n;
   }
   else if (((x1 <= x) && (x2 >= x)) || ((x1 >= x) && (x2 
<= x)))

   {
  // case 2 : point is inside of the rectangle
  if ((x2 - x1)*(y - y1) >= (y2 - y1)*(x - x1))
  ++n; // Increment n because point is on the 
segment or on its left

   }
}
}
else
{
if ((y1 >= y) && (y2 <= y))
{
   if ((x1 < x) && (x2 < x))
   {
  // case 1 : point on the left of the rectangle
  ++n;
   }
   else if (((x1 <= x) && (x2 >= x)) || ((x1 => x) && (x2 
<= x)))

   {
  // case 2 : point is inside of the rectangle
  if ((x2 - x1)*(y - y2) >= (y1 - y2)*(x - x1))
  ++n; // Increment n because point is on the 
segment or on its left

   }
}
}

This algorithm is very fast.

I didn't tested the above code. You might have to massage it a 
bit for corner cases. It should give you a good push to start.


Big thanks!
Ehm... Now I should add iteration on array of points in first 
and second polygon? If it's not hard for you could you show how 
it should look please.


Easiest solution (if you don't care about performance) is to 
pairwise compare every segment of both polygons to see if they 
intersect, and if that fails, then run point-in-polygon algorithm 
with one vertex from each polygon and the other (catches the case 
where one polygon is entirely contained within the other).


Now you have the point in polygon algorithm (kindly provided by 
chmike) and testing for segment intersection is a basic primitive 
geometric operation, so there are lots of examples on the web.  
You should certainly be able to find working C code for this 
without much trouble.


Re: AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 02:33:02 UTC, ketmar wrote:
On Wednesday, 6 July 2016 at 02:19:47 UTC, Craig Dillabaugh 
wrote:

[...]


this is true for any dynamic array, including AAs. until 
something is added to array, it actually a `null` pointer. i.e. 
arrays (and AAs) generally consisting of pointer to data and 
some length/info field. while array is empty, pointer to data 
is `null`. and when you passing your dynamic array slice/AA to 
function, it makes a copy of those internal fields. reallocing 
`null` doesn't affect the original variable.


generally speaking, you should use `ref` if you plan to make 
your dynamic array/AA grow. i.e.


 void insertValue (ref int[][string]aa, string key, int value)


Thanks for giving me the correct solution, and for the 
explanation.


Cheers,
Craig


Re: AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 02:03:54 UTC, Adam D. Ruppe wrote:
On Wednesday, 6 July 2016 at 01:58:31 UTC, Craig Dillabaugh 
wrote:

*(keyvalue) ~ value;   // This line fails.


That should prolly be ~= instead of ~.


Ahh, I was so close.  Thank you that seems to do the trick.

However, now I have another issue.

For the following main function:

int main( string[] args) {

int[][string] myAA;

//int[] tmp;
//tmp ~= 7;
//myAA["world"] = tmp;

insertValue( myAA, "hello", 1 );
insertValue( myAA, "goodbye", 2 );
insertValue( myAA, "hello", 3 );

foreach (k; myAA.keys.sort)
{
writefln("%3s %d", k, myAA[k].length);
}

return 0;
}

If I run this, it prints out nothing.  However, if I uncomment 
adding an element for 'world' then it prints (as expected):


goodbye 1
hello 2
world 1

Why doesn't my function allow me to insert elements into an empty 
associative array, but succeeds for an AA with some element in it?




AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn
How can I create (and update) and associative array where the key 
is a string, and the value is a dynamic array of integers?


For example:

void insertValue( int[][string]aa, string key, int value )
{
int[]* keyvalue;

keyvalue = ( key in aa );
if ( keyvalue !is null )
{
*(keyvalue) ~ value;   // This line fails.
}
else {
int[] tmp;
tmp ~= value;
aa[key] = tmp;
}
}


int main( string[] args) {

int[][string] myAA;

insertValue( myAA, "hello", 1 );
insertValue( myAA, "goodbye", 2 );
insertValue( myAA, "hello", 3 );

return 0;
}

Fails with:
...(16): Error: ~ has no effect in expression (*keyvalue ~ value)

Thanks for any help.



Re: Issue with 2.071: Regression or valid error?

2016-04-06 Thread Craig Dillabaugh via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 19:01:58 UTC, Craig Dillabaugh 
wrote:

On Wednesday, 6 April 2016 at 15:10:45 UTC, Andre wrote:

clip


Not so up to date on D's OOP stuff, but don't you want create() 
to be protected, not private.  You can typically access a 
private method through a base class, which is what you are 
doing with cat.create().


You CAN'T typically access a private ...


Re: Issue with 2.071: Regression or valid error?

2016-04-06 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 6 April 2016 at 15:10:45 UTC, Andre wrote:

Hi,

With 2.071 following coding does not compile anymore and 
somehow I feel it should compile.

The issue is with line "cat.create();".
Cat is a sub type of Animal. Animal "owns" method create and I 
want to call the method

create within the class Animal for cat.

Is the error message "no property create for type 'b.cat'" 
valid or not?


Kind regards
André

module a;
import b;

class Animal
{
private void create() {}

void foo(Cat cat)
{
cat.create(); // >> no property create for type 'b.cat'
}
}

void main() {}

--

module b;
import a;

class Cat: Animal {};

compile with

rdmd a b


Not so up to date on D's OOP stuff, but don't you want create() 
to be protected, not private.  You can typically access a private 
method through a base class, which is what you are doing with 
cat.create().


Re: How is D doing?

2015-12-23 Thread Craig Dillabaugh via Digitalmars-d-learn

On Thursday, 24 December 2015 at 00:16:16 UTC, rsw0x wrote:

On Tuesday, 22 December 2015 at 21:38:22 UTC, ZombineDev wrote:
On Tuesday, 22 December 2015 at 17:49:34 UTC, Jakob Jenkov 
wrote:

clip



removed C++ because it just dwarfs the others.
D, as I expected, has a massive following in Japan. I'm still 
not quite sure why.


Hey, this can be D's theme song:

https://www.youtube.com/watch?v=Cg6rp20OGLo



Re: DUB linking to local library

2015-08-04 Thread Craig Dillabaugh via Digitalmars-d-learn

On Tuesday, 4 August 2015 at 08:18:58 UTC, John Colvin wrote:
On Tuesday, 4 August 2015 at 03:20:38 UTC, Craig Dillabaugh 
wrote:

I can now run it with:

LD_LIBRARY_PATH=/home/craig2/code/gdal-2.0.0/lib64 ./gdaltest

But it appears the LD_LIBRARY_PATH hack is causing havoc with 
other libraries, as I get errors loading other shared 
libraries when I do that.


At the very least you want to do:

LD_LIBRARY_PATH=/home/craig2/code/gdal-2.0.0/lib64:$LD_LIBRARY_PATH ./gdaltest


Thanks!


Re: DUB linking to local library

2015-08-04 Thread Craig Dillabaugh via Digitalmars-d-learn
On Tuesday, 4 August 2015 at 04:21:27 UTC, Joakim Brännström 
wrote:
On Tuesday, 4 August 2015 at 03:20:38 UTC, Craig Dillabaugh 
wrote:

clip


Linkers, so fun they are...
https://wiki.debian.org/RpathIssue

As you can see in the search order RPATH takes precedence over 
LD_LIBRARY_PATH.
If we assume that you want LD_LIBRARY_PATH to be able to 
override the lib you could use the following flags.


lflags : [ --enable-new-dtags, 
-rpath=/home/craig2/code/gdal-2.0.0/lib64/, 
-L/home/craig2/code/gdal-2.0.0/lib64/ ]


you can see what it is in the binary with: readelf --dynamic 
gdaltest|grep PATH


This should make LD_LIBRARY_PATH redundant.

//Joakim


I knew using LD_LIBRARY_PATH was frowned upon, thanks for 
enlightening me on the correct way to handle this.  Works 
beautifully now.


DUB linking to local library

2015-08-03 Thread Craig Dillabaugh via Digitalmars-d-learn
I have been writing bindings for the GDAL library (www.gdal.org). 
  I recently updated my bindings to the latest release of GDAL 
(2.0).


Before adding my bindings to code.dlang.org I want to run some 
tests.  I've built GDAL2 locally and want to link my bindings to 
this library.  However, I also have the older GDAL libraries 
(1.11) installed system wide on my machine.


My GDAL bindings have the following dub.json file:

{
name: gdald,
	description: D bindings for the Geospatial Data Abstraction 
Library (GDAL).,

homepage: https://github.com/craig-dillabaugh/TBD;,
homepage: http://www.gdal.org/;,
importPaths:[.],
targetType:sourceLibrary,
license: MIT,
authors: [
Craig Dillabaugh
],
libs : [gdal]
}

While my test program appears as follows:

{
name: gdaltest,
description: Test cases for GDAL D.,
copyright: Copyright © 2014, Craig Dilladub bubaugh.,
authors: [
Craig R. Dillabaugh
],
dependencies: {
gdald : {version: ~master}
},
	lflags : [ 
-L/home/craig2/code/gdal-2.0.0/lib64/libgdal.so.20.0.0 ],

libs : [gdal],
targetPath : .,
targetType : executable
}

I used add-local so that my test program could see my bindings.

My issue is that while everything compiles OK (with dub build) 
the resulting executable gdaltest seems to be linked with the 
system gdal.so file and not the libgdal.so.20.0.0 file I 
specified with lflags.


ldd prints out:

ldd gdaltest
linux-vdso.so.1 (0x7ffe417e2000)
libgdal.so.1 = /usr/lib64/libgdal.so.1 
(0x7faabacf8000)


So how can I force my application to link to my local copy of 
GDAL2 at /home/craig2/code/gdal-2.0.0/lib64.  Any help is 
appreciated.



Craig






Re: DUB linking to local library

2015-08-03 Thread Craig Dillabaugh via Digitalmars-d-learn
On Tuesday, 4 August 2015 at 02:45:21 UTC, Joakim Brännström 
wrote:
On Tuesday, 4 August 2015 at 02:26:17 UTC, Craig Dillabaugh 
wrote:
So how can I force my application to link to my local copy of 
GDAL2 at /home/craig2/code/gdal-2.0.0/lib64.  Any help is 
appreciated.


Hi,

I recently ran into similare problems, different lib.
Try changing:
lflags : 
[-L/home/craig2/code/gdal-2.0.0/lib64/libgdal.so.20.0.0 ]

libs : [gdal]
to:
lflags : [-L/home/craig2/code/gdal-2.0.0/lib64/ ]
libs : [:libgdal.so.20.0.0]

observe the flags dub passes on to dmd by using --vverbose

//Joakim


Thanks.  Everything compile perfectly, and now the correct libs 
are linked it seems, but I still have an issue with the 
executable:


ldd gdaltest
linux-vdso.so.1 (0x7ffe63381000)
libgdal.so.20 = not found

I can now run it with:

LD_LIBRARY_PATH=/home/craig2/code/gdal-2.0.0/lib64 ./gdaltest

But it appears the LD_LIBRARY_PATH hack is causing havoc with 
other libraries, as I get errors loading other shared libraries 
when I do that.







Re: Binding Nested C Structs

2015-07-09 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 10 July 2015 at 03:38:49 UTC, Craig Dillabaugh wrote:
I am trying to bind to a C union with a number of nested 
structs declared as follows:


typedef union {
int Integer;

struct {
int nCount;
int *paList;
} IntegerList;

struct {
int nCount;
GIntBig *paList;
} Integer64List;

} OGRField;

According to 
http://wiki.dlang.org/D_binding_for_C#Nested_Structs

I should attempt to write something like (last example shown):

extern(C) union OGRField
{
   int Integer;
   struct {
  int  nCount;
  int* paList;
   }

   struct {
  int  nCount;
  GIntBig* paList;
   }
}

But that is obviously not going to work.  Does anyone know the 
right way

to handle nested C structs of that form.


OK Found the answer elsewhere on the same page:

extern(C) union OGRField
{
   int Integer;
   struct _IntegerList
   {
  int  nCount;
  int* paList;
   }
   _IntegerList IntegerList;


   struct _Integer64List
   {
  int  nCount;
  GIntBig* paList;
   }
   _Integer64List Integer64List;
}



Binding Nested C Structs

2015-07-09 Thread Craig Dillabaugh via Digitalmars-d-learn
I am trying to bind to a C union with a number of nested structs 
declared as follows:


typedef union {
int Integer;

struct {
int nCount;
int *paList;
} IntegerList;

struct {
int nCount;
GIntBig *paList;
} Integer64List;

} OGRField;

According to http://wiki.dlang.org/D_binding_for_C#Nested_Structs
I should attempt to write something like (last example shown):

extern(C) union OGRField
{
   int Integer;
   struct {
  int  nCount;
  int* paList;
   }

   struct {
  int  nCount;
  GIntBig* paList;
   }
}

But that is obviously not going to work.  Does anyone know the 
right way

to handle nested C structs of that form.


Re: Converting void* to D array

2015-04-14 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 15 April 2015 at 04:43:39 UTC, Daniel Kozák wrote:


On Wed, 15 Apr 2015 04:24:20 +
Craig Dillabaugh via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:


Hi.
I want to call a C library function that returns a data buffer 
as a void*.  How do I convert the resulting void* into 
something I can process in D?


//I have the following function from the GDAL C library.
extern(C) CPLErr GDALReadBlock( GDALRasterBandH, int, int, 
void* );



So I have (GByte is defined in the GDAL library):

void* buffer = malloc( GByte.sizeof * x_block_size * 
y_block_size );


I fill the buffer (and ignore any errors :o)

GDALReadBlock( AGDALRasterBandHInstance, xblock, yblock, 
buffer );



Now, how can I access the data in buffer?

Or you probably can do it like this:

auto buffer = new GByte[xblock*yblock];

GDALReadBlock( AGDALRasterBandHInstance, xblock, yblock,
(cast void*)buffer.ptr );


Thank you very much. Works like a charm.

Make that last line:
GDALReadBlock( AGDALRasterBandHInstance, xblock, yblock,

cast(void*)buffer.ptr );


Converting void* to D array

2015-04-14 Thread Craig Dillabaugh via Digitalmars-d-learn

Hi.
I want to call a C library function that returns a data buffer as 
a void*.  How do I convert the resulting void* into something I 
can process in D?


//I have the following function from the GDAL C library.
extern(C) CPLErr GDALReadBlock( GDALRasterBandH, int, int, void* 
);



So I have (GByte is defined in the GDAL library):

void* buffer = malloc( GByte.sizeof * x_block_size * y_block_size 
);


I fill the buffer (and ignore any errors :o)

GDALReadBlock( AGDALRasterBandHInstance, xblock, yblock, buffer );


Now, how can I access the data in buffer?


Contributing to Phobos Documentation

2015-03-21 Thread Craig Dillabaugh via Digitalmars-d-learn

Motivated by this thread:

http://forum.dlang.org/thread/measc3$qic$1...@digitalmars.com

I was hoping to see if I could do some work on the Phobos 
documentation, but I am curious to know what the easiest way for 
someone with limited/no ddoc experience to get involved in this 
would be.  I checked the CONTRIBUTING.md file in phobos and it is 
a bit on the 'light' side.


I assume just fixing stuff in my local repo and sending PRs would 
be insufficient, as I should be 'testing' my documentation 
changes.  Is there a resource where I can learn how to generate 
the phobos documentation for phobos locally.


Second question, can I generate documentation for a single module 
rather than all of phobos each time I try to update something.


Craig


Re: Contributing to Phobos Documentation

2015-03-21 Thread Craig Dillabaugh via Digitalmars-d-learn

On Saturday, 21 March 2015 at 21:53:00 UTC, H. S. Teoh wrote:
On Sat, Mar 21, 2015 at 05:48:40PM +, Craig Dillabaugh via 
Digitalmars-d-learn wrote:

Motivated by this thread:

http://forum.dlang.org/thread/measc3$qic$1...@digitalmars.com

I was hoping to see if I could do some work on the Phobos
documentation, but I am curious to know what the easiest way 
for
someone with limited/no ddoc experience to get involved in 
this would
be.  I checked the CONTRIBUTING.md file in phobos and it is a 
bit on

the 'light' side.

I assume just fixing stuff in my local repo and sending PRs 
would be
insufficient, as I should be 'testing' my documentation 
changes.  Is

there a resource where I can learn how to generate the phobos
documentation for phobos locally.


On Posix:

git clone https://github.com/D-Programming-Language/dlang.org
cd dlang.org
make -f posix.mak phobos-prerelease
cd ..
ln -s dlang.org/web .
cd ../phobos
make -f posix.mak html

You should now be able to point your browser at
web/phobos-prerelease/index.html and see the generated docs.

Or copy web/* into your web folder of your local webserver and 
point

your browser to the appropriate URL.

Note that for this to work, the dlang.org and phobos repos must 
share a
common parent directory, as the makefiles currently make a lot 
of
assumptions about your directory layout, and may die horribly 
if you use

a non-standard layout.


Second question, can I generate documentation for a single 
module

rather than all of phobos each time I try to update something.

[...]

You could just run `make -f posix.mak html` and it should only 
update
those files that changed since you last ran it. (In theory, 
anyway. Make
is unreliable and sometimes you have to delete the generated 
files in

order to refresh them, but hopefully this will be rare.)


T


Thanks very much.
Craig


Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-14 Thread Craig Dillabaugh via Digitalmars-d-learn

On Saturday, 14 March 2015 at 09:59:05 UTC, dnewer wrote:
yes,java is good lang,but i dont think it's better than c#,if 
no oracle or google support java will less and less.

C# is a good and easy lang.
i like C# .
but,C# cant compiled to native code.

So far, I have been searching for a language, like c # write 
efficiency, but more secure than that of c #, more efficient 
(runs), stronger (system-level, driving level)


What has led you to this conclusion?  I don't personally find D 
very much like Java.  It definitely doesn't push OO design on you 
like Java (even where it isn't needed), and code is much more 
concise in my experience. I also find D very much more flexible.


I don't have any C# experience so I can't compare those languages 
much, but I've heard people say their are D / C# similarities.


Anyway, this isn't a criticism of your comment, I was just 
curious what (other than the shared C++ syntax heritage) you find 
so Java-like in D?


Cheers,

Craig



Re: Getting started with vibe.d

2014-06-03 Thread Craig Dillabaugh via Digitalmars-d-learn

On Tuesday, 3 June 2014 at 16:16:10 UTC, Chris Saunders wrote:
I've made my first attempt to use dub/vibe.d and I'm running 
into some issues I can't find on the list.


I'm on Ubuntu 14.04/x86_64, using the latest stable dub 
(0.9.21). I can create a new dub project:


“””
$ dub init test vibe.d
Successfully created an empty project in 
'/home/csaunders/devel/csaunders/mongoSB/test'

“””

...but then I'm having trouble building:

“””
$ cd test
$ dub build --compiler=ldc2
vibe-d: [vibe-d, libevent, openssl]
test: [test, vibe-d, libevent, openssl]
Building vibe-d configuration libevent, build type debug.
FAIL 
../../../../.dub/packages/vibe-d-0.7.19/.dub/build/libevent-debug-linux.posix-x86_64-ldc2-0C180158569265198380A4CE65BB2C41 
vibe-d staticLibrary

Error executing command build: No LDC static libraries supported
“””

...I've tried a few variations on this but haven't had any 
luck. This is using the latest ldc:


“””
$ ldc2 --version
LDC - the LLVM D compiler (0.12.1):
  based on DMD v2.063.2 and LLVM 3.3.1
  Default target: x86_64-unknown-linux-gnu
  Host CPU: corei7
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
x86- 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
“””

Any pointers?


Just curious, can you get it to work with DMD?

Also, you might consider posting on the Rejected Software forums 
(although this forum isn't a bad idea).


http://forum.rejectedsoftware.com/


Re: Getting started with vibe.d

2014-06-03 Thread Craig Dillabaugh via Digitalmars-d-learn

On Tuesday, 3 June 2014 at 17:41:27 UTC, Chris Saunders wrote:

Thanks, I somehow missed the vibe.d forums...

I'd need an ldc solution in the end, but trying dmd is a good 
idea. The result is some kind of link error to libevent?:



 dub build
vibe-d: [vibe-d, libevent, openssl]
test: [test, vibe-d, libevent, openssl]
Target is up to date. Using existing build in 
/home/csaunders/.dub/packages/vibe-d-0.7.19/.dub/build/libevent-debug-linux.posix-x86_64-dmd-AB0707232CA963B5DA23C2232BBED51B/. 
Use --force to force a rebuild.

Building test configuration application, build type debug.
Compiling...
Linking...
.dub/build/application-debug-linux.posix-x86_64-dmd-6EEB0831D66A347BFD0076DC383B442F/test.o:(.data._D162TypeInfo_S3std8typecons130__T5TupleTS3std9container54__T5ArrayTS4vibe4core7drivers9libevent212TimeoutEntryZ5ArrayVAyaa6_5f73746f7265TmVAyaa7_5f6c656e677468Z5Tuple6__initZ+0x60): 
undefined reference to 
`_D3std8typecons130__T5TupleTS3std9container54__T5ArrayTS4vibe4core7drivers9libevent212TimeoutEntryZ5ArrayVAyaa6_5f73746f7265TmVAyaa7_5f6c656e677468Z5Tuple15__fieldPostBlitMFZv'

collect2: error: ld returned 1 exit status
--- errorlevel 1
FAIL 
.dub/build/application-debug-linux.posix-x86_64-dmd-6EEB0831D66A347BFD0076DC383B442F 
test executable
Error executing command build: Link command failed with exit 
code 1




Just a guess, but do you have the dev libraries for libevent 
installed?





Re: D Newbie Trying to Use D with Major C Libraries

2014-05-15 Thread Craig Dillabaugh via Digitalmars-d-learn
On Thursday, 15 May 2014 at 22:25:47 UTC, Tom Browder via 
Digitalmars-d-learn wrote:
I am a volunteer developer with the well-known 3D CAD FOSS 
project BRL-CAD:


  http://brlcad.org

I have wanted to use D for a long time but I hadn't taken the 
plunge.
Yesterday I advertised to the BRL-CAD community my new project 
to
attempt to create D bindings for BRL-CAD's C libraries, and I 
created

a branch for the project.

I have been looking for specific information on creating D 
bindings
from C headers for which there seems to be sufficient 
information

available, but I would appreciate recommendations as to the best
method.  I have successfully built my first pure D program but 
now

need to test the feasibility of my project.

What I have not seen yet is the exact way to build a D program 
which
uses D bindings and its matching C library.  I have just 
created a
Cookbook page on the D Wiki where I show my first attempt for a 
real
GNU Makefile as an example for the project.  The page link is 
here:


  http://wiki.dlang.org/Using_C_libraries_for_a_D_program

I would appreciate it if an experienced D user would correct 
that

recipe so it should compile the desired binary source correctly
(assuming no errors in the  input files).

Thanks for any help.

Best regards,

-Tom



Hi Tom,
Sadly, I lack the expertise to give you much advice.  I did read 
through your Wiki posting though.  One thing that came to mind 
was you used GMake.  Perhaps you should consider using DUB.  For 
example here is the DUB config file for one of my library 
bindings (in my case I used a static library though):


{
name: shplib,
description: D bindings for Shapelib. Shapefile 
reader.,
homepage: 
https://github.com/craig-dillabaugh/shplib.d;,

homepage: http://shapelib.maptools.org/;,
importPaths:[.],
targetType: sourceLibrary,
authors: [
Craig Dillabaugh
],
sourcePaths: [./source],
libs-posix : [libshp]
}

A little nicer that GMake, more the D way, and cross platform 
... I think.


Not sure exactly how you change that for linking to a .so lib.

Cheers,

Craig


Re: D Newbie Trying to Use D with Major C Libraries

2014-05-15 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 16 May 2014 at 01:16:46 UTC, Craig Dillabaugh wrote:
On Thursday, 15 May 2014 at 22:25:47 UTC, Tom Browder via 
Digitalmars-d-learn wrote:
I am a volunteer developer with the well-known 3D CAD FOSS 
project BRL-CAD:


 http://brlcad.org

I have wanted to use D for a long time but I hadn't taken the 
plunge.
Yesterday I advertised to the BRL-CAD community my new project 
to
attempt to create D bindings for BRL-CAD's C libraries, and I 
created

a branch for the project.

I have been looking for specific information on creating D 
bindings
from C headers for which there seems to be sufficient 
information
available, but I would appreciate recommendations as to the 
best
method.  I have successfully built my first pure D program but 
now

need to test the feasibility of my project.

What I have not seen yet is the exact way to build a D program 
which
uses D bindings and its matching C library.  I have just 
created a
Cookbook page on the D Wiki where I show my first attempt for 
a real
GNU Makefile as an example for the project.  The page link is 
here:


 http://wiki.dlang.org/Using_C_libraries_for_a_D_program

I would appreciate it if an experienced D user would correct 
that

recipe so it should compile the desired binary source correctly
(assuming no errors in the  input files).

Thanks for any help.

Best regards,

-Tom



Hi Tom,
Sadly, I lack the expertise to give you much advice.  I did 
read through your Wiki posting though.  One thing that came to 
mind was you used GMake.  Perhaps you should consider using 
DUB.  For example here is the DUB config file for one of my 
library bindings (in my case I used a static library though):


{
name: shplib,
description: D bindings for Shapelib. Shapefile 
reader.,
homepage: 
https://github.com/craig-dillabaugh/shplib.d;,

homepage: http://shapelib.maptools.org/;,
importPaths:[.],
targetType: sourceLibrary,
authors: [
Craig Dillabaugh
],
sourcePaths: [./source],
libs-posix : [libshp]
}

A little nicer that GMake, more the D way, and cross platform 
... I think.


Not sure exactly how you change that for linking to a .so lib.

Cheers,

Craig


Some info on DUB can be found at:

http://code.dlang.org/


Writing to stdin of a process

2014-04-26 Thread Craig Dillabaugh via Digitalmars-d-learn
I want to be able to write to the stdin stream of an external 
process using std.process.  I have the following small test app.


myecho.d
--

import std.stdio;

void main(string[] args)
{
  foreach (line; stdin.byLine()) {
stdout.writeln(line);
  }
}

--

If I call this from the command line, it echo's back whatever I 
write

to it.

Then I have the following program.

testpipes.d
---
import std.process;
import std.stdio;

void main( string[] args ) {

auto pipes = pipeProcess(./myecho, Redirect.stdin );
scope(exit) wait(pipes.pid);

pipes.stdin().writeln(Hello world);
}


If I compile and run testpipes.d, nothing happens.  I was 
expecting

it to echo back Hello world to me.

Can anyone tell me what I am dong wrong.


Re: Writing to stdin of a process

2014-04-26 Thread Craig Dillabaugh via Digitalmars-d-learn

On Saturday, 26 April 2014 at 13:30:41 UTC, Adam D. Ruppe wrote:
On Saturday, 26 April 2014 at 08:45:59 UTC, Craig Dillabaugh 
wrote:

Can anyone tell me what I am dong wrong.


In this case, I'd close the pipe when you're done.


pipes.stdin().writeln(Hello world);
pipes.stdin.close;


myecho loops on stdin until it receives everything; until the 
pipe is closed.


testpipes waits for myecho to complete before termination.


The two processes are waiting on each other: testpipes won't 
close the file until it exits, and myecho won't exit until 
testpipes closes the file.


an explicit call to close breaks the deadlock.


In this case, flushing would cause the one line to appear, 
because of the buffering yazd talked about, but the program 
still wouldn't terminate since a flushed buffer still 
potentially has more coming so echo would see that line, then 
wait for  more..


Thank you Adam, and yazd for your responses, now it works.  
Thanks also for the explanations, I was wondering how myecho.d 
would know when the input was finished so it could terminate.


Re: Example of parse whole json answer.

2014-04-24 Thread Craig Dillabaugh via Digitalmars-d-learn

On Thursday, 24 April 2014 at 12:17:42 UTC, Nicolas wrote:
I have a json string saved in a file ( example of json tweeter 
answer: 
https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline 
). I am trying to read the whole json answer and print specific 
data (created_at, retweet_count, ..) . I am new at D 
Programming language and i was wondering if someone can help me 
or post some example that show how to parse json strings using 
std.json library. Thanks in advance.


Here is something to get you started.  The initial version of 
this code was from Ali Cehreli, I can't remember what 
modifications are mine, or if this is all straight form Ali.


If you intend to do any serious work with Json, I highly 
recommend you check out Vibe.d (www.vibed.org) - more stuff to 
learn but its JSON capabilities are awesome compared to what 
std.json gives you.


import std.stdio;
import std.json;
import std.conv;
import std.file;

/**
  Ali's example.
*/
struct Employee
{
string firstName;
string lastName;
}

void readEmployees( string employee_json_string )
{

	JSONValue[string] document = 
parseJSON(employee_json_string).object;

JSONValue[] employees = document[employees].array;

foreach (employeeJson; employees) {
JSONValue[string] employee = employeeJson.object;

string firstName = employee[firstName].str;
string lastName = employee[lastName].str;

auto e = Employee(firstName, lastName);
writeln(Constructed: , e);
}   
}

void main()
{
// Assumes UTF-8 file
auto content =
`{
  employees: [
{ firstName:Walter , lastName:Bright },
{ firstName:Andrei , lastName:Alexandrescu },
{ firstName:Celine , lastName:Dion }
  ]
}`;

readEmployees( content );

//Or to read the same thing from a file
readEmployees( readText( employees.json ) );

}