1 /**
2 License:
3 	Boost Software License - Version 1.0 - August 17th, 2003
4 
5 	Permission is hereby granted, free of charge, to any person or organization
6 	obtaining a copy of the software and accompanying documentation covered by
7 	this license (the "Software") to use, reproduce, display, distribute,
8 	execute, and transmit the Software, and to prepare derivative works of the
9 	Software, and to permit third-parties to whom the Software is furnished to
10 	do so, all subject to the following:
11 	
12 	The copyright notices in the Software and this entire statement, including
13 	the above license grant, this restriction and the following disclaimer,
14 	must be included in all copies of the Software, in whole or in part, and
15 	all derivative works of the Software, unless such copies or derivative
16 	works are solely in the form of machine-executable object code generated by
17 	a source language processor.
18 	
19 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 	FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 	SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 	FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 	DEALINGS IN THE SOFTWARE.
26 
27 Authors:
28 	aermicioi
29 **/
30 module aermicioi.aedi_property_reader.generic_convertor_factory;
31 
32 import aermicioi.aedi.storage.decorator;
33 import aermicioi.aedi.storage.locator;
34 import aermicioi.aedi.storage.wrapper;
35 import aermicioi.aedi_property_reader.convertor_factory;
36 
37 /**
38 A factory that wraps any convertor factory into an interface that is compliant with generic convertor container, and rest of aedi containers.
39 **/
40 class GenericObjectWrappingConvertorFactory(T : ConvertorFactory!(FromType, ToType), FromType, ToType) : 
41 	ConvertorFactory!(FromType, Object), MutableDecorator!T {
42     
43     private {
44         T decorated_;
45     }
46     
47     public {
48         
49 		/**
50 		Constructor for GenericObjectWrappingConvertorFactory!(T, FromType, ToType)
51 		
52 		Params: 
53 			factory = wrapped factory
54 		**/
55         this(T factory) {
56             this.decorated = factory;
57         }
58         
59         @property {
60 			/**
61 			Set decorated
62 			
63 			Params: 
64 				decorated = factory that is wrapped
65 			
66 			Returns:
67 				typeof(this)
68 			**/
69             GenericObjectWrappingConvertorFactory!T decorated(T decorated) @safe nothrow {
70             	this.decorated_ = decorated;
71             
72             	return this;
73             }
74             
75 			/**
76 			Get decorated
77 			
78 			Returns:
79 				T
80 			**/
81             T decorated() @safe nothrow {
82             	return this.decorated_;
83             }
84             
85 			/**
86 			Set convertible
87 			
88 			Params: 
89 				convertible = data that the factory should convert into ToType component
90 			Returns:
91 				ConvertorFactory!(FromType, ToType)
92 			**/
93         	GenericObjectWrappingConvertorFactory!T convertible(FromType convertible) @safe nothrow {
94         		this.decorated.convertible = convertible;
95         	
96         		return this;
97         	}
98         	
99 			/**
100 			Get convertible data
101 			
102 			Returns:
103 				FromType
104 			**/
105         	FromType convertible() @safe nothrow {
106         		return this.decorated.convertible;
107         	}
108         	
109 			/**
110     		Get the type info of T that is created.
111     		
112     		Returns:
113     			TypeInfo object of created component.
114     		**/
115         	TypeInfo type() {
116         	    return decorated.type;
117         	}
118         	
119 			/**
120 			Set a locator to object.
121 			
122 			Params:
123 				locator = the locator that is set to oject.
124 			
125 			Returns:
126 				GenericObjectWrappingConvertorFactory!T
127 			**/
128         	GenericObjectWrappingConvertorFactory!T locator(Locator!() locator) {
129         		this.decorated.locator = locator;
130         	
131         		return this;
132         	}
133         }
134         
135 		/**
136 		Instantiates component of type T.
137 		
138 		Returns:
139 			T instantiated component.
140 		**/
141         Object factory() {
142             
143             static if (is(ToType : Object)) {
144                 return this.decorated.factory;
145             } else {
146                 
147                 return new WrapperImpl!ToType(this.decorated.factory);
148             }
149             
150         }
151     }
152 }