53 | | <a name="l00042"></a>00042 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a>* theinstance; |
54 | | <a name="l00043"></a>00043 vec getvec ( Setting& S ) { |
55 | | <a name="l00044"></a>00044 CHECK_UITYPE(S,TypeArray); |
56 | | <a name="l00045"></a>00045 vec tmp; |
57 | | <a name="l00046"></a>00046 tmp.set_size ( S.getLength() ); |
58 | | <a name="l00047"></a>00047 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
59 | | <a name="l00048"></a>00048 <span class="keywordflow">switch</span> (S[i].getType()) { |
60 | | <a name="l00049"></a>00049 <span class="keywordflow">case</span> Setting::TypeFloat : |
61 | | <a name="l00050"></a>00050 tmp[i]=double(S[i]);<span class="keywordflow">break</span>; |
62 | | <a name="l00051"></a>00051 <span class="keywordflow">case</span> Setting::TypeInt : |
63 | | <a name="l00052"></a>00052 tmp[i]=int(S[i]);<span class="keywordflow">break</span>; |
64 | | <a name="l00053"></a>00053 <span class="keywordflow">case</span> Setting::TypeBoolean : |
65 | | <a name="l00054"></a>00054 tmp[i]=bool(S[i]);<span class="keywordflow">break</span>; |
66 | | <a name="l00055"></a>00055 <span class="keywordflow">default</span>: it_error(<span class="stringliteral">"libconfig error?"</span>); |
67 | | <a name="l00056"></a>00056 } |
68 | | <a name="l00057"></a>00057 } |
69 | | <a name="l00058"></a>00058 <span class="keywordflow">return</span> tmp; |
70 | | <a name="l00059"></a>00059 }; |
71 | | <a name="l00060"></a>00060 vec getivec ( Setting& S ) { |
72 | | <a name="l00061"></a>00061 CHECK_UITYPE(S,TypeArray); |
73 | | <a name="l00062"></a>00062 vec tmp; |
74 | | <a name="l00063"></a>00063 tmp.set_size ( S.getLength() ); |
75 | | <a name="l00064"></a>00064 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
76 | | <a name="l00065"></a>00065 <span class="keywordflow">switch</span> (S[i].getType()) { |
77 | | <a name="l00066"></a>00066 <span class="keywordflow">case</span> Setting::TypeFloat : |
78 | | <a name="l00067"></a>00067 tmp[i]=double(S[i]);<span class="keywordflow">break</span>; |
79 | | <a name="l00068"></a>00068 <span class="keywordflow">case</span> Setting::TypeInt : |
80 | | <a name="l00069"></a>00069 tmp[i]=int(S[i]);<span class="keywordflow">break</span>; |
81 | | <a name="l00070"></a>00070 <span class="keywordflow">case</span> Setting::TypeBoolean : |
82 | | <a name="l00071"></a>00071 tmp[i]=bool(S[i]);<span class="keywordflow">break</span>; |
83 | | <a name="l00072"></a>00072 <span class="keywordflow">default</span>: it_error(<span class="stringliteral">"libconfig error?"</span>); |
84 | | <a name="l00073"></a>00073 } |
85 | | <a name="l00074"></a>00074 } |
86 | | <a name="l00075"></a>00075 <span class="keywordflow">return</span> tmp; |
87 | | <a name="l00076"></a>00076 }; |
88 | | <a name="l00077"></a>00077 <span class="keyword">public</span>: |
89 | | <a name="l00078"></a>00078 <a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &typ){__uimap__.insert(make_pair(typ,<span class="keyword">this</span>));} |
90 | | <a name="l00079"></a>00079 <span class="keyword">virtual</span> <span class="keywordtype">void</span> build(Setting &S, <span class="keywordtype">void</span>** result) <span class="keyword">const</span> =0; |
91 | | <a name="l00080"></a>00080 }; |
92 | | <a name="l00081"></a>00081 |
93 | | <a name="l00082"></a>00082 <span class="keyword">class </span>UIexternal:<span class="keyword">public</span> <a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a>{ |
94 | | <a name="l00083"></a>00083 <span class="keyword">public</span>: |
95 | | <a name="l00084"></a>00084 UIexternal():<a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a>(<span class="stringliteral">"external"</span>){} |
96 | | <a name="l00085"></a>00085 <span class="keywordtype">void</span> build(Setting &S, <span class="keywordtype">void</span>** result) <span class="keyword">const</span>; |
97 | | <a name="l00086"></a>00086 }; |
98 | | <a name="l00087"></a>00087 |
99 | | <a name="l00088"></a>00088 <span class="keyword">class </span>UIinternal:<span class="keyword">public</span> UIbuilder{ |
100 | | <a name="l00089"></a>00089 <span class="keyword">public</span>: |
101 | | <a name="l00090"></a>00090 UIinternal():UIbuilder(<span class="stringliteral">"internal"</span>){} |
102 | | <a name="l00091"></a>00091 <span class="keywordtype">void</span> build(Setting &S, <span class="keywordtype">void</span>** result) <span class="keyword">const</span>; |
103 | | <a name="l00092"></a>00092 }; |
104 | | <a name="l00093"></a>00093 |
105 | | <a name="l00095"></a>00095 <span class="keyword">template</span><<span class="keyword">class</span> T> |
106 | | <a name="l00096"></a>00096 <span class="keywordtype">void</span> UIbuild(Setting &S, T** ret){ |
107 | | <a name="l00097"></a>00097 CHECK_UITYPE(S,TypeGroup); |
108 | | <a name="l00098"></a>00098 T* tmp; |
109 | | <a name="l00099"></a>00099 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
110 | | <a name="l00100"></a>00100 it_assert_debug(S.exists(<span class="stringliteral">"type"</span>), string(S.getPath())+<span class="stringliteral">" is not a valid UI!"</span>); |
111 | | <a name="l00101"></a>00101 |
112 | | <a name="l00102"></a>00102 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
113 | | <a name="l00103"></a>00103 <span class="comment">// Find "type" in list of registred UI builders</span> |
114 | | <a name="l00104"></a>00104 UImap::const_iterator iter = __uimap__.find( typ ); |
115 | | <a name="l00105"></a>00105 <span class="keywordflow">if</span>( iter == __uimap__.end()) { |
116 | | <a name="l00106"></a>00106 it_error(<span class="stringliteral">"UI of type \""</span> + typ + <span class="stringliteral">"\" is not registered!"</span>); |
117 | | <a name="l00107"></a>00107 } |
118 | | <a name="l00108"></a>00108 <span class="keywordflow">else</span> { |
119 | | <a name="l00109"></a>00109 <span class="keyword">const</span> UIbuilder* is= iter->second; |
120 | | <a name="l00110"></a>00110 <span class="comment">//BUILD the result</span> |
121 | | <a name="l00111"></a>00111 is->build(S,reinterpret_cast<void**>(&tmp)); |
122 | | <a name="l00112"></a>00112 } |
123 | | <a name="l00113"></a>00113 <span class="comment">// make assignment</span> |
124 | | <a name="l00114"></a>00114 *ret=tmp; |
125 | | <a name="l00115"></a>00115 }; |
126 | | <a name="l00116"></a>00116 |
127 | | <a name="l00117"></a>00117 } |
128 | | <a name="l00118"></a>00118 <span class="preprocessor">#endif UIBUILD</span> |
| 54 | <a name="l00042"></a>00042 <span class="keyword">const</span> vec getvec ( Setting& S )<span class="keyword"> const </span>{ |
| 55 | <a name="l00043"></a>00043 CHECK_UITYPE ( S,TypeArray ); |
| 56 | <a name="l00044"></a>00044 vec tmp; |
| 57 | <a name="l00045"></a>00045 tmp.set_size ( S.getLength() ); |
| 58 | <a name="l00046"></a>00046 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
| 59 | <a name="l00047"></a>00047 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
| 60 | <a name="l00048"></a>00048 <span class="keywordflow">case</span> Setting::TypeFloat : |
| 61 | <a name="l00049"></a>00049 tmp[i]=double ( S[i] );<span class="keywordflow">break</span>; |
| 62 | <a name="l00050"></a>00050 <span class="keywordflow">case</span> Setting::TypeInt : |
| 63 | <a name="l00051"></a>00051 tmp[i]=int ( S[i] );<span class="keywordflow">break</span>; |
| 64 | <a name="l00052"></a>00052 <span class="keywordflow">case</span> Setting::TypeBoolean : |
| 65 | <a name="l00053"></a>00053 tmp[i]=bool ( S[i] );<span class="keywordflow">break</span>; |
| 66 | <a name="l00054"></a>00054 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
| 67 | <a name="l00055"></a>00055 } |
| 68 | <a name="l00056"></a>00056 } |
| 69 | <a name="l00057"></a>00057 <span class="keywordflow">return</span> tmp; |
| 70 | <a name="l00058"></a>00058 }; |
| 71 | <a name="l00059"></a>00059 <span class="keyword">const</span> vec getivec ( Setting& S )<span class="keyword"> const </span>{ |
| 72 | <a name="l00060"></a>00060 CHECK_UITYPE ( S,TypeArray ); |
| 73 | <a name="l00061"></a>00061 vec tmp; |
| 74 | <a name="l00062"></a>00062 tmp.set_size ( S.getLength() ); |
| 75 | <a name="l00063"></a>00063 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
| 76 | <a name="l00064"></a>00064 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
| 77 | <a name="l00065"></a>00065 <span class="keywordflow">case</span> Setting::TypeFloat : |
| 78 | <a name="l00066"></a>00066 tmp[i]=double ( S[i] );<span class="keywordflow">break</span>; |
| 79 | <a name="l00067"></a>00067 <span class="keywordflow">case</span> Setting::TypeInt : |
| 80 | <a name="l00068"></a>00068 tmp[i]=int ( S[i] );<span class="keywordflow">break</span>; |
| 81 | <a name="l00069"></a>00069 <span class="keywordflow">case</span> Setting::TypeBoolean : |
| 82 | <a name="l00070"></a>00070 tmp[i]=bool ( S[i] );<span class="keywordflow">break</span>; |
| 83 | <a name="l00071"></a>00071 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
| 84 | <a name="l00072"></a>00072 } |
| 85 | <a name="l00073"></a>00073 } |
| 86 | <a name="l00074"></a>00074 <span class="keywordflow">return</span> tmp; |
| 87 | <a name="l00075"></a>00075 }; |
| 88 | <a name="l00076"></a>00076 <span class="keyword">public</span>: |
| 89 | <a name="l00078"></a><a class="code" href="classbdm_1_1UIbuilder.html#c75103dd58395644e80f1eea886c656b">00078</a> <a class="code" href="classbdm_1_1UIbuilder.html#c75103dd58395644e80f1eea886c656b" title="Constructor needs to be run only once macro UIREGISTER.">UIbuilder</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &typ ) {<a class="code" href="namespacebdm.html#edbf34217028dd95a3680c346af85fea" title="global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro...">__uimap__</a>.insert ( make_pair ( typ,<span class="keyword">this</span> ) );} |
| 90 | <a name="l00080"></a>00080 <span class="keyword">virtual</span> <a class="code" href="classbdm_1_1bdmroot.html" title="Root class of BDM objects.">bdmroot</a>* <a class="code" href="classbdm_1_1UIbuilder.html#193cede6302669ff48dfd8ab3b7e31f8" title="Function building the computational object.">build</a> ( Setting &S ) <span class="keyword">const</span> =0; |
| 91 | <a name="l00081"></a>00081 }; |
| 92 | <a name="l00082"></a>00082 |
| 93 | <a name="l00083"></a>00083 <span class="keyword">class </span>UIexternal:<span class="keyword">public</span> UIbuilder { |
| 94 | <a name="l00084"></a>00084 <span class="keyword">public</span>: |
| 95 | <a name="l00085"></a>00085 UIexternal() :UIbuilder ( <span class="stringliteral">"external"</span> ) {} |
| 96 | <a name="l00086"></a>00086 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
| 97 | <a name="l00087"></a>00087 }; |
| 98 | <a name="l00088"></a>00088 |
| 99 | <a name="l00089"></a>00089 <span class="keyword">class </span>UIinternal:<span class="keyword">public</span> UIbuilder { |
| 100 | <a name="l00090"></a>00090 <span class="keyword">public</span>: |
| 101 | <a name="l00091"></a>00091 UIinternal() :<a class="code" href="classbdm_1_1UIbuilder.html#c75103dd58395644e80f1eea886c656b" title="Constructor needs to be run only once macro UIREGISTER.">UIbuilder</a> ( <span class="stringliteral">"internal"</span> ) {} |
| 102 | <a name="l00092"></a>00092 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
| 103 | <a name="l00093"></a>00093 }; |
| 104 | <a name="l00094"></a>00094 |
| 105 | <a name="l00096"></a>00096 <span class="keywordtype">void</span> <a class="code" href="namespacebdm.html#f420706e534b420cf6561aa529be9a9e" title="[Debugging] Print values in current S to cout">UI_DBG</a> ( Setting &S, <span class="keyword">const</span> <span class="keywordtype">string</span> &spc ); |
| 106 | <a name="l00097"></a>00097 |
| 107 | <a name="l00099"></a>00099 <span class="keyword">template</span><<span class="keyword">class</span> T> |
| 108 | <a name="l00100"></a><a class="code" href="namespacebdm.html#b547b14af614cba1ab6c8942dde34462">00100</a> <span class="keywordtype">void</span> <a class="code" href="namespacebdm.html#b547b14af614cba1ab6c8942dde34462" title="Prototype of a UI builder. Return value is by the second argument since it type checking...">UIbuild</a> ( Setting &S, T* &ret ) { |
| 109 | <a name="l00101"></a>00101 CHECK_UITYPE ( S,TypeGroup ); |
| 110 | <a name="l00102"></a>00102 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
| 111 | <a name="l00103"></a>00103 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
| 112 | <a name="l00104"></a>00104 |
| 113 | <a name="l00105"></a>00105 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
| 114 | <a name="l00106"></a>00106 <span class="comment">// Find "type" in list of registred UI builders</span> |
| 115 | <a name="l00107"></a>00107 UImap::const_iterator iter = <a class="code" href="namespacebdm.html#edbf34217028dd95a3680c346af85fea" title="global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro...">__uimap__</a>.find ( typ ); |
| 116 | <a name="l00108"></a>00108 <span class="keywordflow">if</span> ( iter == <a class="code" href="namespacebdm.html#edbf34217028dd95a3680c346af85fea" title="global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro...">__uimap__</a>.end() ) { |
| 117 | <a name="l00109"></a>00109 it_error ( <span class="stringliteral">"UI of type \""</span> + typ + <span class="stringliteral">"\" is not registered!"</span> ); |
| 118 | <a name="l00110"></a>00110 } |
| 119 | <a name="l00111"></a>00111 |
| 120 | <a name="l00112"></a>00112 <span class="comment">//BUILD the result</span> |
| 121 | <a name="l00113"></a>00113 <span class="keywordflow">try</span> { |
| 122 | <a name="l00114"></a>00114 ret = <span class="keyword">dynamic_cast<</span>T*<span class="keyword">></span> ( iter->second->build ( S ) ); |
| 123 | <a name="l00115"></a>00115 } |
| 124 | <a name="l00116"></a>00116 <span class="keywordflow">catch</span> ( SettingTypeException e ) { |
| 125 | <a name="l00117"></a>00117 <a class="code" href="namespacebdm.html#f420706e534b420cf6561aa529be9a9e" title="[Debugging] Print values in current S to cout">UI_DBG</a>(S,<span class="stringliteral">""</span>); |
| 126 | <a name="l00118"></a>00118 it_error ( <span class="stringliteral">"Setting "</span> +<span class="keywordtype">string</span> ( e.getPath() ) +<span class="stringliteral">" is of incorrect Type"</span> );} |
| 127 | <a name="l00119"></a>00119 <span class="keywordflow">catch</span> ( SettingNotFoundException e ) { |
| 128 | <a name="l00120"></a>00120 <a class="code" href="namespacebdm.html#f420706e534b420cf6561aa529be9a9e" title="[Debugging] Print values in current S to cout">UI_DBG</a>(S,<span class="stringliteral">""</span>); |
| 129 | <a name="l00121"></a>00121 it_error ( <span class="stringliteral">"Setting "</span> + <span class="keywordtype">string</span> ( e.getPath() ) +<span class="stringliteral">" was not found"</span> );} |
| 130 | <a name="l00122"></a>00122 }; |
| 131 | <a name="l00123"></a>00123 |
| 132 | <a name="l00125"></a>00125 <span class="keyword">template</span><<span class="keyword">class</span> T> |
| 133 | <a name="l00126"></a><a class="code" href="namespacebdm.html#0760231b120a0b42f80b09515456d57b">00126</a> <span class="keywordtype">void</span> <a class="code" href="namespacebdm.html#0760231b120a0b42f80b09515456d57b" title="Auxiliary function allowing recursivity in S (too complex, remove?).">UIcall</a> ( Setting &S, <span class="keywordtype">void</span> ( *func ) ( Setting&, T ), T Tmp ) { |
| 134 | <a name="l00127"></a>00127 CHECK_UITYPE ( S,TypeGroup ); |
| 135 | <a name="l00128"></a>00128 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
| 136 | <a name="l00129"></a>00129 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
| 137 | <a name="l00130"></a>00130 |
| 138 | <a name="l00131"></a>00131 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
| 139 | <a name="l00132"></a>00132 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"internal"</span> ) { |
| 140 | <a name="l00133"></a>00133 <span class="keywordflow">try</span> { |
| 141 | <a name="l00134"></a>00134 Setting* Stmp = &S; |
| 142 | <a name="l00135"></a>00135 <span class="keywordflow">do</span> {Stmp=& ( Stmp->getParent() );} |
| 143 | <a name="l00136"></a>00136 <span class="keywordflow">while</span> ( !Stmp->isRoot() ); |
| 144 | <a name="l00137"></a>00137 Setting& intS=Stmp->lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ); |
| 145 | <a name="l00138"></a>00138 func ( intS, Tmp ); <span class="comment">// <======== calling func</span> |
| 146 | <a name="l00139"></a>00139 <span class="keywordflow">return</span>; |
| 147 | <a name="l00140"></a>00140 } |
| 148 | <a name="l00141"></a>00141 <span class="keywordflow">catch</span> ( ... ) { |
| 149 | <a name="l00142"></a>00142 it_error ( <span class="stringliteral">"Internal field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
| 150 | <a name="l00143"></a>00143 } |
| 151 | <a name="l00144"></a>00144 } |
| 152 | <a name="l00145"></a>00145 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"external"</span> ) { |
| 153 | <a name="l00146"></a>00146 UIFile C(S[<span class="stringliteral">"filename"</span>]); |
| 154 | <a name="l00147"></a>00147 <span class="keywordflow">try</span> { |
| 155 | <a name="l00148"></a>00148 func ( C.lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ), Tmp ); |
| 156 | <a name="l00149"></a>00149 } |
| 157 | <a name="l00150"></a>00150 <span class="keywordflow">catch</span> ( ... ) { |
| 158 | <a name="l00151"></a>00151 it_error ( <span class="stringliteral">"External field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
| 159 | <a name="l00152"></a>00152 } |
| 160 | <a name="l00153"></a>00153 <span class="keywordflow">return</span>; |
| 161 | <a name="l00154"></a>00154 } |
| 162 | <a name="l00155"></a>00155 |
| 163 | <a name="l00156"></a>00156 <span class="comment">// v======================= calling final func</span> |
| 164 | <a name="l00157"></a>00157 func ( S, Tmp ); |
| 165 | <a name="l00158"></a>00158 }; |
| 166 | <a name="l00159"></a>00159 |
| 167 | <a name="l00160"></a>00160 } |
| 168 | <a name="l00161"></a>00161 <span class="preprocessor">#endif //UIBUILD</span> |