#ifndef UIBUILD #define UIBUILD #include "libconfig/libconfig.h++" #include #include "stat/libBM.h" namespace bdm{ using namespace libconfig; using namespace std; #define CHECK_UITYPE(S,Type) it_assert_debug(S.getType()==Setting::Type, string("Wrong input path \"")+string(S.getPath())+string("\"")); #define UIREGISTER(UI) UI* UI##_global_instance = new UI(); ////////// GLOBAL VAriables class UIbuilder; //! Internal structure mapping strings to UIBuilder objects typedef map UImap; extern UImap __uimap__; class UIFile : public Config{ public: UIFile(const char * fname):Config(){ try{Config::readFile(fname);} catch (ParseException& P) { char msg[200]; sprintf(msg,"Error in file %s on line %d.", fname, P.getLine()); it_error(msg); } catch (FileIOException f) {it_error("File " + string(fname) + " not found");} } }; /*!\brief Builds computational object from a UserInfo structure Return value is a pointer to the created object (memory management issue?) */ class UIbuilder { protected: static const UIbuilder* theinstance; vec getvec ( Setting& S ) { CHECK_UITYPE(S,TypeArray); vec tmp; tmp.set_size ( S.getLength() ); for ( int i=0;i void UIbuild(Setting &S, T** ret){ CHECK_UITYPE(S,TypeGroup); T* tmp; // Check if field "type" is present, if not it is not a valid UI it_assert_debug(S.exists("type"), string(S.getPath())+" is not a valid UI!"); const string typ=S["type"]; // Find "type" in list of registred UI builders UImap::const_iterator iter = __uimap__.find( typ ); if( iter == __uimap__.end()) { it_error("UI of type \"" + typ + "\" is not registered!"); } else { const UIbuilder* is= iter->second; //BUILD the result is->build(S,reinterpret_cast(&tmp)); } // make assignment *ret=tmp; }; } #endif UIBUILD