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.env.env_factory;
31 
32 import aermicioi.aedi_property_reader.convertor_factory;
33 import aermicioi.aedi.factory;
34 import aermicioi.aedi.storage.locator;
35 import aermicioi.aedi.storage.wrapper;
36 import aermicioi.aedi.storage.decorator;
37 import aermicioi.aedi.exception;
38 import std.traits;
39 import std.xml;
40 import std.conv;
41 
42 /**
43 A convertor factory that uses conv.to method to convert strings into To types.
44 
45 Params:
46 	FromType = original representation form of data to be converted.
47 	ToType = type of component that is built based on FromType data.
48 **/
49 class StringConvertorFactory(To, From : string = string) : ConvertorFactory!(string, To) {
50     
51     private {
52         
53         Locator!() locator_;
54         string convertible_;
55     }
56     
57     public {
58         
59         @property {
60 			/**
61 			Set convertible
62 			
63 			Params: 
64 				convertible = data that the factory should convert into To component
65 			Returns:
66 				StringConvertorFactory!(To, From)
67 			**/
68         	StringConvertorFactory!(To, From) convertible(string convertible) @safe nothrow {
69         		this.convertible_ = convertible;
70         	
71         		return this;
72         	}
73         	
74 			/**
75 			Get convertible data
76 			
77 			Returns:
78 				FromType
79 			**/
80         	string convertible() @safe nothrow {
81         		return this.convertible_;
82         	}
83         	
84 			/**
85     		Get the type info of To that is created.
86     		
87     		Returns:
88     			TypeInfo object of created component.
89     		**/
90         	TypeInfo type() {
91         	    return typeid(To);
92         	}
93         	
94 			/**
95 			Set a locator to object.
96 			
97 			Params:
98 				locator = the locator that is set to oject.
99 			
100 			Returns:
101 				LocatorAware.
102 			**/
103         	StringConvertorFactory!(To, From) locator(Locator!() locator) @safe nothrow {
104         		this.locator_ = locator;
105         	
106         		return this;
107         	}
108         }
109         
110 		/**
111 		Instantiates component of type To.
112 		
113 		Returns:
114 			To instantiated component.
115 		**/
116         To factory() {
117             return this.convertible.to!To;
118         }
119     }
120 }