34 | | <a name="l00017"></a>00017 |
35 | | <a name="l00018"></a><a class="code" href="namespacebdm.html#4dc620a66ce2fcd4c5f42a03a3909b7c">00018</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a>; |
36 | | <a name="l00020"></a>00020 <span class="keyword">typedef</span> map<const string, const UIbuilder*> <a class="code" href="namespacebdm.html#4dc620a66ce2fcd4c5f42a03a3909b7c" title="Internal structure mapping strings to UIBuilder objects.">UImap</a>; |
37 | | <a name="l00021"></a>00021 <span class="keyword">extern</span> <a class="code" href="namespacebdm.html#4dc620a66ce2fcd4c5f42a03a3909b7c" title="Internal structure mapping strings to UIBuilder objects.">UImap</a> <a class="code" href="namespacebdm.html#edbf34217028dd95a3680c346af85fea" title="global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro...">__uimap__</a>; |
38 | | <a name="l00022"></a>00022 |
39 | | <a name="l00023"></a>00023 <span class="keyword">class </span>UIFile : <span class="keyword">public</span> Config { |
40 | | <a name="l00024"></a>00024 <span class="keyword">public</span>: |
41 | | <a name="l00025"></a>00025 UIFile ( <span class="keyword">const</span> <span class="keywordtype">char</span> * fname ) :Config() { |
42 | | <a name="l00026"></a>00026 <span class="keywordflow">try</span>{Config::readFile ( fname );} |
43 | | <a name="l00027"></a>00027 <span class="keywordflow">catch</span> ( ParseException& P ) { |
44 | | <a name="l00028"></a>00028 <span class="keywordtype">char</span> msg[200]; |
45 | | <a name="l00029"></a>00029 sprintf ( msg,<span class="stringliteral">"Error in file %s on line %d."</span>, fname, P.getLine() ); |
46 | | <a name="l00030"></a>00030 it_error ( msg ); |
47 | | <a name="l00031"></a>00031 } |
48 | | <a name="l00032"></a>00032 <span class="keywordflow">catch</span> ( FileIOException f ) {it_error ( <span class="stringliteral">"File "</span> + <span class="keywordtype">string</span> ( fname ) + <span class="stringliteral">" not found"</span> );} |
49 | | <a name="l00033"></a>00033 } |
50 | | <a name="l00034"></a>00034 }; |
51 | | <a name="l00035"></a>00035 |
52 | | <a name="l00040"></a><a class="code" href="classbdm_1_1UIbuilder.html">00040</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a> { |
53 | | <a name="l00041"></a>00041 <span class="keyword">protected</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> mat getmat ( Setting& S , <span class="keywordtype">int</span> ncols)<span class="keyword"> const </span>{ |
72 | | <a name="l00060"></a>00060 CHECK_UITYPE ( S,TypeArray ); |
73 | | <a name="l00061"></a>00061 mat tmp; |
74 | | <a name="l00062"></a>00062 <span class="keywordtype">int</span> nrows=S.getLength()/ncols; |
75 | | <a name="l00063"></a>00063 <span class="keywordtype">int</span> r=0,c=0; |
76 | | <a name="l00064"></a>00064 tmp.set_size ( nrows, ncols ); |
77 | | <a name="l00065"></a>00065 <span class="comment">// Build matrix row-wise</span> |
78 | | <a name="l00066"></a>00066 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
79 | | <a name="l00067"></a>00067 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
80 | | <a name="l00068"></a>00068 <span class="keywordflow">case</span> Setting::TypeFloat : |
81 | | <a name="l00069"></a>00069 tmp(r,c)=double ( S[i] );<span class="keywordflow">break</span>; |
82 | | <a name="l00070"></a>00070 <span class="keywordflow">case</span> Setting::TypeInt : |
83 | | <a name="l00071"></a>00071 tmp(r,c)=int ( S[i] );<span class="keywordflow">break</span>; |
84 | | <a name="l00072"></a>00072 <span class="keywordflow">case</span> Setting::TypeBoolean : |
85 | | <a name="l00073"></a>00073 tmp(r,c)=bool ( S[i] );<span class="keywordflow">break</span>; |
86 | | <a name="l00074"></a>00074 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
87 | | <a name="l00075"></a>00075 } |
88 | | <a name="l00076"></a>00076 c++; <span class="keywordflow">if</span> (c==ncols) {c=0;r++;} |
89 | | <a name="l00077"></a>00077 } |
90 | | <a name="l00078"></a>00078 <span class="keywordflow">return</span> tmp; |
91 | | <a name="l00079"></a>00079 }; |
92 | | <a name="l00080"></a>00080 <span class="keyword">const</span> vec getivec ( Setting& S )<span class="keyword"> const </span>{ |
93 | | <a name="l00081"></a>00081 CHECK_UITYPE ( S,TypeArray ); |
94 | | <a name="l00082"></a>00082 vec tmp; |
95 | | <a name="l00083"></a>00083 tmp.set_size ( S.getLength() ); |
96 | | <a name="l00084"></a>00084 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
97 | | <a name="l00085"></a>00085 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
98 | | <a name="l00086"></a>00086 <span class="keywordflow">case</span> Setting::TypeFloat : |
99 | | <a name="l00087"></a>00087 tmp[i]=double ( S[i] );<span class="keywordflow">break</span>; |
100 | | <a name="l00088"></a>00088 <span class="keywordflow">case</span> Setting::TypeInt : |
101 | | <a name="l00089"></a>00089 tmp[i]=int ( S[i] );<span class="keywordflow">break</span>; |
102 | | <a name="l00090"></a>00090 <span class="keywordflow">case</span> Setting::TypeBoolean : |
103 | | <a name="l00091"></a>00091 tmp[i]=bool ( S[i] );<span class="keywordflow">break</span>; |
104 | | <a name="l00092"></a>00092 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
105 | | <a name="l00093"></a>00093 } |
106 | | <a name="l00094"></a>00094 } |
107 | | <a name="l00095"></a>00095 <span class="keywordflow">return</span> tmp; |
108 | | <a name="l00096"></a>00096 }; |
109 | | <a name="l00097"></a>00097 <span class="keyword">public</span>: |
110 | | <a name="l00099"></a><a class="code" href="classbdm_1_1UIbuilder.html#c75103dd58395644e80f1eea886c656b">00099</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> ) );} |
111 | | <a name="l00101"></a>00101 <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; |
112 | | <a name="l00102"></a>00102 }; |
113 | | <a name="l00103"></a>00103 |
114 | | <a name="l00104"></a>00104 <span class="keyword">class </span>UIexternal:<span class="keyword">public</span> UIbuilder { |
115 | | <a name="l00105"></a>00105 <span class="keyword">public</span>: |
116 | | <a name="l00106"></a>00106 UIexternal() :UIbuilder ( <span class="stringliteral">"external"</span> ) {} |
117 | | <a name="l00107"></a>00107 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
118 | | <a name="l00108"></a>00108 }; |
119 | | <a name="l00109"></a>00109 |
120 | | <a name="l00110"></a>00110 <span class="keyword">class </span>UIinternal:<span class="keyword">public</span> UIbuilder { |
121 | | <a name="l00111"></a>00111 <span class="keyword">public</span>: |
122 | | <a name="l00112"></a>00112 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> ) {} |
123 | | <a name="l00113"></a>00113 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
124 | | <a name="l00114"></a>00114 }; |
125 | | <a name="l00115"></a>00115 |
126 | | <a name="l00117"></a>00117 <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 ); |
| 74 | <a name="l00016"></a>00016 <span class="preprocessor">#define UICATCH catch ( SettingTypeException e ) {it_error ( "Setting " +string ( e.getPath() ) +" is of incorrect Type" );} catch ( SettingNotFoundException e ) {it_error ( "Setting " + string ( e.getPath() ) +" was not found" );}</span> |
| 75 | <a name="l00017"></a>00017 <span class="preprocessor"></span> |
| 76 | <a name="l00019"></a>00019 |
| 77 | <a name="l00020"></a>00020 <span class="keyword">class </span>UIbuilder; |
| 78 | <a name="l00022"></a>00022 <span class="keyword">typedef</span> map<const string, const UIbuilder*> UImap; |
| 79 | <a name="l00023"></a>00023 <span class="keyword">extern</span> UImap __uimap__; |
| 80 | <a name="l00024"></a>00024 |
| 81 | <a name="l00025"></a>00025 <span class="keyword">class </span>UIFile : <span class="keyword">public</span> Config { |
| 82 | <a name="l00026"></a>00026 <span class="keyword">public</span>: |
| 83 | <a name="l00027"></a>00027 UIFile ( <span class="keyword">const</span> <span class="keywordtype">char</span> * fname ) :Config() { |
| 84 | <a name="l00028"></a>00028 <span class="keywordflow">try</span>{Config::readFile ( fname );} |
| 85 | <a name="l00029"></a>00029 <span class="keywordflow">catch</span> ( FileIOException f ) {it_error ( <span class="stringliteral">"File "</span> + <span class="keywordtype">string</span> ( fname ) + <span class="stringliteral">" not found"</span> );} |
| 86 | <a name="l00030"></a>00030 <span class="keywordflow">catch</span> ( ParseException& P ) { |
| 87 | <a name="l00031"></a>00031 <span class="keywordtype">char</span> msg[200]; |
| 88 | <a name="l00032"></a>00032 sprintf ( msg,<span class="stringliteral">"Error in file %s on line %d."</span>, fname, P.getLine() ); |
| 89 | <a name="l00033"></a>00033 it_error ( msg ); |
| 90 | <a name="l00034"></a>00034 } |
| 91 | <a name="l00035"></a>00035 } |
| 92 | <a name="l00036"></a>00036 }; |
| 93 | <a name="l00037"></a>00037 |
| 94 | <a name="l00042"></a><a class="code" href="classbdm_1_1UIbuilder.html">00042</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1UIbuilder.html" title="Builds computational object from a UserInfo structure.">UIbuilder</a> { |
| 95 | <a name="l00043"></a>00043 <span class="keyword">protected</span>: |
| 96 | <a name="l00044"></a>00044 <span class="keyword">const</span> vec getvec ( Setting& S )<span class="keyword"> const </span>{ |
| 97 | <a name="l00045"></a>00045 CHECK_UITYPE ( S,TypeArray ); |
| 98 | <a name="l00046"></a>00046 vec tmp; |
| 99 | <a name="l00047"></a>00047 tmp.set_size ( S.getLength() ); |
| 100 | <a name="l00048"></a>00048 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
| 101 | <a name="l00049"></a>00049 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
| 102 | <a name="l00050"></a>00050 <span class="keywordflow">case</span> Setting::TypeFloat : |
| 103 | <a name="l00051"></a>00051 tmp[i]=double ( S[i] );<span class="keywordflow">break</span>; |
| 104 | <a name="l00052"></a>00052 <span class="keywordflow">case</span> Setting::TypeInt : |
| 105 | <a name="l00053"></a>00053 tmp[i]=int ( S[i] );<span class="keywordflow">break</span>; |
| 106 | <a name="l00054"></a>00054 <span class="keywordflow">case</span> Setting::TypeBoolean : |
| 107 | <a name="l00055"></a>00055 tmp[i]=bool ( S[i] );<span class="keywordflow">break</span>; |
| 108 | <a name="l00056"></a>00056 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
| 109 | <a name="l00057"></a>00057 } |
| 110 | <a name="l00058"></a>00058 } |
| 111 | <a name="l00059"></a>00059 <span class="keywordflow">return</span> tmp; |
| 112 | <a name="l00060"></a>00060 }; |
| 113 | <a name="l00061"></a>00061 <span class="keyword">const</span> mat getmat ( Setting& S , <span class="keywordtype">int</span> ncols)<span class="keyword"> const </span>{ |
| 114 | <a name="l00062"></a>00062 CHECK_UITYPE ( S,TypeArray ); |
| 115 | <a name="l00063"></a>00063 mat tmp; |
| 116 | <a name="l00064"></a>00064 <span class="keywordtype">int</span> nrows=S.getLength()/ncols; |
| 117 | <a name="l00065"></a>00065 <span class="keywordtype">int</span> r=0,c=0; |
| 118 | <a name="l00066"></a>00066 tmp.set_size ( nrows, ncols ); |
| 119 | <a name="l00067"></a>00067 <span class="comment">// Build matrix row-wise</span> |
| 120 | <a name="l00068"></a>00068 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
| 121 | <a name="l00069"></a>00069 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
| 122 | <a name="l00070"></a>00070 <span class="keywordflow">case</span> Setting::TypeFloat : |
| 123 | <a name="l00071"></a>00071 tmp(r,c)=double ( S[i] );<span class="keywordflow">break</span>; |
| 124 | <a name="l00072"></a>00072 <span class="keywordflow">case</span> Setting::TypeInt : |
| 125 | <a name="l00073"></a>00073 tmp(r,c)=int ( S[i] );<span class="keywordflow">break</span>; |
| 126 | <a name="l00074"></a>00074 <span class="keywordflow">case</span> Setting::TypeBoolean : |
| 127 | <a name="l00075"></a>00075 tmp(r,c)=bool ( S[i] );<span class="keywordflow">break</span>; |
| 128 | <a name="l00076"></a>00076 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
| 129 | <a name="l00077"></a>00077 } |
| 130 | <a name="l00078"></a>00078 c++; <span class="keywordflow">if</span> (c==ncols) {c=0;r++;} |
| 131 | <a name="l00079"></a>00079 } |
| 132 | <a name="l00080"></a>00080 <span class="keywordflow">return</span> tmp; |
| 133 | <a name="l00081"></a>00081 }; |
| 134 | <a name="l00082"></a>00082 <span class="keyword">const</span> ivec getivec ( Setting& S )<span class="keyword"> const </span>{ |
| 135 | <a name="l00083"></a>00083 CHECK_UITYPE ( S,TypeArray ); |
| 136 | <a name="l00084"></a>00084 ivec tmp; |
| 137 | <a name="l00085"></a>00085 tmp.set_size ( S.getLength() ); |
| 138 | <a name="l00086"></a>00086 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) { |
| 139 | <a name="l00087"></a>00087 <span class="keywordflow">switch</span> ( S[i].getType() ) { |
| 140 | <a name="l00088"></a>00088 <span class="keywordflow">case</span> Setting::TypeFloat : |
| 141 | <a name="l00089"></a>00089 tmp[i]=double ( S[i] );<span class="keywordflow">break</span>; |
| 142 | <a name="l00090"></a>00090 <span class="keywordflow">case</span> Setting::TypeInt : |
| 143 | <a name="l00091"></a>00091 tmp[i]=int ( S[i] );<span class="keywordflow">break</span>; |
| 144 | <a name="l00092"></a>00092 <span class="keywordflow">case</span> Setting::TypeBoolean : |
| 145 | <a name="l00093"></a>00093 tmp[i]=bool ( S[i] );<span class="keywordflow">break</span>; |
| 146 | <a name="l00094"></a>00094 <span class="keywordflow">default</span>: it_error ( <span class="stringliteral">"libconfig error?"</span> ); |
| 147 | <a name="l00095"></a>00095 } |
| 148 | <a name="l00096"></a>00096 } |
| 149 | <a name="l00097"></a>00097 <span class="keywordflow">return</span> tmp; |
| 150 | <a name="l00098"></a>00098 }; |
| 151 | <a name="l00099"></a>00099 <span class="keyword">const</span> Array<string> get_as ( Setting& S )<span class="keyword"> const </span>{ |
| 152 | <a name="l00100"></a>00100 CHECK_UITYPE ( S,TypeArray ); |
| 153 | <a name="l00101"></a>00101 Array<string> tmp; |
| 154 | <a name="l00102"></a>00102 tmp.set_size ( S.getLength() ); |
| 155 | <a name="l00103"></a>00103 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<S.getLength();i++ ) {tmp(i)=(<span class="keyword">const</span> <span class="keywordtype">char</span>*)S[i];} |
| 156 | <a name="l00104"></a>00104 <span class="keywordflow">return</span> tmp; |
| 157 | <a name="l00105"></a>00105 }; |
| 158 | <a name="l00106"></a>00106 <span class="keyword">public</span>: |
| 159 | <a name="l00108"></a><a class="code" href="classbdm_1_1UIbuilder.html#c75103dd58395644e80f1eea886c656b">00108</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 ) {__uimap__.insert ( make_pair ( typ,<span class="keyword">this</span> ) );} |
| 160 | <a name="l00110"></a>00110 <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; |
| 161 | <a name="l00111"></a>00111 }; |
| 162 | <a name="l00112"></a>00112 |
| 163 | <a name="l00113"></a>00113 <span class="keyword">class </span>UIexternal:<span class="keyword">public</span> UIbuilder { |
| 164 | <a name="l00114"></a>00114 <span class="keyword">public</span>: |
| 165 | <a name="l00115"></a>00115 UIexternal() :UIbuilder ( <span class="stringliteral">"external"</span> ) {} |
| 166 | <a name="l00116"></a>00116 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
| 167 | <a name="l00117"></a>00117 }; |
128 | | <a name="l00120"></a>00120 <span class="keyword">template</span><<span class="keyword">class</span> T> |
129 | | <a name="l00121"></a><a class="code" href="namespacebdm.html#b547b14af614cba1ab6c8942dde34462">00121</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 ) { |
130 | | <a name="l00122"></a>00122 CHECK_UITYPE ( S,TypeGroup ); |
131 | | <a name="l00123"></a>00123 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
132 | | <a name="l00124"></a>00124 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
133 | | <a name="l00125"></a>00125 |
134 | | <a name="l00126"></a>00126 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
135 | | <a name="l00127"></a>00127 <span class="comment">// Find "type" in list of registred UI builders</span> |
136 | | <a name="l00128"></a>00128 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 ); |
137 | | <a name="l00129"></a>00129 <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() ) { |
138 | | <a name="l00130"></a>00130 it_error ( <span class="stringliteral">"UI of type \""</span> + typ + <span class="stringliteral">"\" is not registered!"</span> ); |
139 | | <a name="l00131"></a>00131 } |
140 | | <a name="l00132"></a>00132 |
141 | | <a name="l00133"></a>00133 <span class="comment">//BUILD the result</span> |
142 | | <a name="l00134"></a>00134 <span class="keywordflow">try</span> { |
143 | | <a name="l00135"></a>00135 ret = <span class="keyword">dynamic_cast<</span>T*<span class="keyword">></span> ( iter->second->build ( S ) ); |
144 | | <a name="l00136"></a>00136 } |
145 | | <a name="l00137"></a>00137 <span class="keywordflow">catch</span> ( SettingTypeException e ) { |
146 | | <a name="l00138"></a>00138 <a class="code" href="namespacebdm.html#f420706e534b420cf6561aa529be9a9e" title="[Debugging] Print values in current S to cout">UI_DBG</a>(S,<span class="stringliteral">""</span>); |
147 | | <a name="l00139"></a>00139 it_error ( <span class="stringliteral">"Setting "</span> +<span class="keywordtype">string</span> ( e.getPath() ) +<span class="stringliteral">" is of incorrect Type"</span> );} |
148 | | <a name="l00140"></a>00140 <span class="keywordflow">catch</span> ( SettingNotFoundException e ) { |
149 | | <a name="l00141"></a>00141 <a class="code" href="namespacebdm.html#f420706e534b420cf6561aa529be9a9e" title="[Debugging] Print values in current S to cout">UI_DBG</a>(S,<span class="stringliteral">""</span>); |
150 | | <a name="l00142"></a>00142 it_error ( <span class="stringliteral">"Setting "</span> + <span class="keywordtype">string</span> ( e.getPath() ) +<span class="stringliteral">" was not found"</span> );} |
151 | | <a name="l00143"></a>00143 }; |
152 | | <a name="l00144"></a>00144 |
153 | | <a name="l00146"></a>00146 <span class="keyword">template</span><<span class="keyword">class</span> T> |
154 | | <a name="l00147"></a><a class="code" href="namespacebdm.html#0760231b120a0b42f80b09515456d57b">00147</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 ) { |
155 | | <a name="l00148"></a>00148 CHECK_UITYPE ( S,TypeGroup ); |
156 | | <a name="l00149"></a>00149 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
157 | | <a name="l00150"></a>00150 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
158 | | <a name="l00151"></a>00151 |
159 | | <a name="l00152"></a>00152 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
160 | | <a name="l00153"></a>00153 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"internal"</span> ) { |
161 | | <a name="l00154"></a>00154 <span class="keywordflow">try</span> { |
162 | | <a name="l00155"></a>00155 Setting* Stmp = &S; |
163 | | <a name="l00156"></a>00156 <span class="keywordflow">do</span> {Stmp=& ( Stmp->getParent() );} |
164 | | <a name="l00157"></a>00157 <span class="keywordflow">while</span> ( !Stmp->isRoot() ); |
165 | | <a name="l00158"></a>00158 Setting& intS=Stmp->lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ); |
166 | | <a name="l00159"></a>00159 func ( intS, Tmp ); <span class="comment">// <======== calling func</span> |
167 | | <a name="l00160"></a>00160 <span class="keywordflow">return</span>; |
168 | | <a name="l00161"></a>00161 } |
169 | | <a name="l00162"></a>00162 <span class="keywordflow">catch</span> ( ... ) { |
170 | | <a name="l00163"></a>00163 it_error ( <span class="stringliteral">"Internal field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
171 | | <a name="l00164"></a>00164 } |
172 | | <a name="l00165"></a>00165 } |
173 | | <a name="l00166"></a>00166 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"external"</span> ) { |
174 | | <a name="l00167"></a>00167 UIFile C(S[<span class="stringliteral">"filename"</span>]); |
175 | | <a name="l00168"></a>00168 <span class="keywordflow">try</span> { |
176 | | <a name="l00169"></a>00169 func ( C.lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ), Tmp ); |
177 | | <a name="l00170"></a>00170 } |
178 | | <a name="l00171"></a>00171 <span class="keywordflow">catch</span> ( ... ) { |
179 | | <a name="l00172"></a>00172 it_error ( <span class="stringliteral">"External field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
180 | | <a name="l00173"></a>00173 } |
181 | | <a name="l00174"></a>00174 <span class="keywordflow">return</span>; |
182 | | <a name="l00175"></a>00175 } |
183 | | <a name="l00176"></a>00176 |
184 | | <a name="l00177"></a>00177 <span class="comment">// v======================= calling final func</span> |
185 | | <a name="l00178"></a>00178 func ( S, Tmp ); |
186 | | <a name="l00179"></a>00179 }; |
| 169 | <a name="l00119"></a>00119 <span class="keyword">class </span>UIinternal:<span class="keyword">public</span> UIbuilder { |
| 170 | <a name="l00120"></a>00120 <span class="keyword">public</span>: |
| 171 | <a name="l00121"></a>00121 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> ) {} |
| 172 | <a name="l00122"></a>00122 bdmroot* build ( Setting &S ) <span class="keyword">const</span>; |
| 173 | <a name="l00123"></a>00123 }; |
| 174 | <a name="l00124"></a>00124 |
| 175 | <a name="l00126"></a>00126 <span class="keywordtype">void</span> UI_DBG ( Setting &S, <span class="keyword">const</span> <span class="keywordtype">string</span> &spc ); |
| 176 | <a name="l00127"></a>00127 |
| 177 | <a name="l00129"></a>00129 <span class="keyword">template</span><<span class="keyword">class</span> T> |
| 178 | <a name="l00130"></a>00130 <span class="keywordtype">void</span> UIbuild ( Setting &S, T* &ret ) { |
| 179 | <a name="l00131"></a>00131 CHECK_UITYPE ( S,TypeGroup ); |
| 180 | <a name="l00132"></a>00132 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
| 181 | <a name="l00133"></a>00133 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
| 182 | <a name="l00134"></a>00134 |
| 183 | <a name="l00135"></a>00135 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
| 184 | <a name="l00136"></a>00136 <span class="comment">// Find "type" in list of registred UI builders</span> |
| 185 | <a name="l00137"></a>00137 UImap::const_iterator iter = __uimap__.find ( typ ); |
| 186 | <a name="l00138"></a>00138 <span class="keywordflow">if</span> ( iter == __uimap__.end() ) { |
| 187 | <a name="l00139"></a>00139 it_error ( <span class="stringliteral">"UI of type \""</span> + typ + <span class="stringliteral">"\" is not registered!"</span> ); |
| 188 | <a name="l00140"></a>00140 } |
| 189 | <a name="l00141"></a>00141 |
| 190 | <a name="l00142"></a>00142 <span class="comment">//BUILD the result</span> |
| 191 | <a name="l00143"></a>00143 <span class="keywordflow">try</span> { |
| 192 | <a name="l00144"></a>00144 ret = <span class="keyword">dynamic_cast<</span>T*<span class="keyword">></span> ( iter->second->build ( S ) ); |
| 193 | <a name="l00145"></a>00145 } |
| 194 | <a name="l00146"></a>00146 UICATCH; |
| 195 | <a name="l00147"></a>00147 }; |
| 196 | <a name="l00148"></a>00148 |
| 197 | <a name="l00150"></a>00150 <span class="keyword">template</span><<span class="keyword">class</span> T> |
| 198 | <a name="l00151"></a>00151 <span class="keywordtype">void</span> UIcall ( Setting &S, <span class="keywordtype">void</span> ( *func ) ( Setting&, T ), T Tmp ) { |
| 199 | <a name="l00152"></a>00152 CHECK_UITYPE ( S,TypeGroup ); |
| 200 | <a name="l00153"></a>00153 <span class="comment">// Check if field "type" is present, if not it is not a valid UI</span> |
| 201 | <a name="l00154"></a>00154 it_assert_debug ( S.exists ( <span class="stringliteral">"type"</span> ), string ( S.getPath() ) +<span class="stringliteral">" is not a valid UI!"</span> ); |
| 202 | <a name="l00155"></a>00155 |
| 203 | <a name="l00156"></a>00156 <span class="keyword">const</span> <span class="keywordtype">string</span> typ=S[<span class="stringliteral">"type"</span>]; |
| 204 | <a name="l00157"></a>00157 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"internal"</span> ) { |
| 205 | <a name="l00158"></a>00158 <span class="keywordflow">try</span> { |
| 206 | <a name="l00159"></a>00159 Setting* Stmp = &S; |
| 207 | <a name="l00160"></a>00160 <span class="keywordflow">do</span> {Stmp=& ( Stmp->getParent() );} |
| 208 | <a name="l00161"></a>00161 <span class="keywordflow">while</span> ( !Stmp->isRoot() ); |
| 209 | <a name="l00162"></a>00162 Setting& intS=Stmp->lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ); |
| 210 | <a name="l00163"></a>00163 func ( intS, Tmp ); <span class="comment">// <======== calling func</span> |
| 211 | <a name="l00164"></a>00164 <span class="keywordflow">return</span>; |
| 212 | <a name="l00165"></a>00165 } |
| 213 | <a name="l00166"></a>00166 <span class="keywordflow">catch</span> ( ... ) { |
| 214 | <a name="l00167"></a>00167 it_error ( <span class="stringliteral">"Internal field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
| 215 | <a name="l00168"></a>00168 } |
| 216 | <a name="l00169"></a>00169 } |
| 217 | <a name="l00170"></a>00170 <span class="keywordflow">if</span> ( typ==<span class="stringliteral">"external"</span> ) { |
| 218 | <a name="l00171"></a>00171 UIFile C(S[<span class="stringliteral">"filename"</span>]); |
| 219 | <a name="l00172"></a>00172 <span class="keywordflow">try</span> { |
| 220 | <a name="l00173"></a>00173 func ( C.lookup ( ( <span class="keyword">const</span> <span class="keywordtype">char</span>* ) S[<span class="stringliteral">"path"</span>] ), Tmp ); |
| 221 | <a name="l00174"></a>00174 } |
| 222 | <a name="l00175"></a>00175 <span class="keywordflow">catch</span> ( ... ) { |
| 223 | <a name="l00176"></a>00176 it_error ( <span class="stringliteral">"External field "</span> + <span class="keywordtype">string</span> ( S.getPath() ) + <span class="stringliteral">" not valid"</span> ); |
| 224 | <a name="l00177"></a>00177 } |
| 225 | <a name="l00178"></a>00178 <span class="keywordflow">return</span>; |
| 226 | <a name="l00179"></a>00179 } |