digitalmars.D.learn - Question Object.factory and namespaces.
- dcoder (17/17) Apr 12 2012 Hello.
- Justin Whear (5/8) Apr 12 2012 Check out packageName, moduleName, and fullyQualifiedName in std.traits....
- dcoder (19/30) Apr 12 2012 Thanks for this info. I tried it but I'm still getting some
- Justin Whear (2/6) Apr 12 2012 Yeah, I think those templates were added in the last release or two. The...
Hello. I am reading through TDPL by Andresscu. The book has the following example, which I am abbreviating: void main( string[] args) { Stat [] stats; foreach( arg; args[1..$]) { auto newStat = cast(Stat) Object.factory( "statsinc04." ~ arg); enforce( newStat, "Invalid statistical function: " ~ arg); stats ~= newStat; } My module is called statsinc04.d and you can see it listed above in the foreach loop. My question is, how do I change the code above so that it works even if I change the name of the file/module? I'm looking for clean solution something like a macro if one actually exists. Thanks.
Apr 12 2012
On Thu, 12 Apr 2012 16:11:11 +0200, dcoder wrote:My question is, how do I change the code above so that it works even if I change the name of the file/module? I'm looking for clean solution something like a macro if one actually exists.Check out packageName, moduleName, and fullyQualifiedName in std.traits. Additionally, the __FILE__ token will be expanded to the name of the current file. Justin
Apr 12 2012
On Thursday, 12 April 2012 at 15:36:25 UTC, Justin Whear wrote:On Thu, 12 Apr 2012 16:11:11 +0200, dcoder wrote:Thanks for this info. I tried it but I'm still getting some problems. Here's what I have for code: /* traits.d */ import std.stdio, std.traits; void main() { writefln( "moduleName = %s ", moduleName!(main)); return; } When I try to compile this, I get the following error: traits.d(7): Error: undefined identifier moduleName Could it be my compiler version? Here's what I have: $ dmd DMD32 D Compiler v2.055 By the way, I am doing this in cygwin, I don't know if that matters. thanksMy question is, how do I change the code above so that it works even if I change the name of the file/module? I'm looking for clean solution something like a macro if one actually exists.Check out packageName, moduleName, and fullyQualifiedName in std.traits. Additionally, the __FILE__ token will be expanded to the name of the current file. Justin
Apr 12 2012
Could it be my compiler version? Here's what I have: $ dmd DMD32 D Compiler v2.055Yeah, I think those templates were added in the last release or two. The current version is 2.058 (and 2.059 is in beta).
Apr 12 2012