I am working a reflection / introspection library (dynamic / at runtime, as
opposed to compile time with template and mixin).
Now I can create PropertyInfo classes for property with very little code
and it all works well.
I'm hitting a problem, trying to register all property of my class
Hey Adam! Thanks again for your web.d!
My introspection class went along quite well, thanks in no small part to
you! ;)
implementing INotifyPropertyChanged now and .. data binding next! :)
Adam Ruppe wrote in message news:itnfqc$kg2$1...@digitalmars.com...
Indeed, this would be nice. I
I am creating a struct that I want to use as dictionary (associative array)
key
Initially it was a class and I overrode toHash and opCmp.
I just made it a struct to be more lightweight on the system, but can't
override toHash anymore!
How can I make it a good dictionary key?
Here is the
Never mind, just found it!
http://www.digitalmars.com/d/2.0/hash-map.html
the following code seem problematic to compile...
import std.algorithm;
private alias void delegate(int, int) SlotDelegate;
class A
{
void DIT(int a, int b)
{
}
}
int main(string[] argv)
{
A a;
SlotDelegate x= a.DIT;
SlotDelegate[] _slotDg;
_slotDg.remove(x);
There is a remove() method in std.algorithm!I even got asked why I was
reimplementing it!
(well, because I didn't know it existed hey!)
works fine with, say, int...
but not with delegate!
associative array will solve the problem indeed.. (I hope) but they use way
more memory!
it would be
Doost : http://www.dsource.org/projects/doost
Has a serializer that can read value to and from JSon! ;)
Johannes Pfau wrote in message
news:20110619193834.2c6afdf7@jpf-Satellite-A100...
std.json doesn't work at all because of bug #2962 . I tried to remove
the problematic part from std.json
That simple hey?!?
Awesome!
You are a week-end saver! :)
Mike Wey wrote in message news:ithv61$2j5t$1...@digitalmars.com...
bool isTypeOf(T)(TypeInfo ti)
{
return ( typeid(T) is ti );
}
bool isTypeOf(TypeInfo ti1, TypeInfo ti2)
{
return ( ti1 is ti2 );
}
--
Mike Wey
, Lloyd Dupont wrote:
ho... easy hey!
but how about the other 2 test I'd like be able to run?
bool isTypeOf(T)(TypeInfo ti) { return T is ti }
bool isTypeOf(TypeInfo ti1, TypeInfo ti2) { return ti1 is ti2 }
bool isTypeOf(T)(TypeInfo ti)
{
return ( typeid(T) is ti );
}
bool isTypeOf(TypeInfo
It helped! it's working now! :)
Thanks!
Jesse Phillips wrote in message news:itgg6i$2tf3$1...@digitalmars.com...
Lloyd Dupont Wrote:
Hi Jesse, this won't work!
It's my fault in not explaining my problem well though...
I forget to mention something...
I'm using property syntax and try
given
A a =
class A {}
class B : A {}
how could I test, at runtime, if a is just a A or is a B?
also, give a type T and a TypeInfo variable, how can I know if a variable of
type T is attributable to a variable of type described by TypeInfo?
i.e. how could I implement the method
...
On 2011-06-17 19:58, Lloyd Dupont wrote:
given
A a =
class A {}
class B : A {}
how could I test, at runtime, if a is just a A or is a B?
Cast it. The result will be null if the cast fails.
if(cast(B)a)
//it's a B
else
//it's an A but not a B
- Jonathan M Davis
I'm working a small but reasonably interesting D project which I'd like to,
ultimately, open source.
To make it attractive I need to document my class.
Is there anything remotely like Javadoc which works with D?
Thanks bearophile!
bearophile wrote in message news:itcs1k$1l8t$1...@digitalmars.com...
Lloyd Dupont:
I'm working a small but reasonably interesting D project which I'd like
to,
ultimately, open source.
To make it attractive I need to document my class.
Is there anything remotely like
I'm trying to build an introspection system for a project I have.
I already have a working template to get members value
=== working members getter ===
Variant GETTER(T, string member)(Object target)
{
T tt = cast(T)target;
if (!tt)
throw new ReflectionException(target is null or not
work with typeinfo!! :)
=
void SETTER(T, string member)(Object target, Variant value)
{
T tt = cast(T)target;
if (!tt)
throw new ReflectionException(target is null or not ~T.stringof
~ value: ~target.toString());
if(!value.convertsTo!( typeof(__traits(getMember, T,
)) ))
throw new ReflectionException(Can't convert ~value.stringof ~ to
~typeof(__traits(getMember, T, member)).stringof);
__traits(getMember, tt, member) = value.coerce!(
typeof(__traits(getMember, T, member)) );
}
Lloyd Dupont wrote in message news:itcthc$1onk$1...@digitalmars.com
I have 2 overload of the opCall() in one of my class.
They cause a compile time error / conflict... any idea on how to solve it?
=
class MemberDesc
{
Variant opCall(Object target)
{
return getter(target);
}
void opCall(T)(Object target, T value)
{
setter(target,
Ho thanks, even better than the work around I just found! :)
David Nadlinger wrote in message news:itcvbj$1td2$1...@digitalmars.com...
Add a pair of parentheses to the first overload to add an empty template
argument list – currently, template and non-template functions can't be
overloaded.
I have a MemberDesc class which describe a class's members.
I fill it with a template method like that (with GETTER and SETTER some
other templated method I wrote)
=
MemberDesc MEMBER(T, string memberName)()
{
TypeInfo ti = typeid( typeof(__traits(getMember, T, memberName)) );
,
memberName))
{
...
}
Lloyd Dupont Wrote:
I have a MemberDesc class which describe a class's members.
I fill it with a template method like that (with GETTER and SETTER some
other templated method I wrote)
=
MemberDesc MEMBER(T, string memberName)()
{
TypeInfo ti = typeid( typeof(__traits
Thanks for that! It'll need some digesting... but it's already giving me
some idea! :)
Adam D. Ruppe wrote in message news:it7rlo$2ql3$1...@digitalmars.com...
While my code is ugly as sin, it might be useful to look at the
prepareReflection function in my web.d
Yes indeed, I'm using Visual D
Ho... good to know, thanks! :)
mm.. well hopefully it'll be fixed in the next release...
and I should pay a close look at the build script!
Johann MacDonagh wrote in message news:itbp22$28l2$1...@digitalmars.com...
On 6/15/2011 5:32 PM, Jos van Uden wrote:
Too late! :P
I have been inspired by the simplicity of D and DGui.
Never happened before with earlier C++ experiments... my loss!
Jose Armando Garcia wrote in message
news:mailman.906.1308016642.14074.digitalmars-d-le...@puremagic.com...
On Mon, Jun 13, 2011 at 6:33 AM, Lloyd Dupont ld-rem
I'm writing some manual reflection (a bit more automatism will come later,
thanks to __traits and mixin)(hopefully)
There are a few problems with my implementation so far...
- First the implementation:
system.reflection.member.d =
module system.reflection.member;
public:
public enum
I have DMD2.053, on Windows.
I just moved my folder around.
I compile with the following command line:
==
dmd -lib -g -unittest -debug -w -wi -X -XfDebug\dinstall.json -ofDebug\dinstall.lib
-deps=Debug\dinstall.dep -map Debug\dinstall.map -L/NOMAP
@Debug\dinstall.build.rsp
==
I got
Trying to play with introspection.
trying o, for a given object, to check its property by name.
Experimenting with the function below.
1. it doesn't compile! mi.name() seems to be a problem?
2. match is always null! even though I pass the name of an existing property
and / or field!
I see mm
Thanks for the info!
Jonathan M Davis wrote in message
news:mailman.866.1307943671.14074.digitalmars-d-le...@puremagic.com...
Object is not currently const-correct:
http://d.puremagic.com/issues/show_bug.cgi?id=1824
As a result, a number of basic functions do not currently
Let's learn together then! :P
http://galador.net/codeblog/?tag=/D
While my blog post are only about setting up the environment so far.. I have
delved in the code for 2 weeks now! (Although I had some day off (work and
programing) in Darwin) I'm right into it now, should have a new blog post
trying to learn introspection, I have this simple test method:
===
static void dumpelement(Object o)
{
if (!o)
return;
auto ci = o.classinfo;
foreach(mi ; ci.getMembers(null))
{
writefln(%s . %s, ci.name, mi.name());
}
}
==
However
I'm trying to create 2 extra method for arrays (range would be better,
though I don't quite understand what is a range)
Although I have some indecipherable (to me) compiler error...
What's wrong with the code below?
==
import std.algorithm;
public:
void remove(T)(ref T[]
(didn't see any assignment...)
Anyway of ... making the runtime update xgetMembers?
Johannes Pfau wrote in message
news:20110613140030.70c8d27b@jpf-Satellite-A100...
Lloyd Dupont wrote:
trying to learn introspection, I have this simple test method:
===
static void
removed some obvious error, still stumped on the templated syntax ...
so.. why is it not compiling?
(error:
Error: template std.algorithm.countUntil(alias pred = a == b,R1,R2) if
(is(typeof(startsWith!(pred)(haystack,needle does not match any function
template declaration
)
=
import
ho.. plenty of silly mistake indeed.. thanks for spotting them!
(maybe I should take a break and play the witcher 2 hey!?!? :)
however I still have a problem with removeAt now! :(
===
void removeAt(T)(ref T[] array, int index)
{
if(index 0 || index = array.length)
return;
Thanks Robert!
Mm.. can you (per chance!) share some code?
I'm a newbie and compile time reflection is something which eludes me (so
far...)!
Robert Clipsham wrote in message news:it4vp1$1n5q$1...@digitalmars.com...
Anyway of ... making the runtime update xgetMembers?
My understanding
Works a treat!
Thanks for your detailed sample! :)
Robert Clipsham wrote in message news:it5395$2028$1...@digitalmars.com...
See: http://www.digitalmars.com/d/2.0/traits.html
class MyClass
{
void method1(){}
void method2(){}
}
import std.stdio;
void main()
{
foreach
From the book I was under the impression that there could be user defined
attribute.
I wonder if this has been implemented?
My problem: I try to implement a simplistic DataContractSerializer (as in
Apparently std.string.format() is not implemented / does not compile! :(
Is there any sort of replacement?
Something which works like writefln() but output a string!
mm... ok.
but why the line below doesn't compile?
mixin(format(class %s {}, A));
bearophile wrote in message news:it2pf5$1qh6$1...@digitalmars.com...
Apparently std.string.format() is not implemented / does not compile! :(
This works for me, DMD 2.053:
I'm using 2.053
this compile fine:
enum : string
{
A = hello,
B = betty,
}
this doesn't!
enum AA : string
{
A = hello,
B = betty,
}
Am I missing something? Named enum can't be typed? known bug?
I have a method like that:
===
public string repeat(string s, int num)
{
string result = s;
for (int i=1; inum; i++)
result ~= s;
return result;
}
===
basically it will create num string, each a little longer...
is there a more efficient way to go about that?
thanks! :)
): Error: Integer constant expression expected instead of betty
=
Timon Gehr wrote in message news:it3k0u$15s6$1...@digitalmars.com...
Lloyd Dupont wrote:
I'm using 2.053
this compile fine:
enum : string
{
A = hello,
B = betty,
}
this doesn't!
enum AA : string
yep, the example is simple because it is an example!
Thanks for your suggestion! :)
Jonathan M Davis wrote in message
news:mailman.850.1307909499.14074.digitalmars-d-le...@puremagic.com...
On 2011-06-12 10:30, David Nadlinger wrote:
On 6/12/11 6:37 PM, Lloyd Dupont wrote:
mm... ok
But... string being immutable I don't see the point of allocating some space
for one..
Am I missing something?
Steven Schveighoffer wrote in message
news:op.vwy503w4eav7ka@localhost.localdomain...
On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont ld-rem...@galador.net
wrote:
I have
Thanks!
Jonathan M Davis wrote in message
news:mailman.851.1307909610.14074.digitalmars-d-
Also, std.string.repeat has been scheduled for deprecation. You should use
std.array.replicate instead. It does the same thing but for all arrays
instead
of just strings.
- Jonathan M Davis
Thanks Steven, that was very informative!
Steven Schveighoffer wrote in message
news:op.vwzrwdmteav7ka@localhost.localdomain...
On Sun, 12 Jun 2011 21:02:05 -0400, Lloyd Dupont ld-rem...@galador.net
wrote:
But... string being immutable I don't see the point of allocating some
space for one
I have problem with Object
for example this doesn't compile:
===
Object o;
o = ;
===
with error: cannot implicitly convert expression () of type string to
object.Object
or this also failed to compile:
===
class Foo
{
public:
Object foo, bar, snafu;
override const bool opEquals(Object
what if the Win32 function I'm interested in don't seem to be in .lib
provide by dmd...
(for example vista up windows function)
Can I just use the .lib which come from the windows SDK?
I did the following, what do you think of my implementation?
(checking if my string and array usage could be improved / powered
up!!!)
string[] _locales = [en-AU, fr-FR];
string getCurrentLocal() { return fr-BE; }
string[] getCandidates()
{
auto local = getCurrentLocal();
string
Thanks I'll try tomorrow! :)
(now I should really go to bed...)
Andrej Mitrovic wrote in message
news:mailman.565.1307117174.14074.digitalmars-d-le...@puremagic.com...
If you have coffimplib (which isn't free), then you could just convert
the windows sdk import lib to OMF format.
Otherwise,
std.algorithm!
will have a look, thanks!
bearophile wrote in message news:isb5ql$1i23$1...@digitalmars.com...
Lloyd Dupont:
I did the following, what do you think of my implementation?
Those for loops seem better as foreach ones, or even reverse foreach ones.
Probably in std.algorithm
Where can I find this implib tool you mentioned?
I have the latest Windows SDK and Visual Studio 2010. Yet when I perform a
search in program files I can't find it!!
:(
Andrej Mitrovic wrote in message
news:mailman.565.1307117174.14074.digitalmars-d-le...@puremagic.com...
If you have
Sweet, thanks you very much! :)
Andrej Mitrovic wrote in message
news:mailman.573.1307123755.14074.digitalmars-d-le...@puremagic.com...
http://ftp.digitalmars.com/bup.zip
Docs here:
http://www.digitalmars.com/ctg/implib.html
Yes and no!
On one hand I'm a fervent believer of all things Windows 7! :P
On the other hand my (learning) D project is about writing an installer.
Which should just work with no unexpected dependencies!
I was telling to myself earlier today too that I should not use this
function, just in
let say there is a .h in the windows SDK I'm interested in (namely msi.h),
is there a way to automatically translate it to a .d?
I think I read about such a thing once...
Thanks!
I'm trying to define an array of constant like:
===
immutable string[int] MyDict = [
1: monday,
2: tuesday,
];
And I keep having compiler error:
Error1Error: non-constant expression [1:monday,2:tuesday]
C:\Dev\DTest\DTest1\Dexperiment\LCIDs.d9
what can I do? how do
Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)
Anyhow I'm toying with a D learning project and there are 2 .NET feature
that will be welcome in this D project:
1. internationalization.
the app will contains a bunch of simple UIs and I was wondering how I would
go on
I'm on a windows PC in Australia
I'd like to get the string en-AU and en from Windows
How do I do that please?
_GetUserDefaultLocaleName@8
C:\Dev\DTest\DTest1\Dexperiment\
Any clues?
Lloyd Dupont wrote in message news:is5gm7$1a8u$1...@digitalmars.com...
I'm on a windows PC in Australia
I'd like to get the string en-AU and en from Windows
How do I do that please?
Thanks for the link hey! :)
Otherwise I still get the same linking error with the W :(
Andrej Mitrovic wrote in message
news:mailman.518.1306939098.14074.digitalmars-d-le...@puremagic.com...
From what I can tell you're using the wide version, so try prototyping
it as
Awesome! WIll take a look at it tonight!
Thanks for the link! :)
Jacob Carlborg wrote in message news:is5msf$1lt0$1...@digitalmars.com...
On 2011-06-01 14:51, Lloyd Dupont wrote:
Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)
Anyhow I'm toying with a D learning project
I'm looking!
mm... how do I download the repository!?! :~
Jacob Carlborg wrote in message news:is5msf$1lt0$1...@digitalmars.com...
For the serialization you could have a look at Orange:
http://www.dsource.org/projects/orange
Don't know if it works with the latest compilers, it's been a
Thanks for the quick answers hey!
Another quick one (it's time to go to work for me!)
Does this lib contains the MSI function?
Andrej Mitrovic wrote in message
news:mailman.518.1306939098.14074.digitalmars-d-le...@puremagic.com...
From what I can tell you're using the wide version, so try
Thanks, I'll have a look tonight!
Steven Schveighoffer wrote in message
news:op.vwezfbqmeav7ka@localhost.localdomain...
On Wed, 01 Jun 2011 16:13:44 -0400, Lloyd Dupont ld-rem...@galador.net
wrote:
Here is my new theory -- note that the function is only defined on Vista
or later. DMD does
!
===
Jesse Phillips wrote in message news:ir3pl3$1df4$1...@digitalmars.com...
Jesse Phillips Wrote:
Lloyd Dupont Wrote:
so I copied the Entice generated UI code in Visual D, and tried to
compile.
I got 1 error:
Error1Error: module all is in file 'dfl\all.d' which cannot be
read
C
Thanks Jesse!
Before I was in the dark! :( Now I'm in.. errr... dawn!
Simple questions and answers but it has clarified important stumbling
starting block for me! :)
Jesse Phillips wrote in message news:ir3imc$rhs$1...@digitalmars.com...
Lloyd Dupont Wrote:
1]. ok, I unzipped dmd.zip
1]. ok, I unzipped dmd.zip and dm.zip. what's this dm.zip for?
2]. I install Visual D, I had to point it to the DMD folder. And it did
compile my 1st D program fine... doubly wondering what's dm for?
3]. I try installed DFL. Actuall it unzipped in the worng forlder, so I
moved whateve in
so I copied the Entice generated UI code in Visual D, and tried to compile.
I got 1 error:
Error1Error: module all is in file 'dfl\all.d' which cannot be read
C:\Dev\DTest\DTest1\myform.d7
On
import dfl.all;
For info I do have dfl.all in
C:\D\dmd2\windows\import\dfl
68 matches
Mail list logo