Object.factory

DanO dsstruthers at nospamplease.yahoo.com
Wed Sep 26 08:30:00 PDT 2007


Sean Kelly Wrote:


> You will need to generate the code for any template you want to generate 
> via Object.factory by aliasing or instantiating it at compile-time. 
> Otherwise, the code won't even exist in your app.  This should do the trick:
> 
> alias MyDict!(int) GenerateMyDict_int;
> 
> 
> Sean

Just so everyone knows, all of the templates I am trying to dynamically create are declared and instantiated in the same module where they are defined, and all of the ones I am trying to instantiate are used somewhere in the module, usually as members of other classes.  I have tried every conceivable permutation of things to get it to work, but it just looks like those classes are not in the ModuleInfo.  Probably a compiler issue.

As a workaround, I have made up a mixin that registers a loader function with my SerializationManager class that it can fall back on if Object.factory() fails to locate a "factory" for the type.  It's kind of funky, but it works.

This approach, or any for that matter, relies on both sides of the serialization stream to have instantiated each version of the template in order for the serialization to work properly.

Normally that wouldn't be an issue, since two sides of a stream are usually running the same version of software, but in the case of serializing out to file, the reader could be anyone or any version.  I guess that's where serialization versioning comes in....

=DanO



More information about the Digitalmars-d mailing list