Changeset 257
- Timestamp:
- 01/28/09 10:01:19 (16 years ago)
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libBM.h
r256 r257 26 26 27 27 //! Root class of BDM objects 28 class bdmroot{}; 28 class bdmroot{ 29 virtual void print(){} 30 }; 29 31 30 32 //! Structure of RV (used internally), i.e. expanded RVs -
bdm/stat/loggers.h
r254 r257 26 26 This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed. 27 27 */ 28 class logger {28 class logger : public bdmroot{ 29 29 protected: 30 30 //! RVs of all logged variables. -
bdm/uibuilder.cpp
r256 r257 5 5 UImap __uimap__; 6 6 7 void UIexternal::build(Setting &S, bdmroot* &result) const{7 bdmroot* UIexternal::build(Setting &S) const{ 8 8 Config C; 9 bdmroot* tmp; 9 10 try{ 10 11 C.readFile((const char*)S["filename"]); … … 14 15 try { 15 16 Setting& remS=C.lookup((const char*)S["path"]); 16 UIbuild(remS, result);17 UIbuild(remS,tmp); 17 18 } 18 19 catch (...) { it_error("External field " + string(S.getPath()) + " not valid"); 19 20 } 20 21 return tmp; 21 22 }; 22 23 UIREGISTER(UIexternal); 23 24 24 void UIinternal::build(Setting &S, bdmroot* &result) const{ 25 bdmroot* UIinternal::build(Setting &S) const{ 26 bdmroot* tmp; 25 27 try { 26 28 Setting* Stmp = &S; 27 29 do {Stmp=&(Stmp->getParent());} while (!Stmp->isRoot()); 28 30 Setting& intS=Stmp->lookup((const char*)S["path"]); 29 UIbuild(intS, result);31 UIbuild(intS,tmp); 30 32 } 31 33 catch (...) { it_error("Internal field " + string(S.getPath()) + " not valid"); 32 34 } 33 35 return tmp; 34 36 }; 35 37 UIREGISTER(UIinternal); -
bdm/uibuilder.h
r256 r257 76 76 }; 77 77 public: 78 //!Constructor needs to be run only once via REGISTERUI78 //!Constructor needs to be run only once macro UIREGISTER 79 79 UIbuilder(const string &typ){__uimap__.insert(make_pair(typ,this));} 80 80 //! Function building the computational object 81 virtual void build(Setting &S, bdmroot* &result) const =0;81 virtual bdmroot* build(Setting &S) const =0; 82 82 }; 83 83 … … 85 85 public: 86 86 UIexternal():UIbuilder("external"){} 87 void build(Setting &S, bdmroot* &result) const;87 bdmroot* build(Setting &S) const; 88 88 }; 89 89 … … 91 91 public: 92 92 UIinternal():UIbuilder("internal"){} 93 void build(Setting &S, bdmroot* &result) const;93 bdmroot* build(Setting &S) const; 94 94 }; 95 95 96 //! Prototype of a UI builder. Return value is by the second argument since it allows some type of type checking.96 //! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast. 97 97 template<class T> 98 98 void UIbuild(Setting &S, T* &ret){ 99 99 CHECK_UITYPE(S,TypeGroup); 100 T* tmp;101 100 // Check if field "type" is present, if not it is not a valid UI 102 101 it_assert_debug(S.exists("type"), string(S.getPath())+" is not a valid UI!"); 103 102 104 const string typ=S["type"]; 105 103 const string typ=S["type"]; 106 104 // Find "type" in list of registred UI builders 107 105 UImap::const_iterator iter = __uimap__.find( typ ); 108 106 if( iter == __uimap__.end()) { 109 cout << "UI error" << endl;110 107 it_error("UI of type \"" + typ + "\" is not registered!"); 111 108 } 112 109 113 const UIbuilder* is= iter->second;114 110 //BUILD the result 115 is->build(S,(bdmroot*&)(tmp)); 116 // make assignment 117 ret=tmp; 111 ret = dynamic_cast<T*>(iter->second->build(S)); 112 }; 113 114 //! Auxiliary function allowing recursivity in S 115 template<class T> 116 void UIcall(Setting &S, void (*func)(Setting&, T), T Tmp ){ 117 CHECK_UITYPE(S,TypeGroup); 118 // Check if field "type" is present, if not it is not a valid UI 119 it_assert_debug(S.exists("type"), string(S.getPath())+" is not a valid UI!"); 120 121 const string typ=S["type"]; 122 if(typ=="internal"){ 123 try { 124 Setting* Stmp = &S; 125 do {Stmp=&(Stmp->getParent());} while (!Stmp->isRoot()); 126 Setting& intS=Stmp->lookup((const char*)S["path"]); 127 func(intS, Tmp); // <======== calling UIset 128 return; 129 } 130 catch (...) { it_error("Internal field " + string(S.getPath()) + " not valid"); 131 } 132 } 133 if(typ=="extern"){ 134 Config C; 135 bdmroot* tmp; 136 try{C.readFile((const char*)S["filename"]);} catch (...){ 137 it_error("File " + string((const char*)S["filename"]) + " not found or broken"); 138 } 139 try {func(C.lookup((const char*)S["path"]), Tmp);} catch (...) { //<=========== calling UIset 140 it_error("External field " + string(S.getPath()) + " not valid"); 141 } 142 return; 143 } 144 145 // v======================= calling final set 146 func(S, Tmp); 118 147 }; 119 148 -
pmsm/CMakeLists.txt
r250 r257 30 30 EXEC (mpf_load pmsmsim) 31 31 32 #EXEC (sim pmsmsim config++)32 EXEC (sim pmsmsim) 33 33 EXEC (sim_var pmsmsim) 34 34 EXEC (sim_var_arx pmsmsim) -
pmsm/sim.cpp
r254 r257 11 11 */ 12 12 13 #include < config/uibuilder.h>13 #include <uibuilder.h> 14 14 #include <stat/libDS.h> 15 15 #include "pmsmDS.h" 16 16 17 #include <stat/loggers_ui.h> 18 17 19 using namespace bdm; 18 20 int main() { 19 UIFile F("sim. bdm");21 UIFile F("sim.txt"); 20 22 21 23 logger* L; 22 UIbuild(F.lookup("logger"), &L);24 UIbuild(F.lookup("logger"),L); 23 25 pmsmDS * DS; 24 UIbuild(F.lookup("system"), &DS);26 UIbuild(F.lookup("system"),DS); 25 27 int Ndat; 26 28 F.lookupValue("ndat",Ndat); … … 36 38 37 39 L->finalize(); 40 41 delete L; 42 delete DS; 38 43 return 0; 39 44 } -
tests/UI/UIbuilder_test.cpp
r256 r257 21 21 public: 22 22 UItest():UIbuilder("test"){} 23 void build(Setting &S, bdmroot* &ret) const{23 bdmroot* build(Setting &S) const{ 24 24 try{ 25 25 int a=S["a"]; … … 27 27 S.lookupValue("S",St); 28 28 cls* tmp = new cls(a,St); 29 ret =tmp;29 return tmp; 30 30 } 31 31 catch (...){ … … 38 38 public: 39 39 UItest2():UIbuilder("test2"){} 40 void build(Setting &S, bdmroot* &ret) const{40 bdmroot* build(Setting &S) const{ 41 41 try{ 42 42 int a=S["a"]; 43 43 string St; 44 44 S.lookupValue("S",St); 45 cls* tmp = new cls2(a,St); 46 ret=tmp; 45 return new cls2(a,St); 47 46 } 48 47 catch (...){