From: stephan b. <st...@s1...> - 2004-12-26 06:31:07
|
This is an interesting little feature: typedef Factory<MyType> F; F & f = F::instance(); f.registerFactory( "MyType", MyType::createNewInstance ); f.alias( "AnAlias", "MyType" ); MyType * m = f.create( "AnAlias" ); Since PluginManager extends Factory, we can do some more subtle tricks with it, like aliasing DLL names or simulating symlinks by aliasing /P/plugins/mypluginname to /real/path/to/mypluginname.so. Or alias http://path/to/s11n/data to ~/foo.s11n (or vice versa). Setting up a "virtual filesystem" to factories/DLLs this way might be really interesting to consider: /P/plugins, /P/devices, /P/protocols... That would require slighty different aliasing support (the current support is word-based, whereas /P/... effectively needs partial string search support). Anyway... There's *all kinds* of evil we can do with this. :) This has some nice benefits for code maintenance: we can use aliases in code and allow the user to re-map their own types to those aliases via config files and whatnot. For example, in client code we write: DocumentType * d = f.create( "default-document-class" ); The factory could expect "default-document-class" to come from the DocumentPluginManager, which reads ~/.myapprc (or equivalent) to get the info. For example, the user maps this in his configuration data: default-document-class = MySpecialDocType During plugin initialization, the DocumentPluginManager simply converts config info to: Factory<Document>.alias( default-document-class", "MySpecialDocType" ); MySpecialDocType must, of course, be linked in or be found in MySpecialDocType.{so,dll}. -- ----- st...@s1... http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts |