emulate with

2019-05-31 Thread Amex via Digitalmars-d-learn

with lets one remove a direct reference...

The problem is the things I want to access are not part of a 
single object but have a common naming structure:


X_A
X_B
X_C_Q

(rather than X.A, X.B, X.C.Q)

it would be very helpful(since X is long) to be able to do 
something like


with(X)
{
A;
B;
C_Q;
}

or even

with(X)
{
A;
B;
with(C)
{
Q;
}
}


I imagine this can actually be done with dispatching because one 
could use opDispatch to redirect. The problem is that this 
requires filling out the info which sorta defeated the 
purpose(unless it's used often).


What I'm talking about is that if A would be dispatched to, say, 
W!X where W handles the special dispatching by returning X_A 
rather than X.A.



I don't know if D can do this kinda stuff even though it would be 
rather simple as it would depend on with.


e.g., would be cool if there was an opWith ;)





Re: emulate with

2019-05-31 Thread Simen Kjærås via Digitalmars-d-learn

On Friday, 31 May 2019 at 07:17:22 UTC, Amex wrote:
What I'm talking about is that if A would be dispatched to, 
say, W!X where W handles the special dispatching by returning 
X_A rather than X.A.



I don't know if D can do this kinda stuff even though it would 
be rather simple as it would depend on with.


Of course D can! However, it's not really pretty, and I think I 
found a bug in the process.


This is my code that compiles and runs:

void X_A(int i) {}
void X_A(string s) {}
void X_B(int i) {}
void X_C_Q(int i) {}

unittest {
with (Dispatcher.X!({})) {
A(1);
A("a");
B(2);
C_Q(3);
}
}

template getMethod(alias x, string name) {
static if (__traits(hasMember, x, name)) {
alias getMethod = __traits(getMember, x, name);
} else static if (x.stringof[0..7] == "module ") {
import std.meta : AliasSeq;
alias getMethod = AliasSeq!();
} else {
alias getMethod = getMethod!(__traits(parent, x), name);
}
}

struct Dispatcher {
template opDispatch(string prefix) {
static auto opDispatch(alias context)() {
struct WithObject {
auto opDispatch(string name, A...)(A a) {
struct OverloadCaller {
auto opCall(Args...)(Args args) {
return getMethod!(context, 
prefix~"_"~name)(args);

}
}
OverloadCaller result;
return result;
}
}
return WithObject();
}
}
}

So, the ugly:

1) Instead of just Dispatcher.X, we need to give Dispatcher a 
context from where to look for X_. That's the curly 
brackets in Dispatcher.X!({}).


2) The bug I mentioned. The whole OverloadCaller deal is a silly 
workaround for WithObject's opDispatch not being called correctly 
by DMD. That's also why WithObject's opDispatch takes (A...)(A 
a). I'll be filing this, of course.


3) with doesn't correctly handle static opDispatch. I'll be 
filing a bug for that as well.


We could fix 1) by introducing a new magic identifier - something 
like __CONTEXT__, which would work somewhat like __FUNCTION__, 
but be useful for reflection with __traits. I've played a little 
with this idea, but I'm not ready to make a PR with it.


With 1), 2) and 3) fixed, the code would look like this (only 
changed code included):


unittest {
with (Dispatcher.X) {
A(1);
A("a");
B(2);
C_Q(3);
}
}

struct Dispatcher {
struct opDispatch(string prefix, alias context = __CONTEXT__) 
{

static auto opDispatch(string name, Args...)(Args args) {
 return getMethod!(context, prefix~"_"~name)(args);
}
}
}

I think that's kinda neat, TBH.

--
  Simen


Re: emulate with

2019-05-31 Thread KnightMare via Digitalmars-d-learn
imo for parts of names such things will never appear.. names, 
subnames, overloading.. hell no


but I want Kotlin lambdas
https://kotlinlang.org/docs/reference/lambdas.html
I want more:
Function literals with receiver
it: implicit name of a single parameter
Passing a lambda to the last parameter
than will appear
https://ask.ericlin.info/post/2017/06/subtle-differences-between-kotlins-with-apply-let-also-and-run/
https://medium.com/tompee/idiomatic-kotlin-lambdas-with-receiver-and-dsl-3cd3348e1235



Blog Post #0040 - File Dialog VI - The Simple Message Dialog

2019-05-31 Thread Ron Tarrant via Digitalmars-d-learn
Today's blog post covers a topic that was requested back in 
mid-April, the message dialog. Some of the extra info you may 
glean from today's post is:


- tracing widget inheritance to find a complete list of available 
functions, and

- where to find the DialogFlags enum.

You can find it here: 
http://gtkdcoding.com/2019/05/31/0040-messagedialog.html


Have a great weekend, everyone.



Reading .pem files for secured

2019-05-31 Thread Dukc via Digitalmars-d-learn
I need to manually sign and verify stuff with asymmetric crypto 
keys. I ended up using rsa from secured.


The key pair needs to be persistant between, so I made a 4096-bit 
private key with OpenSSL, stored in .pem file. Then I constructed 
a public key from the private one, again with OpenSSL. It seemed 
strange to me that I could generate a public key afterwards with 
the private key, instead of having to do both at the same time. I 
just thought that perhaps crypto is somehow cryptic enough to do 
that.


But then came a problem that I need to feed the key from .pem to 
initialize RSA class at 
https://github.com/LightBender/SecureD/blob/master/source/secured/rsa.d. Someone at the internet claimed that .pem files are Base64-encoding. "Great, there's a base64 handler in Phobos", was my reaction. It was easy to write a parser, but I think something must have went wrong.


The reason is that if I understand the logic of Base64, it's that 
each character stores 6 bits. My private key .pem has 49 lines of 
64 characters worth of Base64, though the sat line isn't full. 
Anyway, this is data worth of over 18000 bits. The RSA key is 
supposed to be 4096 bits, so this can't be correct.


What am I missing?


Re: Reading Dicom files in Dlang

2019-05-31 Thread KnightMare via Digitalmars-d-learn

whats wrong with answer at SO?
https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang


Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Anonymouse via Digitalmars-d-learn

On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:


What is the correct way?


--DRT flags are for run time, not compile time. They're 
intended to be passed to your executable and not the compiler. 
From the docs [1]:


"By default, GC options can only be passed on the command line 
of the program to run"


My use-case is limiting the amount of memory dmd will allocate 
before -lowmem kicks in and collects (by use of 
--DRT-gcopt=heapSizeFactor on dmd), to accomodate for limited 
available memory. As pasted in the original post I seem to be 
able to do this manually.


So there is no way to set up a dub build configuration that 
automates this?


Re: Reading Dicom files in Dlang

2019-05-31 Thread KnightMare via Digitalmars-d-learn

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   // 
 line 457

  _outer = data;
  _a = a;
  _b = b;
}


imo problem is in string
private __vector(ushort)_outer;
it looks like template(vector!ushort) or function or this is 
vector from core.simd

and replacing it to private long _outer; fix the problem
paste code imebra.d and imebra_im.d to someplace


Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Andre Pany via Digitalmars-d-learn

On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:


What is the correct way?


--DRT flags are for run time, not compile time. They're 
intended to be passed to your executable and not the compiler. 
From the docs [1]:


"By default, GC options can only be passed on the command line 
of the program to run"


With dub, anything following a solitary -- on the command line 
will be passed to the application [2], so you probably want 
something like this:


dub test -- --DRT-gcopt=profile:1

[1] https://dlang.org/spec/garbage.html#gc_config
[2] https://dub.pm/commandline


This might be eaten by the runtime of dub and not the application.

Kind regards
Andre


Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Mike Parker via Digitalmars-d-learn

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:


What is the correct way?


--DRT flags are for run time, not compile time. They're intended 
to be passed to your executable and not the compiler. From the 
docs [1]:


"By default, GC options can only be passed on the command line of 
the program to run"


With dub, anything following a solitary -- on the command line 
will be passed to the application [2], so you probably want 
something like this:


dub test -- --DRT-gcopt=profile:1

[1] https://dlang.org/spec/garbage.html#gc_config
[2] https://dub.pm/commandline


Re: Reading .pem files for secured

2019-05-31 Thread Dukc via Digitalmars-d-learn

On Friday, 31 May 2019 at 11:09:07 UTC, KnightMare wrote:
The reason is that if I understand the logic of Base64, it's 
that each character stores 6 bits. My private key .pem has 49 
lines of 64 characters worth of Base64, though the sat line 
isn't full. Anyway, this is data worth of over 18000 bits. The 
RSA key is supposed to be 4096 bits, so this can't be correct.


What am I missing?


PEM is a X.509 certificate (whose structure is defined using 
ASN.1), encoded using the ASN.1 DER (distinguished encoding 
rules), then run through Base64 encoding and stuck between 
plain-text anchor lines (BEGIN CERTIFICATE and END CERTIFICATE).


Ouch. I quess I have to translate the file into something that 
doesn't contain any certification cruft I don't use. Back to 
reading OpenSSL manual...


Thanks for the info.


Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Andre Pany via Digitalmars-d-learn

On Friday, 31 May 2019 at 13:37:05 UTC, Anonymouse wrote:

On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:


What is the correct way?


--DRT flags are for run time, not compile time. They're 
intended to be passed to your executable and not the compiler. 
From the docs [1]:


"By default, GC options can only be passed on the command line 
of the program to run"


My use-case is limiting the amount of memory dmd will allocate 
before -lowmem kicks in and collects (by use of 
--DRT-gcopt=heapSizeFactor on dmd), to accomodate for limited 
available memory. As pasted in the original post I seem to be 
able to do this manually.


So there is no way to set up a dub build configuration that 
automates this?


You can specify the parameters also in code. See example here

https://dlang.org/changelog/2.085.0.html#gc_cleanup

Kind regards
Andre


[dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Anonymouse via Digitalmars-d-learn
I'm trying to tweak the GC when compiling with dub, starting with 
something easy like profile:1.



$ grep dflags dub.json
"dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],
$ dub test


Doesn't work, doesn't give any extra output. Entering bogus flags 
like --DRT-gcopt=banana:1 doesn't evoke any error message either, 
making me doubt it's being passed on at all.



$ dmd -oftest -lowmem --DRT-gcopt=profile:1 source/**/*.d
Number of collections:  13
Total GC prep time:  7 milliseconds
Total mark time:  2110 milliseconds
Total sweep time:  270 milliseconds
Total page recovery time:  204 milliseconds
Max Pause Time:  472 milliseconds
Grand total GC time:  2592 milliseconds
GC summary: 1099 MB,   13 GC 2592 ms, Pauses 2117 ms <  472 ms


Manual dmd invocation does work, so it's not like dmd is ignoring 
--DRT-gcopt.



$ dub test --DRT-gcopt=profile:1
[...]
Number of collections:  10
Total GC prep time:  0 milliseconds
Total mark time:  4 milliseconds
Total sweep time:  7 milliseconds
Total page recovery time:  4 milliseconds
Max Pause Time:  0 milliseconds
Grand total GC time:  15 milliseconds
GC summary:   12 MB,   10 GC   15 ms, Pauses4 ms <0 ms


The totals should be in the ballpark of 1Gb+ (as above), not 
12Mb. Is it only profiling dub itself? (Incidentally this is 
roughly what dmd reports if called without -lowmem.)



$ export DRT_GCOPT=profile:1
$ dub test


Doesn't work either, I can't actually get the env var to affect 
dmd at all, even when manually running it.


What is the correct way?


Re: Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn

On Friday, 31 May 2019 at 11:20:15 UTC, KnightMare wrote:

whats wrong with answer at SO?
https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang


dlang_wrapper.so file is created.

I try to access it with following file:

import imebra;
import imebra_im;

import core.stdc.stdio;
import core.stdc.stdlib;
import core.sys.posix.dlfcn;

extern (C) int ldl();

void main(){
//auto loadedDataSet = CodecFactory.load("33141578.dcm") ;
printf("+main()\n");

void* lh = dlopen("libdlang_wrapper.so", RTLD_LAZY);
if (!lh)   {
fprintf(stderr, "dlopen error: %s\n", dlerror());
exit(1);
}
printf("libdlang_wrapper.so is loaded\n");
}


But it gives following error:

$ rdmd rntestImebra.d
imebra.d(457): Error: function declaration without return type. 
(Note that constructors are always named this)

imebra.d(457): Error: found data when expecting )
imebra.d(457): Error: semicolon expected following function 
declaration

imebra.d(457): Error: declaration expected, not ,
imebra.d(459): Error: no identifier for declarator _a
imebra.d(459): Error: declaration expected, not =
imebra.d(460): Error: no identifier for declarator _b
imebra.d(460): Error: declaration expected, not =
imebra.d(464): Error: function declaration without return type. 
(Note that constructors are always named this)
imebra.d(731): Error: function declaration without return type. 
(Note that constructors are always named this)

imebra.d(731): Error: found other when expecting )
imebra.d(731): Error: semicolon expected following function 
declaration

imebra.d(731): Error: declaration expected, not )
imebra.d(733): Error: declaration expected, not if
imebra.d(734): Error: unrecognized declaration
imebra_im.d(51): Error: module `string` is in file 
'std/c/string.d' which cannot be read

import path[0] = .
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: ["/usr/bin/dmd", "-v", "-o-", "rntestImebra.d", "-I."]

Line 457 of part of this code:

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   //  
line 457

  _outer = data;
  _a = a;
  _b = b;
}



Re: Reading .pem files for secured

2019-05-31 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Friday, 31 May 2019 at 10:35:46 UTC, Dukc wrote:
The key pair needs to be persistant between, so I made a 
4096-bit private key with OpenSSL, stored in .pem file. Then I 
constructed a public key from the private one, again with 
OpenSSL. It seemed strange to me that I could generate a public 
key afterwards with the private key, instead of having to do 
both at the same time. I just thought that perhaps crypto is 
somehow cryptic enough to do that.


The public key can always be constructed from the private key.

But then came a problem that I need to feed the key from .pem 
to initialize RSA class.


Just base64 decode the PEM data (without the ) and feed it to 
RSA.this(ubyte[] publicKey). Ought to be that simple.


Disclaimer: I have only used openssl directly. No experience with 
SecureD.


Re: Reading .pem files for secured

2019-05-31 Thread KnightMare via Digitalmars-d-learn
The reason is that if I understand the logic of Base64, it's 
that each character stores 6 bits. My private key .pem has 49 
lines of 64 characters worth of Base64, though the sat line 
isn't full. Anyway, this is data worth of over 18000 bits. The 
RSA key is supposed to be 4096 bits, so this can't be correct.


What am I missing?


PEM is a X.509 certificate (whose structure is defined using 
ASN.1), encoded using the ASN.1 DER (distinguished encoding 
rules), then run through Base64 encoding and stuck between 
plain-text anchor lines (BEGIN CERTIFICATE and END CERTIFICATE).


Re: How to create a template class using foreach delegate to filter objects in a member function call?

2019-05-31 Thread Alex via Digitalmars-d-learn

On Thursday, 30 May 2019 at 18:34:31 UTC, Robert M. Münch wrote:
I have myClass and I want to add a way where I can provide a 
delegate to iterate over myClass.objects when a member function 
put(...) of myClass is called. The idea is that a user of 
myClass can provide something like an "iterator filter" so that 
the function is only called on a subset of myClass.objects.



myClass(E){
myOtherClass!E objects;

void put(E obj) {
.put(objects, obj);
}

void put(T)(E obj, T filter) {
foreach(o ; filter!E(objects)){
.put(o, obj);
}
}
}

struct myFilter {
myOtherClass!E object;

opApply(int delegate(E) foreach_body) const {
if(mytestfunc(object))
return(foreach_body(object));
}
}

But I'm struggeling how to write all this down with tempaltes, 
because E is not known in myFilter. But the filter code needs 
to be aware of the template type if myClass. I hope the idea 
want to do is understandable.


Not sure, if I understood your problem correctly. It is meant 
that the class myClass defines an array of myOtherClass objects? 
The code does not compile and it does not provide an example, how 
you would apply the pattern, even in a non-compileable way... 
However,


commonly, a filter is a higher order function, which expects a 
predicate acting on each element of a set. Even if it's higher 
order, it is still a function, not a delegate. Therefore, it is 
unexpected, that you want to store something inside the filter.


Said this, I for myself had a similar problem. I solved this by 
reversing the hierarchy:
I templated my objects I wanted to use the filter on with the 
filter function and removed the need of the template parameter 
inside the filter.
You could still write a general filter function in this case, if 
you want. For example, you could use mixins for this...

As I said... not sure if this is of any help for you...


Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn
Is it possible to read Dicom (https://en.wikipedia.org/wiki/DICOM 
) images (which are widely used in medical field) using D 
language?


Dicom specifications are given here: 
https://www.dicomstandard.org/current/


There is some discussion on this topic on this page but no 
details on this forum: 
https://forum.dlang.org/post/fsjefp$10sp$1...@digitalmars.com


I do not think there are any specific d library for this purpose 
but there are many C libraries available, e.g. :


https://dicom.offis.de/dcmtk.php.en

and

https://github.com/dgobbi/vtk-dicom

There is some discussion here on using C for reading Dicom files 
on [this forum][3].


Can one of these libraries be used to read Dicom images in D 
language?


PS: Sample Dicom images are available here: 
https://www.dicomlibrary.com/


Wrapper for Imebra has been suggested here 
(https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang ) but it is not working.


Re: Reading .pem files for secured

2019-05-31 Thread KnightMare via Digitalmars-d-learn

https://lapo.it/asn1js
but dont insert ur certificate there, generate new one for tests



Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Anonymouse via Digitalmars-d-learn

On Friday, 31 May 2019 at 13:50:57 UTC, Andre Pany wrote:

You can specify the parameters also in code. See example here

https://dlang.org/changelog/2.085.0.html#gc_cleanup


I need it to apply to dmd though, I'm exceeding memory limits 
when compiling. Once done the program doesn't need a whole lot of 
it, but dmd -lowmem does.


Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread Anonymouse via Digitalmars-d-learn

On Friday, 31 May 2019 at 15:31:13 UTC, kinke wrote:

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

$ grep dflags dub.json
"dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],


This should work indeed. I guess it doesn't because dub 
probably uses a response file containing all cmdline options, 
whereas -lowmem definitely [and --DRT-* probably] need to be 
direct cmdline args.


Is this something I can/should report? (Where do dub issues go?)


Re: emulate with

2019-05-31 Thread Amex via Digitalmars-d-learn

On Friday, 31 May 2019 at 08:35:23 UTC, Simen Kjærås wrote:

On Friday, 31 May 2019 at 07:17:22 UTC, Amex wrote:
What I'm talking about is that if A would be dispatched to, 
say, W!X where W handles the special dispatching by returning 
X_A rather than X.A.



I don't know if D can do this kinda stuff even though it would 
be rather simple as it would depend on with.


Of course D can! However, it's not really pretty, and I think I 
found a bug in the process.


This is my code that compiles and runs:

void X_A(int i) {}
void X_A(string s) {}
void X_B(int i) {}
void X_C_Q(int i) {}

unittest {
with (Dispatcher.X!({})) {
A(1);
A("a");
B(2);
C_Q(3);
}
}

template getMethod(alias x, string name) {
static if (__traits(hasMember, x, name)) {
alias getMethod = __traits(getMember, x, name);
} else static if (x.stringof[0..7] == "module ") {
import std.meta : AliasSeq;
alias getMethod = AliasSeq!();
} else {
alias getMethod = getMethod!(__traits(parent, x), name);
}
}

struct Dispatcher {
template opDispatch(string prefix) {
static auto opDispatch(alias context)() {
struct WithObject {
auto opDispatch(string name, A...)(A a) {
struct OverloadCaller {
auto opCall(Args...)(Args args) {
return getMethod!(context, 
prefix~"_"~name)(args);

}
}
OverloadCaller result;
return result;
}
}
return WithObject();
}
}
}

So, the ugly:

1) Instead of just Dispatcher.X, we need to give Dispatcher a 
context from where to look for X_. That's the curly 
brackets in Dispatcher.X!({}).


2) The bug I mentioned. The whole OverloadCaller deal is a 
silly workaround for WithObject's opDispatch not being called 
correctly by DMD. That's also why WithObject's opDispatch takes 
(A...)(A a). I'll be filing this, of course.


3) with doesn't correctly handle static opDispatch. I'll be 
filing a bug for that as well.


We could fix 1) by introducing a new magic identifier - 
something like __CONTEXT__, which would work somewhat like 
__FUNCTION__, but be useful for reflection with __traits. I've 
played a little with this idea, but I'm not ready to make a PR 
with it.


With 1), 2) and 3) fixed, the code would look like this (only 
changed code included):


unittest {
with (Dispatcher.X) {
A(1);
A("a");
B(2);
C_Q(3);
}
}

struct Dispatcher {
struct opDispatch(string prefix, alias context = 
__CONTEXT__) {
static auto opDispatch(string name, Args...)(Args args) 
{

 return getMethod!(context, prefix~"_"~name)(args);
}
}
}

I think that's kinda neat, TBH.

--
  Simen



Thanks, I haven't messed with it but it by your examples it 
should do what I want...


I actually probably need the use of .'s turned in to _'s... so I 
can write stuff like


A.B.C.D and it all goes to X.A_B_C_D.

I'm not sure if A.B.C.D would get dispatched as a whole or just 
in part though(e.g., is it treated as A.(B.(C.D)) or (A.B).C).D 
or A.B.C.D) which would require some type of chaining dispatcher 
I guess).


In any case it helps with my specific problem. I like the idea of 
_CONTEXT_ and it might be usable in other areas.


Thanks.


Re: How to create a template class using foreach delegate to filter objects in a member function call?

2019-05-31 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-05-31 11:07:00 +, Alex said:


Not sure, if I understood your problem correctly.


I can imagine... I try my best :-)


It is meant that the class myClass defines an array of myOtherClass objects?


Yes. So there is one class having an array of other stuff.

The code does not compile and it does not provide an example, how you 
would apply the pattern, even in a non-compileable way...


The code is just to show the problem and not meant to compile. I 
couldn't get anything to compile...


However, commonly, a filter is a higher order function, which expects a 
predicate acting on each element of a set. Even if it's higher order, 
it is still a function, not a delegate. Therefore, it is unexpected, 
that you want to store something inside the filter.


I choose filter to give a hint what the idea is, not meant to be that I 
want to use a filter.


Said this, I for myself had a similar problem. I solved this by 
reversing the hierarchy: I templated my objects I wanted to use the 
filter on with the filter function and removed the need of the template 
parameter inside the filter.


The thing is, myClass is not under my control. It's coming from a 
library I don't maintain and I don't want to mess around with the code 
or if, as minimalistic as possible. That's why I was thinking about 
providing a put(T)... function.


My first idea was to sub-class myClass, but objects is private, so no 
chance to get access to it.


You could still write a general filter function in this case, if you 
want. For example, you could use mixins for this...


Then myClass needs to somehow get the mixin in.

So, to summurize the problem: Given a class that manages an array of 
things as an OutputRange how can I provide a put() function with 
something like a filter-predicate? I only want to put() to some of the 
things, not all.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: [dub] Passing --DRT-gcopt to dmd

2019-05-31 Thread kinke via Digitalmars-d-learn

On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

$ grep dflags dub.json
"dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],


This should work indeed. I guess it doesn't because dub probably 
uses a response file containing all cmdline options, whereas 
-lowmem definitely [and --DRT-* probably] need to be direct 
cmdline args.


Re: Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn

On Friday, 31 May 2019 at 13:49:02 UTC, KnightMare wrote:

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   // 
 line 457

  _outer = data;
  _a = a;
  _b = b;
}


imo problem is in string
private __vector(ushort)_outer;
it looks like template(vector!ushort) or function or this is 
vector from core.simd

and replacing it to private long _outer; fix the problem
paste code imebra.d and imebra_im.d to someplace


Best to download it from https://imebra.com/get-it/ so that all 
files are available to you.




How to create GTK+ apps with Glade and D on windows

2019-05-31 Thread Obsidian Jackal via Digitalmars-d-learn
I'm new to D and want to create GTK+ apps. I have Visual Studio, 
Glade, the Gtk+ runtime, DMD, and DUB installed. What steps, 
guides, or advice should I follow to be able to be able to use 
these tools together to make a sane app?.


get executable version

2019-05-31 Thread Machine Code via Digitalmars-d-learn
is there something on std library or package on dub to get a 
executable version on windows? just in case I don't need to dig 
into winapi.


Like C#'s:

FileVersionInfo.GetVersionInfo(path).FileVersion

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.fileversioninfo.fileversion?view=netframework-4.8


Re: get executable version

2019-05-31 Thread rikki cattermole via Digitalmars-d-learn

On 01/06/2019 7:07 AM, Machine Code wrote:
is there something on std library or package on dub to get a executable 
version on windows? just in case I don't need to dig into winapi.


Like C#'s:

FileVersionInfo.GetVersionInfo(path).FileVersion

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.fileversioninfo.fileversion?view=netframework-4.8 



You'll need to go to WinAPI.

Here is a jumping off point[0] and yes we have bindings for it[1] 
(although missing the Ex versions).


[0] 
https://docs.microsoft.com/en-us/windows/desktop/api/winver/nf-winver-getfileversioninfow
[1] 
https://github.com/dlang/druntime/blob/8fd52019826259dc92ab712f4b37a3f0ea4d8265/src/core/sys/windows/winver.d


Re: How to create GTK+ apps with Glade and D on windows

2019-05-31 Thread Ron Tarrant via Digitalmars-d-learn

On Friday, 31 May 2019 at 18:47:06 UTC, Obsidian Jackal wrote:
I'm new to D and want to create GTK+ apps. I have Visual 
Studio, Glade, the Gtk+ runtime, DMD, and DUB installed. What 
steps, guides, or advice should I follow to be able to be able 
to use these tools together to make a sane app?.


If you aren't opposed to reading about hand-coding techniques: 
http://GtkDcoding.com


Re: How to create GTK+ apps with Glade and D on windows

2019-05-31 Thread Aphex via Digitalmars-d-learn

On Friday, 31 May 2019 at 18:47:06 UTC, Obsidian Jackal wrote:
I'm new to D and want to create GTK+ apps. I have Visual 
Studio, Glade, the Gtk+ runtime, DMD, and DUB installed. What 
steps, guides, or advice should I follow to be able to be able 
to use these tools together to make a sane app?.


I wrote some D code that parses a glade interface file and 
converts it in to easily accessible D code.


You use the ID field in glade to specify the D object name.

Go to github's gtkD to find a reference to it in issues. It's not 
perfect and might require a little work figuring it out but it 
works out nice once you get it set up.


It's basically used like

class App : GtkBase!("Interface.Glade")
{
...
}

and then App will have all the objects ID's as objects.

e.g., if you have a label in the glade interface with ID label, 
then


App.label

is the gtkD object for that label.



Re: get executable version

2019-05-31 Thread Machine Code via Digitalmars-d-learn

On Friday, 31 May 2019 at 19:22:03 UTC, rikki cattermole wrote:

On 01/06/2019 7:07 AM, Machine Code wrote:
is there something on std library or package on dub to get a 
executable version on windows? just in case I don't need to 
dig into winapi.


Like C#'s:

FileVersionInfo.GetVersionInfo(path).FileVersion

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.fileversioninfo.fileversion?view=netframework-4.8



You'll need to go to WinAPI.

Here is a jumping off point[0] and yes we have bindings for 
it[1] (although missing the Ex versions).


[0] 
https://docs.microsoft.com/en-us/windows/desktop/api/winver/nf-winver-getfileversioninfow
[1] 
https://github.com/dlang/druntime/blob/8fd52019826259dc92ab712f4b37a3f0ea4d8265/src/core/sys/windows/winver.d


Thanks I wrote this D version, if anyone is interested or would 
like to point out any mistake/improvement:


string getFileVersionString(string filename)
{
import  core.sys.windows.windows :
MAX_PATH;
import core.sys.windows.winbase :
GetModuleFileName;
import core.sys.windows.windef :
DWORD, UINT, LPBYTE, NULL,
LPSTR, TCHAR;
import core.sys.windows.winver :
GetFileVersionInfoSize,
GetFileVersionInfo,
VerQueryValue,
VS_FIXEDFILEINFO;
import std.windows.syserror : wenforce;
import std.string : format;
import std.conv : wtext;
import std.traits : fullyQualifiedName;

wchar* szVersionFile = cast(wchar*)filename.wtext.ptr;
DWORD verHandle = 0;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize =
wenforce(GetFileVersionInfoSize(szVersionFile,

),
fullyQualifiedName!GetFileVersionInfoSize ~ " failed");
wchar[] verData = new wchar[verSize];
wenforce(GetFileVersionInfo(szVersionFile,
verHandle,
verSize,
verData.ptr),
 fullyQualifiedName!GetFileVersionInfo ~ " faield");
if(!VerQueryValue(cast(const(void)*)verData.ptr,
  cast(const(wchar)*)"\\".ptr,
  cast(void**),
  )) {
assert(0, fullyQualifiedName!VerQueryValue ~ " failed");
}
if(!size) {
assert(0, "no size");
}
auto verInfo = cast(VS_FIXEDFILEINFO*)lpBuffer;
if (verInfo.dwSignature == 0xfeef04bd) {
return format!"%d.%d.%d.%d"(
   (verInfo.dwFileVersionMS >> 16 ) & 0x,
   (verInfo.dwFileVersionMS >>  0 ) & 0x,
   (verInfo.dwFileVersionLS >> 16 ) & 0x,
   (verInfo.dwFileVersionLS >>  0 ) & 0x
);
}
return "";
}


Calling copyctor manually

2019-05-31 Thread SrMordred via Digitalmars-d-learn

Its possible to call copyctor manually without calling dtor?

ex, what i did before:

struct T{ ~this(){ writeln("DTOR"); } this(this){ 
writeln("POSTBLIT"); } }


T a;
T b;

memcpy(,,T.sizeof);
a.__postblit;

/*
output:
POSTBLIT
DTOR
DTOR
*/

With copy ctors, not sure what to do.


struct T{
~this(){ writeln("DTOR"); }   
this(ref return scope T self){ writeln("COPYCTOR"); } }

T a;
T b;

memcpy(,,T.sizeof);
a.opAssign(b); //???
//same as a = b;

/*
output:
COPYCTOR
DTOR
DTOR
DTOR
*/

I want something like '.__xcopyctor'


'version'-based code selection

2019-05-31 Thread Yatheendra via Digitalmars-d-learn



Hi people.

The 'version' keyword sounds like a fantastic capability, but how 
far does DMD take it (and does GDC take it equally far)? This is 
not a "D Improvement Proposal", I am just asking how it is now.


Can code of multiple versions be compiled into the same 
executable or library, and a particular one selected from 
"later"? I guess not without some name mangling and wrangling.


Can such selection be done at link-time for standard as well as 
user-defined library code? Maybe some library file naming 
conventions are followed to allow the compiler to select the 
corresponding file?


Wishful thinking, but can the selection be at runtime? That would 
be language support for making some things easy, e.g. picking 
from assembly-coded routines based on runtime CPU id (the video 
player MPlayer picks routines that way, and I read that the D 
library, Mir, has CPU id support).


Thanks.

P.S: I am a brand-new C++'y asylum seeker who may have missed 
seeing some documentation, so RTFM is a valid response.


P.P.S: This question was triggered by the D GSoC project for 
independent-of-C implementations of malloc/free/memcpy/memset. 
Could a common malloc be exposed to the D 
runtime/Phobos/programs, with the C or D implementations 
selectable at link-time (using a mechanism available to user code 
too)?


Re: How to create a template class using foreach delegate to filter objects in a member function call?

2019-05-31 Thread Alex via Digitalmars-d-learn

On Friday, 31 May 2019 at 16:24:28 UTC, Robert M. Münch wrote:
The code is just to show the problem and not meant to compile. 
I couldn't get anything to compile...


That's ok, but could you provide an example anyway? Is it like 
this?


´´´
void main(){
auto target = new myClass!int();
target.objects.length = 4;
auto val = 42;
put(target, val, testfunction); // does the test function 
enters here?

put(target, val);
auto f = myFilter!int; // where do you want to use this 
entity?

}
´´´

Said this, I for myself had a similar problem. I solved this 
by reversing the hierarchy: I templated my objects I wanted to 
use the filter on with the filter function and removed the 
need of the template parameter inside the filter.


The thing is, myClass is not under my control. It's coming from 
a library I don't maintain and I don't want to mess around with 
the code or if, as minimalistic as possible. That's why I was 
thinking about providing a put(T)... function.


*



My first idea was to sub-class myClass, but objects is private, 
so no chance to get access to it.


You could still write a general filter function in this case, 
if you want. For example, you could use mixins for this...


Then myClass needs to somehow get the mixin in.

So, to summarize the problem: Given a class that manages an 
array of things as an OutputRange how can I provide a put() 
function with something like a filter-predicate? I only want to 
put() to some of the things, not all.


Do you have control about the contained classes? If so, it is a 
hint to implement the testing inside them. Like:


/* probably inside a templated mixin */
bool testfunction(inputs){...}

class myOtherClass(/*probably templated*/){... mixin testfunction 
... & provide a put function}


* So, you are not totally against the idea of modifying the 
foreign library, but you want to keep modifications small? With 
the approach now, you could, for example, handle compile time 
blocks inside the put function in the myClass and dynamical ones 
inside the myOtherClasses.


class myClass(E){/* inserted put function */ void put(...){static 
if put action is at all possible --> put. }}


Re: 'version'-based code selection

2019-05-31 Thread rikki cattermole via Digitalmars-d-learn

On 01/06/2019 3:59 PM, Yatheendra wrote:


Hi people.

The 'version' keyword sounds like a fantastic capability, but how far 
does DMD take it (and does GDC take it equally far)? This is not a "D 
Improvement Proposal", I am just asking how it is now.


GDC, LDC and DMD all share the same frontend from DMD.

Can code of multiple versions be compiled into the same executable or 
library, and a particular one selected from "later"? I guess not without 
some name mangling and wrangling.


It is not supported.

Think #ifdef and you should get a basic understanding of its scope.