Re: Simulating multiple inheritance

2012-04-01 Thread bls

On 03/31/2012 10:05 AM, Andrej Mitrovic wrote:

This is related to wrapping wxWidgets.

One issue with the new wxWidgets 2.9.x series is that there seem to be
more multiply-inherited classes than before


As Jacob already said mixin templates and Interfaces are the way to go.
I think you have to define the mixin template as
*mixin* template mixin_name.

interface Baz
{}

mixin template Baz()
{
// In case that you need to access the parent class
alias typeof(this) ThisClass;
}

class Bar
{}

class Foo : Bar , Baz
{
mixin Baz;
}

Good to know that you are still develop the wxWidget bindings. Keep us 
informed.


Re: Simulating multiple inheritance

2012-04-01 Thread bls

On 03/31/2012 10:05 AM, Andrej Mitrovic wrote:

One issue with the new wxWidgets 2.9.x series is that there seem to be
more multiply-inherited classes than before


A bit more complete snippet.

interface Foo
{
void doFoo();
}
// Foo implementation
mixin template FooMixin()
{
alias typeof(this) thisClass;

void doFoo()
{
thisClass.init();
}
}

class Bar
{
void doFoo() {}
}

class Baz :Bar, Foo
{
alias Bar.doFoo BarFoo;

mixin FooMixin;

void init() {}

}

hth


opDispatch(string name, E...) (E e) question.

2012-03-25 Thread bls

How do I call opDispatch(string name, E...)(E elements) ?
What I want to archive is to call f.i. fm.list with an arbitrary number 
of arguments without using


fm.list(1, abc, 4L, 3.33);

Instead I would prefer
fm.list = (1, abc, 4L, 3.33);

Is this somehow possible ?

import std.variant;
import std.conv;

auto fm = FlexMap();

fm.ten = 10;
fm.ten = [Ten, Zehn, Tein];
fm.list = [20, 10, 2, 2, 44 ] ;
fm.list = Hello opDispatch;

struct FlexMap
{
Variant[] [string] map;

Variant[] opDispatch(string name)()
{
   return map[name];
}

Variant[] opDispatch(string name, E...)(E elements)
{
foreach(element; elements)
map[name] ~= to!Variant(element);
return map[name];
}

Variant[] opDispatch(string name, T) (T t)
{
map[name] ~= to!Variant(t);
return map[name];
}   
}



Another question :
How do I bring in :

opDispatch(string name, T) (T[] t)

into FlexMap ?

TIA, Bjoern


Re: opDispatch(string name, E...) (E e) question.

2012-03-25 Thread bls

On 03/25/2012 02:04 PM, James Miller wrote:

On 26 March 2012 09:45, blsbizp...@orange.fr  wrote:

How do I call opDispatch(string name, E...)(E elements) ?
What I want to archive is to call f.i. fm.list with an arbitrary number of
arguments without using

fm.list(1, abc, 4L, 3.33);

Instead I would prefer
fm.list = (1, abc, 4L, 3.33);


You can use @property on opDispatch to use setter/getter notation,
however I wouldn't rely on that functionality long-term if you want to
keep the same function-call syntax (since -property flag is supposed
to enforce proper parenthesis use on `@property`s).


fm.list = (1, abc, 4L, 3.33);


I'm hoping you mean `fm.list = [1, abc, 4L, 3.33];` I think that
using the right template parameters, you can use the same code for
(T...)(T el) and (T)(T[]), I just can't remember what that is...



Ouch, yep, I mean [1, abc, 4L, 3.33]
But I have no clue how to implement it.



Another question :
How do I bring in :

opDispatch(string name, T) (T[] t)


--
James Miller


(T) (T[] t) AND (T) (T t) seems not to work.
snip
struct FlexMap
{
Variant[] [string] map;

Variant[] opDispatch(string name)()
{
   return map[name];
}

Variant[] opDispatch(string name, E...)(E elements)
{
foreach(element; elements)
map[name] ~= to!Variant(element);

return properties[name];
}

Variant[] opDispatch(string name, T) (T t)
{
map[name] ~= to!Variant(t);
return map[name];
}   
// No go
Variant[] opDispatch(string name, T) (T[] t) {}

}


Re: opDispatch(string name, E...) (E e) question.

2012-03-25 Thread bls

On 03/25/2012 02:59 PM, James Miller wrote:

Ok, so looking here:http://dlang.org/function.html, I have determined
that, if you are using Variant arrays (though I'm not sure if you can
do that using literals...) you can use the syntax from this example:


Thanks James..
will give it tomorrow a new try.

At least
Variant[] va =  [1, 2.3222, abc];

is not working.

Guess I have to give up the opDispatch() thing and create it a bit more 
traditional :)



Bjoern

oh, beside you mean :
opDispatch(string name, T) (T[] t...)


Re: opDispatch(string name, E...) (E e) question.

2012-03-25 Thread bls

Thanks Artur,

On 03/25/2012 03:18 PM, Artur Skawina wrote:

On 03/25/12 22:45, bls wrote:

How do I call opDispatch(string name, E...)(E elements) ?
What I want to archive is to call f.i. fm.list with an arbitrary number of 
arguments without using

fm.list(1, abc, 4L, 3.33);

Instead I would prefer
fm.list = (1, abc, 4L, 3.33);

Is this somehow possible ?


Well, you can do

template ID(A...) { alias A ID; }

fm.list = ID!(1, abc, 4L, 3.33);

but is that any better than your first version above?...

Not sure...

Maybe if we rename it
fm.list = Values!(1,2,true);

But I does not work..  Seems I am not able to figure out the opDispatch 
signature.


Think I will rewrite it without using opDispatch.



artur




QR code based twitter --slightly OT

2012-03-02 Thread bls
Twitter messages are pretty limited, so I think it could make sense to 
implement a QR code based twitter like information-service. D could be 
the tool of choice, But does this idea makes sense at all ? I Think so, 
but would like to hear your opinion.

TIA
Bjoern


Re: Class Initialization

2012-01-31 Thread bls

On 01/31/2012 12:41 PM, Trass3r wrote:

*whispers gee dee c*


windows binaries please...


Re: Partial classes

2012-01-30 Thread bls

On 01/29/2012 01:43 PM, Mars wrote:

Hello everybody.
Quick question, is there anything like C#'s partial classes in D?

Mars


As already said template mixins are close to partial classes.
A snippet. HTH

import std.stdio, std.cstream;

void main(string[] args)
{
auto bar = new Bar();
writeln(bar.onClick());

// Lets the user press Return before program stops
din.getc();
}

mixin template FooMixin()
{
void initCommonControls()
{

}
string onClick()
{
return Clicked;
}
}

class Foo
{
mixin FooMixin;
}
class Bar : Foo
{

}


Re: OOP Windows

2012-01-16 Thread bls

On 01/16/2012 09:07 AM, Andrej Mitrovic wrote:

Oh I thought that tutorial was about MFC/ATL, but it seems to use the
regular C API. I might look into this to add it to the DWinProgramming
project if it's worthwhile.


I think it is worth a closer look.  Especially Bartosz Milewski 
ActiveObject class. https://www.relisoft.com/win32/active.html



OT @Andrej
The MONO folks are using Cairo to rebuild MS NET System.Drawing and 
System.Drawing2D. I wonder if this could be an approach for DGUI.

I quess my question is : using CAIRO or GDI+  as Graphic engine for DGUI.
TIA
Bjoern


Re: Taking a function or delegate as argument.

2012-01-10 Thread bls

On 01/10/2012 06:53 AM, Jacob Carlborg wrote:

On 2012-01-10 14:48, simendsjo wrote:

On 10.01.2012 14:43, Mike Parker wrote:

On 1/10/2012 10:05 PM, simendsjo wrote:

If I want to have a method taking a callback function, I have to
specify
if it should take a function or delegate even if I don't really care.
What's the best way to accept either? I cannot see any wrapper for
something like this in std.typecons.


The simple way:

void callback(int i, void delegate(int) dg)
{
dg(i);
}

void callback(int i, void function(int) fn)
{
void wrap(int j)
{
function(j);
}
callback(i, wrap);
}


Yeah, but a bit tedious.. I found toDelegate:
http://dlang.org/phobos/std_functional.html#toDelegate


Or make it a template parameter and check if it's callable using
std.traits.isCallable.


What's wrong with toDelegate ? Seems to be pretty handy.

//simple snip
import std.functional;

int main()
{
int delegate( int i) dg;
alias dg callback;
callback = toDelegate(test);
writeln( callback( 12 ) );
readln();

return 0;
}

int test(int i) { return 30 +i;}




Re: Using delegate for WindowProc - possible ?

2011-12-29 Thread bls

On 12/28/2011 03:45 PM, Tal wrote:

Can I do something like this :
__
extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) MyWinProcDelegate;

this() {
MyWinProcDelegate =Events;
}

extern (Windows) LRESULT Events (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
MessageBoxA(null , Success!!! , null ,0);
return DefWindowProcA(hWnd, message, wParam, lParam);
}
__

The Events() doesn't seem to fire... am I missing something ?


Maybe std.functional toDelegate() ?

auto DelegateToUse = toDelegate(Events);
Not sure how much sense this makes...

If I  recall correctly I have used

alias extern windows LRESULT delegate() callback;
callback = cbfunc;
As said I am not sure, hth Bjoern


Re: Using delegate for WindowProc - possible ?

2011-12-29 Thread bls

On 12/28/2011 03:45 PM, Tal wrote:

Can I do something like this :
__
extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) MyWinProcDelegate;

this() {
MyWinProcDelegate =Events;
}

extern (Windows) LRESULT Events (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
MessageBoxA(null , Success!!! , null ,0);
return DefWindowProcA(hWnd, message, wParam, lParam);
}
__

The Events() doesn't seem to fire... am I missing something ?


ok next try : At least it compiles ..

import std.functional;

int main(string[] argv)
{



extern(Windows) int delegate() dg;
alias dg callback;
callback = toDelegate(test);




return 0;
}

extern(Windows) int test() { return 42;}

hth, bjoern


Re: Using delegate for WindowProc - Is possible and fun!

2011-12-29 Thread bls

On 12/28/2011 03:45 PM, Tal wrote:

Can I do something like this :
__
extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) MyWinProcDelegate;

this() {
MyWinProcDelegate =Events;
}

extern (Windows) LRESULT Events (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
MessageBoxA(null , Success!!! , null ,0);
return DefWindowProcA(hWnd, message, wParam, lParam);
}
__

The Events() doesn't seem to fire... am I missing something ?


Hi Tal.
I have added an other example using array of delegates. I guess I know 
what you want to do... so do not miss the end of the document. Enjoy.


import std.stdio;
import std.functional;


int main(string[] argv)
{


// array of delegates
extern(Windows) int delegate( int i)[] dg;
alias dg callback;

// function to delegate
callback ~= toDelegate( test );  // std.functional
writeln( callback[0]( 1 ) );

callback ~= toDelegate( inc );
writeln( callback[1] (0) );
writeln (callback[0]( 1 ) );
readln();


return 0;
}

extern(Windows) int test(int i) { return 41 +i;}
extern(Windows) int inc(int i) { return ++i;}

// Now an associative array of delegates indexed by (of course) HWND  ;)
extern (Windows)
LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,LPARAM 
lParam)[HWND] dg;


alias dg MyWinProcDelegate;

bjoern



Re: use of D for ropes data structures

2011-10-19 Thread bls

On 10/19/2011 06:22 AM, Jay Norwood wrote:

can someone propose the appropriate  D features  or libraries that would 
support a native D implementation of the ropes structures described in this Sgi 
C++ library.

http://www.sgi.com/tech/stl/Rope.html


From the library
std.range  -Iteration
std.container (RB tree, and interesting documentation),

Language features, Templates
hth,Bjoern


Re: C Bitfields in D

2010-12-08 Thread BLS

On 08/12/2010 02:23, Simen kjaeraas wrote:

Andrej Mitrovic andrej.mitrov...@gmail.com wrote:


Cool! But, when is ctod.exe coming out? :p



That should have been cpptod. ;)


As soon as you write it.


See d.announce SWIG for D :)


Re: [SO] D support for COM

2010-09-14 Thread BLS

On 13/09/2010 20:58, Jesse Phillips wrote:

There is a question on using COM with D and how it simplifies using COM[1]. I 
haven't done it myself and don't have any examples.

http://stackoverflow.com/questions/3698910/d-support-for-com


http://www.dsource.org/projects/juno/wiki

Juno contains a TypeLibraryImport tool and set of modules making COM 
client respective server programming a piece of cake. Unfortunately Juno 
is not in sync with the latest D2 compiler.


Bjoern



alias this ...

2010-09-06 Thread BLS

// ..snip
point3D p; // Da
p.x = 10;
p.y = 20;
p.z = 100;

point3D = = new point3D(10,20,30) // Njet
//etc
}

struct point {
int x;
int y;
}

struct point3D {

point p;
alias p this;
int z;

// NOPE :(
/*static point3D opcall(int _x, int _y, int _z) {
// ..snip
}*/

// NOPE :(
/*
this(int _x, int _y, int _z) {
// .. snip
}
*/
}
would be nice to use alias this as struct inheritance substitute, 
especially in conjunction with Implements!()


But maybe I don't get the alias this thingy. So what's my mistake  TIA


Re: alias this ...

2010-09-06 Thread BLS

On 06/09/2010 22:36, BLS wrote:

point3D = = new point3D(10,20,30) // Njet
 //etc


should be
point3D p3 = new point3D(10,20,30) // Njet


sorry


Re: Generic collection/element function signatures in D2 versus D1

2010-09-05 Thread BLS

On 05/09/2010 02:16, Jonathan M Davis wrote:

void foo(T)(T[] collection, T elem)

 {
  // Blah, whatever
 }



I am curious, how this will look and feel once inout is working ?

inout void foo(T)(inout(T)[] collection, inout T elem)
{
  // Blah, whatever}
}



Re: Grokking concurrency, message passing and Co

2010-07-12 Thread BLS

On 12/07/2010 10:35, Justin Spahr-Summers wrote:

On Mon, 12 Jul 2010 00:03:53 +0200, BLSwindev...@hotmail.de  wrote:


On 11/07/2010 21:29, Philippe Sigaud wrote:

I tried this because I was reading an article on Scala's actors, where
they talk about millions of actors. I guess they are quite different.


Google for fibers or have a look at the dreactor project on dsource.
Tango has fiber support (afaik).

hth bjoern


Phobos2 has a Fiber class in core.thread as well.


Thanks Justin,
just wish that core. documents are comparable to the std. ones. (At least)
Beside.. why core is not documented at all ?
bjoern


Re: Grokking concurrency, message passing and Co

2010-07-12 Thread BLS

On 12/07/2010 14:18, Lars T. Kyllingstad wrote:

I'm pretty sure they will be soon, perhaps even in the next release:

http://www.dsource.org/projects/druntime/changeset/321

-Lars


Thanks Lars.. Good news ! Hope the auto x = whatever(); //  thing for 
ddoc is also solved than..


Re: std.pattern.. templated publisher subscriber pattern, adding events to collections

2010-07-08 Thread BLS

@ Dmitry
Thanks for all the feedback Dmitry. Seems that we have similar projects 
in mind :) (maybe we can talk about the GUI project.. mine is similar to 
win32++ at http://sourceforge.net/projects/win32-framework/)



However : Like you I would prefer to use something like ..

void delegate(const ref message) CallBack;
CallBack[] cb;
@Jakob
Adding some delegates to our list (D dyn. array) like in C# is a piece 
of cake..


But keep in  mind that we also need  removeObserver() in order to 
implement the Observer pattern.  And removing makes the difference.


The question is now :
How do we identify our Observer object in order to remove..
possible solutions :

1) passing the object instance to the mixin template. (as shown in my 
code) adding of course a : toHash() method.

2)
adding a GUID to the delegate..
3)
...

Dmitry, I think

YOUR :

final class Observable(Cont){
Cont cont;
//here goes your current Publisher stuff
//...
alias Cont!ElementType T;
static if(__traits(compiles,cont.insert(T.init)))//some such ...
need to test if it has this method

SOLUTION

is very hackish. (Beside, like IsForwardRange!R )

IMHO a mixin template is a more clean solution.

BUT this requires that container/collection classes are not final.

Well, even for final classes there is still the option to implement a 
decorator pattern! But the decorator pattern makes code quite unreadable...


However, ATM I am thinking about how we can you use std.concurrent 
message passing stuff...


Finally
Would be nice if we can write a few LOC together! ??
bjoern
PS Sure the Publisher/Observable mixin has to work for structs too.





std.pattern.. templated publisher subscriber pattern, adding events to collections

2010-07-06 Thread BLS

Hi,
Andrei brings in the idea of std.pattern. Seems that this module is 
stalled;  Unfortunately !
However I would like to enhance collection classes (likewise 
dcollections)  with a Publisher - Subscriber pattern (signal - slot, or 
observer pattern) , if you prefer)
Hope the idea of enhancing collections with events become clear with the 
following snippet.
---I am able to spend just a few hours a month with D programming.. in 
other words, please don't kill me ;)


Untested Draft code which requires a lot of help and ,more important, 
feedback from you.


struct publisherMsg(T) {
T data;
Action a;
}
mixin template Publisher(T) {
private :

enum Action = {INSERT, UPDATE, DELETE, READONLY};   
//alias typeof(this) PT;

struct receiver {
Object o;
callback cb;
// opCall() or this() ?
}

receiver[] subscriber;

publisherMsg!(T) msg;

alias void delegate(ref msg) callback;  

void addSubscriber(object o, callback cb) {
//subscriber ~= o;
}   

void publish(T t, Action act) {
foreach  (object o ; subscriber)
{
// create and send message

}
}   
}

mixin template Subscriber() {
// see UndoList
}

final class Stack(T, bool observable = false ) /+ should use alias +/ {
T[] data;   
static if (observable)  mixin Observable!T;

void push(T t) {
publish(t, Action.INSERT)
}
T pop() {

}   
bool empty() {

}
T top() {

}
size_t size() {

}
}


/// Undo list will receive every pushed or popped item (T and Action)
class UndoList(T) {
private:
T[] data;

// should be part of the subscriber mixin template.
publisherMsg!T stackMessage;

void delegate(ref stackMessage) dg;

alias Stack!(int) IntegerStack;
IntegerStack intstack = new IntegerStack;

private this() {
dg = this.feedback;

}
public void feedback(ref stackMessage msg ) {
writefln(push or pop action);
}

}
-Bjoern


Re: std.pattern.. templated publisher subscriber pattern, adding events to collections

2010-07-06 Thread BLS
Okay a  bit better snippet than before. snippet should be almost 
functional..


/*
Hi,
Andrei brings in the idea of std.pattern. Seems that this module is
stalled;  Unfortunately !
However I would like to enhance collection classes (likewise
dcollections)  with a Publisher - Subscriber pattern (signal - slot, or
observer pattern) , if you prefer)
Hope the idea of enhancing collections with events become clear with the
following snippet.
!!! I am able to spend just a few hours a month with D programming.. in
other words, please don't kill me :)
Untested Draft code which requires a lot of help and ,more important,
feedback from you.

*/

struct publisherMsg(T) {
T data;
Action a;
}

mixin template Publisher(T) {
private :

enum Action = {INSERT, UPDATE, DELETE, READONLY};   
//alias typeof(this) PT;

struct receiver {
Object o;
callback cb;
}

receiver[] subscriber;

publisherMsg!(T) msg;

alias void delegate(const ref msg) callback;

void addSubscriber(object o, callback cb) {
//subscriber ~= o;
}   

void publish() {
foreach  (object o ; subscriber)
{
// create message and send message

}
}   
}

mixin template Subscriber() {
  // see UndoList for implementation
}

final class Stack(T, bool observable = false ) {
T[] data;   

static if (observable)  mixin Observable!T;

void push( T t) {
data ~= t;
publish(t, Action.INSERT);  
}
T pop() {
publish(t, Action.DELETE);
//...
}   
bool empty() {

}
T top() {
publish(t, Action.READONLY);
//...
}
size_t size() {

}
}
// Undo list will receive every pushed or popped item -data and action)
class UndoList(T) {
private:
T[] data;

/// should be part of the sunscriber mixin templates.
publisherMsg!T stackMessage;

void delegate(const ref stackMessage) dg;

alias Stack!(int) IntegerStack;

IntegerStack intstack = new IntegerStack;

private this() {
dg = this.feedback;

// SUBBSCRIBE Stack(T) push and pop events.
intstack.addSubscriber(this, dg);

}
public void feedback(const ref stackMessage msg ) {
writefln(Action);
}
}


Re: std.pattern.. templated publisher subscriber pattern, adding events to collections

2010-07-06 Thread BLS

Hi Dimitry, thanks for the feedback!
Please have a look at the new snippet (just posted)

msg is a ref parameter cause it is filled in our example from Stack. The 
Publisher mixin HOST.



In other words. Where ever you mixin the Publisher template a message 
will be broad casted to all subscribers containing 2 information.

1 ) a value of type T, and an enum value INSERT, DELETE etc...

will read your comments tomorrow more carefully.. have to sleep now.)

bjoern


Re: MS VirtualFree(), VirtualAlloc()

2010-07-03 Thread BLS

On 02/07/2010 20:11, BLS wrote:

Hi, for reasons I don't completely understand I would like to implement
a BIP Buffer in D2. ;) well async IO is the use case .. I think.

How can I allocate/free buffer-space from virtual memory ?

What I am looking for is a way to do platform independent allocating of
memory from the virtual address space. Like - VirtualAlloc/Free() in MS
Win.

Thanks in advance,
Bjoern




mmap or mallloc is what I get.. Pretty interesting. shit


MS VirtualFree(), VirtualAlloc()

2010-07-02 Thread BLS
Hi, for reasons I don't completely understand I would like to implement 
a BIP Buffer in D2.  ;) well async IO is the use case .. I think.


How can I allocate/free buffer-space from virtual memory ?

What I am looking for is a way to do platform independent allocating of 
memory from the virtual address space.  Like - VirtualAlloc/Free() in MS 
Win.


Thanks in advance,
Bjoern





dcollections ArrayList pb with mixin template

2010-07-01 Thread BLS
Hi, I have a problem with a mixin template. More exact with an 
Arraylist!T within a mixin template.

Given.
void main() {
auto p = new Person(Hans, 32);
p ~= new Person(Steve, 40);
p ~= new Person(Bjoern, 101);
}   

class Person {
private string _name;
private uint _age;

mixin TLinkList;

this(string name, uint age) {
this._name = name;
this._age = age;
}
}

mixin template TLinkList() {
alias typeof(this) T;
alias ArrayList!T TList;

T[] pa;
auto pl = new TList(pa);  // This does not work !
void opCatAssign(T v) {
pa ~= v;
}   
}
Error: non-constant expression new ArrayList(pa)main.d  

Ideas ?
Thanks Bjoern


Re: dcollections ArrayList pb with mixin template

2010-07-01 Thread BLS

On 01/07/2010 22:59, Steven Schveighoffer wrote:

On Thu, 01 Jul 2010 15:36:53 -0400, BLS windev...@hotmail.de wrote:


Hi, I have a problem with a mixin template. More exact with an
Arraylist!T within a mixin template.
Given.
void main() {
auto p = new Person(Hans, 32);
p ~= new Person(Steve, 40);
p ~= new Person(Bjoern, 101);
}

class Person {
private string _name;
private uint _age;

mixin TLinkList;

this(string name, uint age) {
this._name = name;
this._age = age;
}
}

mixin template TLinkList() {
alias typeof(this) T;
alias ArrayList!T TList;

T[] pa;
auto pl = new TList(pa); // This does not work !
void opCatAssign(T v) {
pa ~= v;
}
}
Error: non-constant expression new ArrayList(pa) main.d

Ideas ?
Thanks Bjoern


I'm thinking it has to do with you trying to create a member with that
line.

I think a member initializer has to be a constant expression, like int i
= 1. Anything else has to be done in the constructor. This kinda sucks,
because you can't initialize members with their defaults where you
declare them, but it's the way D works.

-Steve

Thanks for the feedback Steve.
IMHO it should work.. One reason is that C.E. Miller has created a 
Circularly-linked list module, containing a portable linked list 
template mixin. Indeed Christophers implementation is  different in that 
the LinkList is part of the mixin template...


http://www.dprogramming.com/list.php

2) Commenting the auto pl = new TList() line out makes the snippet work.

mixin template TLinkList() {
alias typeof(this) T;
alias ArrayList!T TList;

T[] pa;
//auto pl = new TList(pa);  // NOW IT WORKS !
void opCatAssign(T v) {
pa ~= v;
}   
Well I am a D noob.  Have to investigate a bit more, and of course any 
help is welcome :)


Bjoern


Re: dcollections ArrayList pb with mixin template

2010-07-01 Thread BLS

On 02/07/2010 00:26, bearophile wrote:

Steven Schveighoffer:

I think a member initializer has to be a constant expression, like int i =
1.  Anything else has to be done in the constructor.


There are the static constructors too, for modules, structs, classes.

Bye,
bearophile


Hi bearophile,
I don't understand (in this context) . Can you please elaborate a bit more ?

thanks bjoern


dcollections ArrayList conating array of classes/structs

2010-06-30 Thread BLS

Hi,
IMHO ArrayList has a bug. Just declaring ArrayList!B bl, raises an 
error. But maybe I am wrong.. Nevertheless I 've filed a ticket. In case 
that I switch from class to struct also std.algorithm is involved.


class AListTest {
alias ArrayList!B BList;
BList bl;
this() {}

}
class B {
string _name;
this(string name) {
this._name = name;
}
}

Error	1	Error: cannot implicitly convert expression (this._array[0u]) of 
type const(B) to main.B 
D:\dmd2\windows\bin\..\..\src\phobos\dcollections\ArrayList.d	772	
Error	2	Error: cannot implicitly convert expression 
(this._array[__dollar - 1u]) of type const(B) to main.B 
D:\dmd2\windows\bin\..\..\src\phobos\dcollections\ArrayList.d	780	


@property and interfaces

2010-06-29 Thread BLS

Just wonder how to translate this C# snippet into D..
//C#
 public interface IBindingList   {

bool AllowEdit {
  get;
}
}

//D2
interface IBindingList {

@property bool allowEdit();
}

Is this correct ? I think in C# AllowEdit() takes tare that you don't 
implement a setter. Seems to be impossible in D.


Thanks Bjoern


Re: @property and interfaces

2010-06-29 Thread BLS

sorry for making so much noise.. figured it out by myse4lf.
interface IBindingList {

@property bool AllowEdit();
//@property bool AllowEdit(bool enable);
//remove // to enable setter
}

class A : IBindingList {
private bool _allowEdit;

@property {
bool AllowEdit() { return _allowEdit;   }
//bool AllowEdit(bool enable) { return _allowEdit = enable; }
}   
}
bjoern

On 29/06/2010 12:11, BLS wrote:

Just wonder how to translate this C# snippet into D..
//C#
public interface IBindingList {

bool AllowEdit {
get;
}
}

//D2
interface IBindingList {

@property bool allowEdit();
}

Is this correct ? I think in C# AllowEdit() takes tare that you don't
implement a setter. Seems to be impossible in D.

Thanks Bjoern




Re: @property and interfaces

2010-06-29 Thread BLS

On 29/06/2010 12:32, Jonathan M Davis wrote:

So, there certainly won't be any restriction on
having a getter or setter in a class if an interface it implements declared only
one. It's just that you'll only be able to use the one that's part of the
interface if you're using a reference of the interface type rather than the
implementing class.


Hi Jonathan,
interesting : this snippet compiles.

interface IBindingList {

@property bool AllowEdit();


class A : IBindingList {
private bool _allowEdit;

@property {
bool AllowEdit() { return _allowEdit;   }
bool AllowEdit(bool enable) { return _allowEdit = enable; }
}   
}

But this one NOT.

interface IBindingList {

@property bool AllowEdit();
@property bool AllowEdit(bool enable);
}
class A : IBindingList {
private bool _allowEdit;

@property {
bool AllowEdit() { return _allowEdit;   }
}   
}
IMO this is bad design.
bjoern


Re: @property and interfaces

2010-06-29 Thread BLS

On 29/06/2010 14:08, Steven Schveighoffer wrote:

Besides, try to do this in C#:

@property int value() {return _x;}
@property int value(int x) { return _x = x;}
@property int value(string s) { return _x = to!int(s);}

:)  D's properties are so much better...

-Steve


Ok, convinced ;)


Re: @property and interfaces

2010-06-29 Thread BLS

Hi bearophile,
sorry for my ignorance, but what is the difference between @disable and 
simply deleting the line ?

where can I read more about @disable ?
thanks, bjoern


C# Indexers. how to implement them in D.. also property related.

2010-06-29 Thread BLS

Hi, in C# you can do some thing like this.

public interface IDataErrorInfo
{
// INDEXER  
string this[string columnName] { get; }
  }
}

how to translate this into D2 ?
thanks in advance, bjoern


Re: C# Indexers. how to implement them in D.. also property related.

2010-06-29 Thread BLS

On 29/06/2010 15:27, Steven Schveighoffer wrote:

string opIndex(string columnName);


yeah this is what I did, too..
However defined as ;

interface I1 {
  string opIndex(string columnName);
}

is a no go. So can we say operator overloading within interfaces is not 
allowed in D2 ?


thanks again Steve.. try to learn the interface/property stuff.


Re: C# Indexers. how to implement them in D.. also property related.

2010-06-29 Thread BLS

On 29/06/2010 15:35, BLS wrote:

On 29/06/2010 15:27, Steven Schveighoffer wrote:

string opIndex(string columnName);


yeah this is what I did, too..
However defined as ;

interface I1 {
string opIndex(string columnName);
}

is a no go. So can we say operator overloading within interfaces is not
allowed in D2 ?

thanks again Steve.. try to learn the interface/property stuff.


Jeez, my mistake.. forget to create the implementation. sorry!


dcollections problem

2010-06-29 Thread BLS

Hi
- probably Steve :)


I have problem in compiling a little programm using dcollection.LinkList.
(similar problem appears when I use dcollections.ArrayList)

D2.047

Linker error..
Error   1   Error 42: Symbol Undefined _D12dcollections8LinkList7__arrayZ   

Error	2	Error 42: Symbol Undefined 
_D12dcollections8LinkList12__ModuleInfoZ		


// LinkList use...
import dcollections.LinkList;

final class LoadBalancer {
alias LinkList!Server ServerList;
private ServerList sl;  
static this() {
synchronized lb = new LoadBalancer;
}
static LoadBalancer opCall() {
return lb;
}
private this() {
sl = new ServerList;
sl.add( new Server() );

...
}
Thanks, Bjoern


Re: dcollections problem

2010-06-29 Thread BLS

On 29/06/2010 20:19, Steven Schveighoffer wrote:

Are you linking against dcollections?  It looks like you are not...



No.


BTW, you can use dcollections' ticket tracking system for things like
this instead of sending to the newsgroup :)


Will do. Thanks Steve
bjoern


dcollections how to LinkList // port c# code

2010-06-29 Thread BLS

Hi,
in C# this is  common.

private ListServer _servers;
 _servers = new ListServer
{
 new Server{ Name = ServerI, IP = 120.14.220.18 },
 new Server{ Name = ServerII, IP = 120.14.220.19 },
 new Server{ Name = ServerIII, IP = 120.14.220.20 },
 new Server{ Name = ServerIV, IP = 120.14.220.21 },
 new Server{ Name = ServerV, IP = 120.14.220.22 },
};

D2 so far..
import dcollections.LinkList;
class LoadBalancer {
alias LinkList!Server ServerList;
private ServerList sl;  

this() {
sl = new ServerList;
sl.add( new Server() );

...
}

Do I really have to create something like this
auto x = new Server(); x.Name = Blah; x.IP = 120.14.220.22;
s1.add(x)
(Name and IP are Server properties.)

thanks
bjoern


Re: dcollections how to LinkList // port c# code

2010-06-29 Thread BLS

On 29/06/2010 22:12, Steven Schveighoffer wrote:

For now, can you do something like this?

sl = new ServerList;
sl.add([
new Server(ServerI, 120.14.220.18),
new Server(...)
...
]);


Hi Steve, I think this should work, however I got very strange err. msg. 
in file ArrayList.d  Have to stop now..need some sleep.

BTW the new constructor stuff would be nice to have.

//current code.

import std.stdio;
import std.random;

import dcollections.ArrayList;
import dcollections.LinkList;

void main() {

auto b1 = LoadBalancer();
auto b2 = LoadBalancer();
auto b3 = LoadBalancer();

// Confirm these are the same instance
if (b1 == b2  b2 == b3 )  {
writeln(Same instance\n);
}

// Next, load 15 requests for a server
for (int i = 0; i  15; i++) {
string serverName = b1.nextServer.servername;
writeln(Dispatch request to:  ~ serverName);
  }
}

// D2 singleton
final class LoadBalancer {
private static LoadBalancer lb;
alias ArrayList!Server ServerList;
private ServerList sl;  

static this() {
synchronized lb = new LoadBalancer;
}

static LoadBalancer opCall() {
return lb;
}

private this() {
sl = new ServerList;
sl.add([
new Server(ServerI, 120.14.220.18),
new Server(ServerII, 121.14.220.18)
]); 
}

@property
{   
Server nextServer() { return sl[uniform(0, sl.length)]; }
}

private class Server {
private string _name, _id;

this(string name, string id) {
this._name = _name;
this._id  = id; 
}

string servername() {
return _name;
}

/* OLD PROPERTY STUFF
@property
{
string servername(string sn) { return _name = sn; }
string servername() { return _name; }

string id(string id) { return _id = id; }
string id() { return _id; }
}
*/

}
}

cheers,bjoern


Re: dcollections how to LinkList // port c# code

2010-06-29 Thread BLS

On 29/06/2010 23:49, Steven Schveighoffer wrote:

One thing to note, ArrayList *does* accept an array as a constructor,
and it will actually use that array as its storage.  This is so you can
wrap an array as a ArrayList and get the full dcollections
functionality from it.


Hi Steve
This is why I've switched from LinkList to ArrayList. (ArrayList is 
simply cool)

also :
Server nextServer() { return sl[uniform(0, sl.length)]; }
is impossible with LinkList. ( sl is LinkList)
yeah opIndex on linked lists is simply slow.

However the snippet in the previous msg. does not compile.. will see later.
bjoern


@porperty problem..

2010-06-28 Thread BLS

Hi I have a forward reference pb in conjunction with @property.
Err msg is :
forward refrence to inferred return type of function call s1.servername.
any ideas ? beside, where are the @property docs ?
thanks, bjoern

final class LoadBalancer {
private static LoadBalancer lb;
private Server[] servers;

static this() {
synchronized lb = new LoadBalancer;
}

private this() {
Server s1 = new Server();
s1.servername = Server 1;  // ERROR
servers ~= s1;
}

public static LoadBalancer getLoadBalancer() {
  return lb;
}

@property nextServer() {
return servers[0];
}

class Server {
private string _name, _id;

@property servername(string name) {
_name = name;
}
@property servername() {
return _name;
}
}
}


Re: @prorperty problem..

2010-06-28 Thread BLS

On 28/06/2010 22:37, BLS wrote:

forward refrence to inferred return type of function call s1.servername.
any ideas ? beside, where are the @property docs ?
thanks, bjoern


ok moving the inner Server class (see prev. msg) in front of 
LoadBalancer works.. seems to be a forward reference bug.


class Server {
private string _name, _id;

@property servername(string name) {
_name = name;
}
@property servername() {
return _name;
}
}
final class LoadBalancer {
private static LoadBalancer lb;
private Server[] servers;

static this() {
synchronized lb = new LoadBalancer;
}

private this() {
Server s1 = new Server();
s1.servername = Server 1;  // NO PROBLEM
}
... 

}



Re: @porperty problem..

2010-06-28 Thread BLS

On 28/06/2010 22:47, Steven Schveighoffer wrote:

houldn't this be

@property Server nextServer() {


Ouch, you are right.. Interesting enough that @property nextServer() { 
return ...} compiles without giving any error message..


Anyway it seems to be a forward reference bug. moving the inner Server() 
class in front of LoadBalancer eliminates the error msg.


bjoern


Re: @porperty problem..

2010-06-28 Thread BLS

On 28/06/2010 22:58, Steven Schveighoffer wrote:

I wasn't aware that @property implies auto.  I guess that makes sense,
but I didn't consider it anything but a hint to the compiler about how
it could be called, not that did anything with the type.


Hm,  this snippet does not compile :
class Server {
private string _name, _id;

@property servername(string name) {
_name = name;
}
@property string servername() {
return _name;
}
}

remove string from @property and it works.

On the other hand ..
@property Server nextServer() {
return servers[0];
}
compiles fine !
Guess we need the official documents...
Bjoern


Re: @porperty problem..

2010-06-28 Thread BLS

On 28/06/2010 23:00, Steven Schveighoffer wrote:


http://www.digitalmars.com/d/2.0/function.html#property-functions

-Steve


Makes sense :) thanks


Re: @porperty problem..

2010-06-28 Thread BLS

On 29/06/2010 00:07, Simen kjaeraas wrote:

Maybe it's because you haven't added string to the setter? Just grasping
at straws here.

--
Simen


Hi Simen, yes, thats the prob. I just have not found the @property 
docs.. thanks for all the help..

This snippet works now as expected.. D properties are just fine.
Bjoern
import std.stdio;
import std.random;

void main(string[] args)
{
LoadBalancer b1 = LoadBalancer.getLoadBalancer();
LoadBalancer b2 = LoadBalancer.getLoadBalancer();
LoadBalancer b3 = LoadBalancer.getLoadBalancer();

// Confirm these are the same instance
if (b1 == b2  b2 == b3 )  {
writeln(Same instance\n);
}

// Next, load 15 requests for a server
for (int i = 0; i  15; i++) {
string serverName = b1.nextServer.servername;
writeln(Dispatch request to:  ~ serverName);
  }

}

// D2 thread safe ?? singleton

final class LoadBalancer {
private static LoadBalancer lb;
private Server[] servers;

static this() {
synchronized lb = new LoadBalancer;
}

private this() {
Server s1 = new Server();
s1.servername = Server 1;
s1.id = ;
Server s2 = new Server();
s2.servername = Server 2;
servers ~= s1;
servers ~= s2;

}

public static LoadBalancer getLoadBalancer() {
  return lb;
}

@property
{   
Server nextServer() { return servers[ uniform(0,
servers.length) ]; }
}

// inner class  
class Server {
private string _name, _id;

@property
{
string servername(string sn) { return _name = sn; }
string servername() { return _name; }

string id(string id) { return _id = id; }
string id() { return _id; }
}
}
}


Re: templates

2010-04-19 Thread BLS

On 19/04/2010 20:16, Ellery Newcomer wrote:

Hello.

Say I have a [struct] template T, which takes a param S.

Any T!(S) satisfies a certain template constraint W, so I can use any
T!(S) the same way. I want to be able to store heterogeneous T!(S) in a
single list. Is there any good way to express the type for this?


Why not simply...

class C(O)
{
  private O obj;
  object next;
  this(O obj)
  {
this.obj = obj;
  }
  ...
  invariant()
  {
assert(this.obj fulfills W);
  }
  ...
}




char* to string

2009-11-04 Thread BLS

HI,
I would like to use some pbobos string based functions within an DLL.
Unfortunately all I can do is to pass char* parameters from the callee 
side.


Now I want to use f.i. std.regex

export extern(windows) char* xxx()


//Heck were is Jarret when I need him most ?

D2,beside

Björn


Re: char* to string

2009-11-04 Thread BLS

On 05/11/2009 00:11, BLS wrote:

char* xxx()


better
char* xxx(char* a, char* b)
{
  string A = 
}




gap buffer in D2

2009-11-04 Thread BLS

yep, mean it...

has somebody done it before...to me it seems to be not as trivial as it 
looks on the very first view. (speed matters)





Re: gap buffer in D2

2009-11-04 Thread BLS

On 05/11/2009 01:04, Spacen Jasset wrote:

BLS wrote:

yep, mean it...

has somebody done it before...to me it seems to be not as trivial as
it looks on the very first view. (speed matters)



Did one in C once for an editor (of course). Does that count? I might be
able to find the code. It might not be pretty I can't remember.


YEP,would be nice to have a look. thanks!

would be interesting to have a 2 gaps buffer for beyond-end insert (append)


Re: Pointer to method C++ style

2009-07-23 Thread BLS

Sergey Gromov wrote:

Use case: I'm writing an ActiveX plug-in for a dynamic language.  The



class Component : IUnknown


WOW!

But shouldn't you use

class Component : IDispatch
{
  HRESULT QueryInterface( REFIID riid, LPVOID * ppvObj) {};
  ULONG   AddRef() {};
  ULONG   Release(){};

  // plus IDispatch methods
  // GetTypeInfoCount, GetTypeInfo, GetIDsOfNames, Invoke.
  // to support late binding ?
}

instead ?

Beside, John C. (Juno library) is a specialist (guru) regarding this 
topic. maybe he is willing to help.


However, I am _very_ interested in having/seeing the source of a very 
basic ActiveX control. Any chance that you share the core implementation 
with us ?

björn




Re: Pointer to method C++ style

2009-07-23 Thread BLS

Sergey Gromov wrote:

Thu, 23 Jul 2009 12:37:42 +0200, BLS wrote:




Sorry, I'm not a guru at all, so ActiveX was a misnomer.  What I'm
writing is a simple in-process server DLL which implements a couple of
interfaces.


Oh, that's sad. :(

well, especially in this case I would suggest to have a look on this page :
http://www.dsource.org/projects/juno/wiki/ComProgramming

--- I think John's juno.com.server module contains almost everything you 
need.


good luck













Re: Regex

2009-07-10 Thread BLS

Robert Fraser wrote:

BLS wrote:

Vladimir Voinkov wrote:
std.regex can't be used in compile time function call. It's quite 
frustrating...


see dsource.org .. afaik there is a compile time regex project. hth


http://www.dsource.org/projects/scregexp

But the generated functions aren't CTFE-compatible AFAIK. A CTFE regex 
engine would be um... tricky to say the least. About 50GB of memory 
tricky (on DMD, LDC has a GC... though, it's still just as slow with 
CTFE). Really, if you need that level of code manipulation, a 
preprocessor is probably a better choice.


Ouch!
Remaining question :
 std.regex can't be used in compile time function call

Why this* don't work for you ?
*  http://www.digitalmars.com/d/2.0/templates-revisited.html
(middle of the document / Regular Expression Compiler)



Re: Regex

2009-07-09 Thread BLS

Vladimir Voinkov wrote:

std.regex can't be used in compile time function call. It's quite frustrating...


see dsource.org .. afaik there is a compile time regex project. hth


Re: [SO] memory paging with D

2009-06-29 Thread BLS

BCS wrote:


http://stackoverflow.com/questions/1057219/memory-paging-with-d

I'm using D/Tango for catalog indexing, is there any library to aid with 
memory (RAM) paging for a dictionary which is in memory and can go up to 
10gb while performing indexing?




Why not using SQLite as memory db ?


Re: Simple file manipulation

2009-05-20 Thread BLS

Sam Hu wrote:

I looked up in D2  in std.stdio,std.file,std.cstream and std.stream and try to find 
a very simple method which can read from a file once a  value other than once an 
entire row.I just can not find it maybe this idea is wrong.Say how to simply read 
 write key/value pairs to and from a file like this format:

//file data.dat
Tommy M 22

where the keys are name,gender and age while the values are Tommy,M ,22.

I found there is methods that can read from a file once an entire row.But is 
there a simple method which can read once a value?In C++ one can do like this:

#include iosteam
#include fstream
using namespace std;
ifstream inData;
inData.open(data.dat);
inDataname;
inDatagender;
inDataage;

coutInfo:endl
   Name:nameendl
   Gender:genderendl
   Age:ageendl;





IN D2 you can use std.file and slurp (cool name, beside)
slurp reads an entire file into an array.

// Load file; each line is an string followed by whitespace , another 
//string followed by whitespace and a  int.


auto a = slurp!(string, string, int)(data.dat, %s %s %s);

Now you can go on an play a bit with the new range stuff. (std.range)

Enjoy, Björn


Re: How to check for internet connectivity and download file?

2009-04-27 Thread BLS

Tyro[a.c.edwards] wrote:

I've used Burton Radons' urllib in the past to get download files from the 
internet, however the library has atrophied and can no longer be used with DMD v2.029 
(not how long it's been this way because I haven't tried to compile it since 2006).

I'm wondering if someone could point me to an example of how to check for 
internet connectivity and if available download the latest version of a given 
file.

Thanks in advance.
Andrew


What about PING ?
Björn


C++ operator new

2009-01-25 Thread BLS

Hi,

I wonder if this is doable in D ?

class Cpp
{
public:
void* operator new(size_t n);
void* operator new(size_t n, void* p)
{ return p; }

}

Just guessing that operator new means this in D
class D
{
new(uint n);
new(uint n,void* p)
{ return p; }

}

Am I wrong ?
TIA, Bjoern



Re: Print a PDF

2008-12-09 Thread BLS

John schrieb:

BCS Wrote:


Reply to John,


Hello!

I'm wanting to use D to send a PDF to a printer. Is there an easy way
to do this? Also, I may need to set which tray to go to and whether it
should duplex or not.

Could someone help me out?

THANKS!

You would do it the same way that it would be done in C. IIRC D has no special 
support for that. (If you need help hunting down windows bindings, there 
are s few people here who work on that kind of thing)





Thanks!

Is there anyone here familiar with the Windows bindings?


The are bindings for the libharu pdf Have a look at dsource.org project 
AKI /


hth,
Bjoern


whois bulk queries, how to

2008-11-08 Thread BLS
Hi I want to do bulk queries on whois engines. Everthing works fine for 
a single request. whois(suneido.com) for instance. The problem is that 
the whois servers  are disconnecting after 1 request. I know about a few 
desktop whois apps which are able to do bulk queries..
Questions is what is the big trick ? This seems to be a good kept 
secret. Any ideas ?

Bjoern