root/doc/html/uibuilder_8h-source.html @ 259

Revision 259, 11.8 kB (checked in by smidl, 16 years ago)

doc

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>mixpp: work/git/mixpp/bdm/uibuilder.h Source File</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.6 -->
8<div class="navigation" id="top">
9  <div class="tabs">
10    <ul>
11      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
12      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
13      <li><a href="modules.html"><span>Modules</span></a></li>
14      <li><a href="annotated.html"><span>Classes</span></a></li>
15      <li class="current"><a href="files.html"><span>Files</span></a></li>
16    </ul>
17  </div>
18<h1>work/git/mixpp/bdm/uibuilder.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef UIBUILD</span>
19<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define UIBUILD</span>
20<a name="l00003"></a>00003 <span class="preprocessor"></span>
21<a name="l00004"></a>00004 <span class="preprocessor">#include "libconfig/libconfig.h++"</span>
22<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;itpp/itbase.h&gt;</span>
23<a name="l00006"></a>00006 <span class="preprocessor">#include "<a class="code" href="libBM_8h.html" title="Bayesian Models (bm) that use Bayes rule to learn from observations.">stat/libBM.h</a>"</span>
24<a name="l00007"></a>00007
25<a name="l00008"></a>00008 <span class="keyword">namespace </span>bdm{
26<a name="l00009"></a>00009
27<a name="l00010"></a>00010 <span class="keyword">using namespace </span>libconfig;
28<a name="l00011"></a>00011 <span class="keyword">using namespace </span>std;
29<a name="l00012"></a>00012
30<a name="l00013"></a>00013 <span class="preprocessor">#define CHECK_UITYPE(S,Type) it_assert_debug(S.getType()==Setting::Type, string("Wrong input path \"")+string(S.getPath())+string("\""));</span>
31<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define UIREGISTER(UI) UI* UI##_global_instance = new UI();</span>
32<a name="l00015"></a>00015 <span class="preprocessor"></span>
33<a name="l00017"></a>00017
34<a name="l00018"></a>00018 <span class="keyword">class </span>UIbuilder;
35<a name="l00020"></a>00020 <span class="keyword">typedef</span> map&lt;const string, const UIbuilder*&gt; UImap;
36<a name="l00021"></a>00021 <span class="keyword">extern</span> UImap __uimap__;
37<a name="l00022"></a>00022
38<a name="l00023"></a>00023 <span class="keyword">class </span>UIFile : <span class="keyword">public</span> Config{
39<a name="l00024"></a>00024         <span class="keyword">public</span>:
40<a name="l00025"></a>00025         UIFile(<span class="keyword">const</span> <span class="keywordtype">char</span> * fname):Config(){
41<a name="l00026"></a>00026                 <span class="keywordflow">try</span>{Config::readFile(fname);}
42<a name="l00027"></a>00027                 <span class="keywordflow">catch</span> (ParseException&amp; P) {
43<a name="l00028"></a>00028                         <span class="keywordtype">char</span> msg[200];
44<a name="l00029"></a>00029                         sprintf(msg,<span class="stringliteral">"Error in file %s  on line %d."</span>, fname, P.getLine());
45<a name="l00030"></a>00030                         it_error(msg);
46<a name="l00031"></a>00031                 }
47<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>);}
48<a name="l00033"></a>00033         }
49<a name="l00034"></a>00034 };
50<a name="l00035"></a>00035
51<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> {
52<a name="l00041"></a>00041         <span class="keyword">protected</span>:
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&amp; 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&lt;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&amp; 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&lt;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> &amp;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 &amp;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 &amp;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 &amp;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>&lt;<span class="keyword">class</span> T&gt;
106<a name="l00096"></a>00096                 <span class="keywordtype">void</span> UIbuild(Setting &amp;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-&gt;second;
120<a name="l00110"></a>00110                 <span class="comment">//BUILD the result</span>
121<a name="l00111"></a>00111                 is-&gt;build(S,reinterpret_cast&lt;void**&gt;(&amp;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>
129</pre></div></div>
130<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jan 27 16:29:53 2009 for mixpp by&nbsp;
131<a href="http://www.doxygen.org/index.html">
132<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
133</body>
134</html>
Note: See TracBrowser for help on using the browser.