Changeset 281
- Timestamp:
- 03/27/10 08:24:14 (2 years ago)
- Files:
-
- dconstructor/trunk/dconstructor/build2.d (modified) (3 diffs)
- dconstructor/trunk/dconstructor/circular.d (modified) (2 diffs)
- dconstructor/trunk/dconstructor/lifecycles.d (modified) (1 diff)
- dconstructor/trunk/dconstructor/property.d (modified) (1 diff)
- dconstructor/trunk/dconstructor/subbuilders.d (modified) (2 diffs)
- dconstructor/trunk/examples/LICENSE.TXT (modified) (2 diffs)
- dconstructor/trunk/examples/custom.d (modified) (1 diff)
- dconstructor/trunk/examples/speedctor.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dconstructor/trunk/dconstructor/build2.d
r280 r281 71 71 circular = new Circular (stack); 72 72 defaultLifecycle = new SingletonLifecycle; 73 lifecycleProviders ~= new InstanceLifecycleProvider; 74 lifecycleProviders ~= new SingletonLifecycleProvider; 73 auto instance = new InstanceLifecycleProvider; 74 assert (instance !is null); 75 auto singleton = new SingletonLifecycleProvider; 76 assert (singleton !is null); 77 lifecycleProviders = [cast(ILifecycleProvider)instance, singleton].dup; 75 78 } 76 79 … … 134 137 Builder provide(T) (T value) 135 138 { 136 void[] arr = (cast(void*) (&value))[0 .. T.sizeof]; 139 static if (is (T == interface)) 140 { 141 // always store interface values as Object 142 Object o = cast(Object) value; 143 void[] arr = (cast(void*) (&o))[0 .. Object.sizeof]; 144 } 145 else 146 { 147 void[] arr = (cast(void*) (&value))[0 .. T.sizeof]; 148 } 137 149 registerBuilder (typeid(T), new ConstantBuilder (arr), null); 138 150 return this; … … 222 234 foreach (provider; lifecycleProviders) 223 235 { 236 assert (provider !is null); 224 237 auto cycle = provider.get(type); 225 if (cycle) return cycle; 238 if (cycle) 239 { 240 return cycle; 241 } 226 242 } 227 243 return defaultLifecycle; dconstructor/trunk/dconstructor/circular.d
r269 r281 3 3 import dconstructor.stack; 4 4 import dconstructor.exception; 5 import tango.io.Stdout; 5 6 6 7 // Something can be in here many times -- once for a constructor, and once … … 22 23 in 23 24 { 24 assert (_stack.last () is info, "trying to exit a constructor that has not been entered -- this is a bug"); 25 assert (_stack !is null); 26 assert (info !is null, "tried to exit constructor for null typeinfo"); 27 auto last = _stack.last; 28 assert (last !is null); 29 } 30 out 31 { 32 assert (!_stack.contains (info)); 25 33 } 26 34 body 27 35 { 28 36 _stack.pop (); 29 assert (!_stack.contains (info));30 37 } 31 38 dconstructor/trunk/dconstructor/lifecycles.d
r271 r281 42 42 { 43 43 private InstanceLifecycle _single; 44 44 45 this () 45 46 { dconstructor/trunk/dconstructor/property.d
r268 r281 30 30 static this () 31 31 { 32 builder().bind!(` ~ T.stringof ~ `, typeof(this)); 32 auto b = builder; 33 builder.bind!(` ~ T.stringof ~ `, typeof(this)); 33 34 } 34 35 `; dconstructor/trunk/dconstructor/subbuilders.d
r272 r281 59 59 this (void[] instance) 60 60 { 61 this.instance = instance ;61 this.instance = instance.dup; 62 62 } 63 63 … … 79 79 void build (Builder parent, void* fill) 80 80 { 81 parent.circular.push (typeid(T)); 81 auto t = typeid(T); 82 parent.circular.push (t); 82 83 auto object = get (parent); 83 parent.circular.endCtor (t ypeid(T));84 parent.circular.endCtor (t); 84 85 static if (is (typeof(T.inject) == function)) 85 86 { dconstructor/trunk/examples/LICENSE.TXT
r132 r281 1 The documentation and examples in this directory are copyright 2008 by Christopher Wright. It is releasedunder the WTFPL:1 The documentation and examples in this directory are originally copyright 2008 by Christopher Wright. It is released under public domain where applicable, otherwise under the WTFPL: 2 2 3 3 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE … … 5 5 0. You just DO WHAT THE FUCK YOU WANT TO. 6 6 7 dconstructor/trunk/examples/custom.d
r269 r281 53 53 { 54 54 auto build = builder (); 55 builder ().autobuild (true);55 builder ().autobuild = true; 56 56 auto special = new SpecializedBuilder!(typeof(build)) (); 57 builder (). config.custom!(Specialized) (special);57 builder ().provide!(Specialized) (special); 58 58 builder ().get!(NeedsSpecialized); 59 59 builder ().get!(WantsSpecialized); dconstructor/trunk/examples/speedctor.d
r268 r281 1 1 module speedctor; 2 2 3 //import dconstructor.api;4 //import dconstructor.default_builder;5 3 import tango.io.Stdout; 6 4 import tango.time.StopWatch; … … 8 6 void main () 9 7 { 10 // builder ().register!(Thingaaaaa);11 // builder ().get!(Thingaaaaa);12 Stdout.formatln ("built 10,000 iterations in {} seconds with instances", -1);13 8 StopWatch watch; 14 9 watch.start (); 15 Stdout.formatln ("built 10,000 iterations in {} seconds with instances", -1);16 10 for (int i = 0; i < 10_000; i++) 17 11 new Thing (); 18 Stdout.formatln ("built 10,000 iterations in {} seconds with instances", -1);19 12 double d = watch.stop (); 20 13 Stdout.formatln ("built 10,000 iterations in {} seconds with instances", d);
