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     Alexandru Ermicioi
29 **/
30 module aermicioi.aedi_property_reader.yaml.inspector;
31 
32 import aermicioi.aedi_property_reader.core.inspector;
33 import dyaml;
34 import std.algorithm;
35 import std.range;
36 
37 /**
38 Inspector for xml elements.
39 **/
40 class YamlInspector : Inspector!Node {
41 
42     /**
43     Identify the type of child field of component.
44 
45     Params:
46         component = a composite component (class, struct, assoc array etc.) containing some fields
47 
48     Returns:
49         Type of field, or typeid(void) if field is not present in component
50     **/
51     TypeInfo typeOf(Node component, in string property) const nothrow {
52         try {
53 
54             return this.typeOf(component[property]);
55         } catch (Exception e) {
56 
57         }
58 
59         return typeid(void);
60     }
61 
62     /**
63     Identify the type of component itself.
64 
65     Identify the type of component itself. It will inspect the component and will return accurate
66     type info that the component represents.
67 
68     Params:
69         component = component which should be identified.
70 
71     Returns:
72         Type info of component, or typeid(void) if component cannot be identified by inspector
73     **/
74     TypeInfo typeOf(Node component) const nothrow {
75         return typeid(component);
76     }
77 
78     /**
79     Check if component has a field or a property.
80 
81     Params:
82         component = component with fields
83         property = component property that is tested for existence
84 
85     Returns:
86         true if field is present either in readonly, or writeonly form (has getters and setters).
87     **/
88     bool has(Node component, in string property) const nothrow {
89         try {
90 
91             return component.containsKey(property);
92         } catch (Exception e) {
93 
94         }
95 
96         return false;
97     }
98 
99     /**
100     Return a list of properties that component holds.
101 
102     Params:
103         component = the component with fields
104 
105     Returns:
106         an arary of property identities.
107     **/
108     string[] properties(Node component) const nothrow {
109         try {
110 
111             if (component.isMapping) {
112                 return component.mappingKeys!string.array;
113             }
114         } catch (Exception e) {
115 
116         }
117 
118         return [];
119     }
120 }