Changeset 256

Show
Ignore:
Timestamp:
01/28/09 10:01:18 (15 years ago)
Author:
smidl
Message:

uibuilder works (again)

Files:
8 modified

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r247 r256  
    2626ELSE() 
    2727        #This is for UNIX makefile which does only one release at a time. 
    28         SET(CMAKE_BUILD_TYPE Optimized) 
     28        SET(CMAKE_BUILD_TYPE Debug) 
    2929        SET(CMAKE_CXX_FLAGS "-Wall -pipe  -Wno-unknown-pragmas") 
    3030        SET(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG -O2") 
  • bdm/CMakeLists.txt

    r249 r256  
    11# Create a library called "bdm" which includes sources from all directories 
    2  
    3 #add_subdirectory(config) 
    42 
    53SET(BdmMath math/libDC.cpp math/libDC.h math/chmat.cpp math/chmat.h) 
  • bdm/stat/libBM.h

    r254 r256  
    2626 
    2727//! Root class of BDM objects 
    28 class base{}; 
     28class bdmroot{}; 
    2929 
    3030//! Structure of RV (used internally), i.e. expanded RVs 
     
    4747*/ 
    4848 
    49 class RV :base{ 
     49class RV :public bdmroot{ 
    5050protected: 
    5151        //! size = sum of sizes 
     
    139139//! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv 
    140140 
    141 class fnc :base{ 
     141class fnc :public bdmroot{ 
    142142protected: 
    143143        //! Length of the output vector 
     
    165165//! Probability density function with numerical statistics, e.g. posterior density. 
    166166 
    167 class epdf :base { 
     167class epdf :public bdmroot { 
    168168protected: 
    169169        //! Identified of the random variable 
     
    217217//TODO Samplecond can be generalized 
    218218 
    219 class mpdf { 
     219class mpdf : public bdmroot{ 
    220220protected: 
    221221        //! modeled random variable 
     
    358358}; 
    359359 
    360 //!\brief Abstract composition of pdfs, a base for specific classes 
     360//!\brief Abstract composition of pdfs, will be used for specific classes 
    361361//!this abstract class is common to epdf and mpdf 
    362362class compositepdf { 
     
    381381*/ 
    382382 
    383 class DS { 
     383class DS : public bdmroot{ 
    384384protected: 
    385385        //!Observed variables, returned by \c getdata(). 
     
    413413*/ 
    414414 
    415 class BM { 
     415class BM :public bdmroot{ 
    416416protected: 
    417417        //!Random variable of the posterior 
     
    473473*/ 
    474474 
    475 class BMcond :base{ 
     475class BMcond :public bdmroot{ 
    476476protected: 
    477477        //! Identificator of the conditioning variable 
  • bdm/stat/libEF.h

    r254 r256  
    345345 \f] 
    346346 
    347  Inverse Gamma can be converted to Gamma using \[ 
     347 Inverse Gamma can be converted to Gamma using \f[ 
    348348 x\sim iG(a,b) => 1/x\sim G(a,1/b) 
    349 \] 
     349\f] 
    350350This relation is used in sampling. 
    351351 */ 
  • bdm/uibuilder.cpp

    r254 r256  
    55UImap __uimap__; 
    66 
    7 void UIexternal::build(Setting &S, void** result) const{ 
     7void UIexternal::build(Setting &S, bdmroot* &result) const{ 
    88        Config C; 
    99        try{ 
     
    2222UIREGISTER(UIexternal); 
    2323 
    24 void UIinternal::build(Setting &S, void** result) const{ 
     24void UIinternal::build(Setting &S, bdmroot* &result) const{ 
    2525        try {    
    2626                Setting* Stmp = &S; 
  • bdm/uibuilder.h

    r254 r256  
    22#define UIBUILD 
    33 
    4 #include "libconfig/libconfig.h++" 
    54#include <itpp/itbase.h> 
    65#include "stat/libBM.h" 
     6#include "libconfig/libconfig.h++" 
    77 
    88namespace bdm{ 
     
    7676        }; 
    7777        public: 
     78                //!Constructor needs to be run only once via REGISTERUI 
    7879                UIbuilder(const string &typ){__uimap__.insert(make_pair(typ,this));} 
    79                 virtual void build(Setting &S, void** result) const =0; 
     80                //! Function building the computational object 
     81                virtual void build(Setting &S, bdmroot* &result) const =0; 
    8082}; 
    8183 
     
    8385        public: 
    8486                UIexternal():UIbuilder("external"){} 
    85                 void build(Setting &S, void** result) const; 
     87                void build(Setting &S, bdmroot* &result) const; 
    8688}; 
    8789 
     
    8991        public: 
    9092                UIinternal():UIbuilder("internal"){} 
    91                 void build(Setting &S, void** result) const; 
     93                void build(Setting &S, bdmroot* &result) const; 
    9294}; 
    9395 
    9496//! Prototype of a UI builder. Return value is by the second argument since it allows some type of type checking. 
    9597template<class T> 
    96                 void UIbuild(Setting &S, T** ret){ 
     98void UIbuild(Setting &S, T* &ret){ 
    9799        CHECK_UITYPE(S,TypeGroup); 
    98100        T* tmp; 
     
    101103                 
    102104        const string typ=S["type"]; 
     105         
    103106        // Find "type" in list of registred UI builders 
    104107        UImap::const_iterator iter = __uimap__.find( typ ); 
    105108        if( iter == __uimap__.end()) { 
     109                cout << "UI error" << endl; 
    106110                it_error("UI of type \"" + typ + "\" is not registered!"); 
    107111        } 
    108         else { 
    109                 const UIbuilder* is= iter->second;  
    110                 //BUILD the result 
    111                 is->build(S,reinterpret_cast<void**>(&tmp)); 
    112         } 
     112         
     113        const UIbuilder* is= iter->second;  
     114        //BUILD the result 
     115        is->build(S,(bdmroot*&)(tmp)); 
    113116        // make assignment 
    114         *ret=tmp; 
     117        ret=tmp; 
    115118}; 
    116119 
  • tests/CMakeLists.txt

    r249 r256  
    44# Make sure the linker can find the Hello library once it is built. 
    55link_directories (${BDM_BINARY_DIR}/bdm) 
    6  
    7 # Define macro for testing a file 
    8 MACRO(TEST FN) 
    9         add_executable (${FN} ${FN}.cpp) 
    10         target_link_libraries (${FN} debug itpp_debug) 
    11         target_link_libraries (${FN} optimized itpp) 
    12         target_link_libraries (${FN} bdm ${AddLib}) 
    13 ENDMACRO(TEST) 
    146 
    157# Add executable called "helloDemo" that is built from the source files 
  • tests/UI/UIbuilder_test.cpp

    r254 r256  
    55using namespace bdm; 
    66 
    7 class cls { 
     7class cls :public bdmroot{ 
    88        public: 
    99                int a; 
     
    2121        public: 
    2222        UItest():UIbuilder("test"){} 
    23         void build(Setting &S, void** ret) const{ 
     23        void build(Setting &S, bdmroot* &ret) const{ 
    2424                try{ 
    2525                        int a=S["a"]; 
     
    2727                        S.lookupValue("S",St); 
    2828                        cls* tmp = new cls(a,St); 
    29                         *ret=tmp; 
     29                        ret=tmp; 
    3030                } 
    3131                catch (...){ 
     
    3838        public: 
    3939        UItest2():UIbuilder("test2"){} 
    40         void build(Setting &S, void** ret) const{ 
     40        void build(Setting &S, bdmroot* &ret) const{ 
    4141                try{ 
    4242                        int a=S["a"]; 
     
    4444                        S.lookupValue("S",St); 
    4545                        cls* tmp = new cls2(a,St); 
    46                         *ret=tmp; 
     46                        ret=tmp; 
    4747                } 
    4848                catch (...){ 
     
    5959 
    6060int main(){ 
    61  
    6261UIFile UI("UIbuilder_test.cfg"); 
    6362 
    6463cls* Cls; 
    65 UIbuild(UI.lookup("test"),&Cls); 
     64UIbuild(UI.lookup("test"),Cls); 
    6665cls* Cls2; 
    67 UIbuild(UI.lookup("test2"),&Cls2); 
     66UIbuild(UI.lookup("test2"),Cls2); 
    6867cls* Cls3; 
    69 UIbuild(UI.lookup("test3"),&Cls3); 
     68UIbuild(UI.lookup("test3"),Cls3); 
    7069 
    7170Cls->print(); 
    7271Cls2->print(); 
    73 Cls3->print(); 
    74 return 0; 
     72Cls3->print();  
     73 
     74delete Cls; 
     75delete Cls2; 
     76delete Cls3; 
    7577}