From 993710aae023efaccb75b56eee2347c340bdc71d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 18 Aug 2003 17:31:41 +0000 Subject: [PATCH] - Normalized Fallback constructor to be the same of Widget (or Container). - Removed Fallback::Constructor prototype since now Fallback are constructed just like any regular Widget. - Renamed Widget::Constructor and Widget::Destructor in modules to bife_widget_constructor and bife_widget_destructor. - Added some more check to dynamic object creation in Parser. --- libbife/container.h | 2 -- libbife/fallback.cpp | 22 ++++++++-------------- libbife/fallback.h | 12 ++++++------ parser.cpp | 16 +++++++++++++--- translate/translate.cpp | 21 ++++++++------------- translate/translate.h | 16 +++++----------- translate/translate_loader.cpp | 17 ++++++++--------- 7 files changed, 48 insertions(+), 58 deletions(-) diff --git a/libbife/container.h b/libbife/container.h index eb2bb1f..cf9a3cc 100644 --- a/libbife/container.h +++ b/libbife/container.h @@ -11,8 +11,6 @@ namespace bife { - using std::string; - /** * Base Container Class. * diff --git a/libbife/fallback.cpp b/libbife/fallback.cpp index ca188b3..9e48e1c 100644 --- a/libbife/fallback.cpp +++ b/libbife/fallback.cpp @@ -12,36 +12,30 @@ using std::cerr; using std::endl; #endif -Fallback::Fallback(const string& name): name(name) { +Fallback::Fallback(void) { #ifdef DEBUG - cerr << "In Fallback::Fallback(name = '" << name << "');" << endl; + cerr << "In Fallback::Fallback();" << endl; #endif } -Fallback::Fallback(const string& name, const Hash& attrs): - Container(attrs), name(name) { +Fallback::Fallback(const Hash& attrs): Container(attrs) { #ifdef DEBUG - cerr << "In Fallback::Fallback(name = '" << name - << "', attrs = {" /* TODO << attrs */ << "});" << endl; + cerr << "In Fallback::Fallback(attrs = {" /* TODO << attrs */ << "});" << endl; #endif } -Fallback::Fallback(const string& name, const Hash& attrs, Widget* content): - Container(attrs, content), name(name) { +Fallback::Fallback(const Hash& attrs, Widget* content): Container(attrs, content) { // FIXME - this->content.push_back(content); #ifdef DEBUG - cerr << "In Fallback::Fallback(name = '" << name - << "', attrs = {" /* TODO << attrs */ + cerr << "In Fallback::Fallback(attrs = {" /* TODO << attrs */ << "}, content = {" /* TODO << content */ << "});" << endl; #endif } -Fallback::Fallback(const string& name, Widget* content, const Hash& attrs): - Container(content, attrs), name(name) { +Fallback::Fallback(Widget* content, const Hash& attrs): Container(content, attrs) { // FIXME - this->content.push_back(content); #ifdef DEBUG - cerr << "In Fallback::Fallback(name = '" << name - << "', content = {" /* TODO << content */ + cerr << "In Fallback::Fallback(content = {" /* TODO << content */ << "}, attrs = {" /* TODO << attrs */ << "});" << endl; #endif } diff --git a/libbife/fallback.h b/libbife/fallback.h index f772893..b27eab2 100644 --- a/libbife/fallback.h +++ b/libbife/fallback.h @@ -23,7 +23,7 @@ namespace bife { // Typedefs public: /// Fallback constructor function prototype. - typedef Fallback* Constructor(const string&, const string&, const Hash&); + //typedef Fallback* Constructor(const string&, const string&, const Hash&); // Attributes. public: @@ -37,7 +37,7 @@ namespace bife { * * @param name Name of the widget. */ - Fallback(const string&); + Fallback(void); /** * Constructor. @@ -45,7 +45,7 @@ namespace bife { * @param name Name of the widget. * @param attrs Widget attributes. */ - Fallback(const string&, const Hash&); + Fallback(const Hash&); /** * Constructor. @@ -54,7 +54,7 @@ namespace bife { * @param attrs Widget attributes. * @param content Content of the widget. */ - Fallback(const string&, const Hash&, Widget*); + Fallback(const Hash&, Widget*); /** * Constructor. @@ -62,7 +62,7 @@ namespace bife { * @param name Name of the widget. * @param content Content of the widget. */ - Fallback(const string&, Widget*); + //Fallback(Widget*); /** * Constructor. @@ -71,7 +71,7 @@ namespace bife { * @param content Content of the widget. * @param attrs Widget attributes. */ - Fallback(const string&, Widget*, const Hash&); + Fallback(Widget*, const Hash&); /** * Destructor. diff --git a/parser.cpp b/parser.cpp index 4f7ed98..b9d26e5 100644 --- a/parser.cpp +++ b/parser.cpp @@ -45,7 +45,17 @@ void Parser::on_start_element(const string& name, const AttributeMap& attrs) { if (fbClass.empty()) { throw string("Widget '") + name + "' not found and now using a fallback class."; } else { - stack.push(fbNew(fbClass, name, attrs)); + Fallback* fb; + try { + fb = dynamic_cast(fbNew(fbClass, attrs)); + if (!fb) { + throw string("Fallback widget '") + fbClass + " not found!"; + } + } catch (...) { + throw fbClass + " is not a Fallback Widget!"; + } + fb->name = name; + stack.push(fb); } } @@ -160,8 +170,8 @@ Parser::Parser(const string& fallback): fbNew(NULL), fbDel(NULL), root(NULL) { if (!dlh) { throw string("No se puede cargar el plug-in: ") + dlerror(); } - fbNew = (Fallback::Constructor*)dlsym(dlh, "fallback_constructor"); - fbDel = (Widget::Destructor*)dlsym(dlh, "widget_destructor"); + fbNew = (Widget::Constructor*)dlsym(dlh, "bife_widget_constructor"); + fbDel = (Widget::Destructor*)dlsym(dlh, "bife_widget_destructor"); if (!fbNew || !fbDel) { throw string("No se puede cargar el creador del plug-in: ") + dlerror(); } diff --git a/translate/translate.cpp b/translate/translate.cpp index b37453a..32e9315 100644 --- a/translate/translate.cpp +++ b/translate/translate.cpp @@ -12,35 +12,30 @@ using std::cerr; using std::endl; #endif -Translate::Translate(const string& name): Fallback(name) { +Translate::Translate(void) { #ifdef DEBUG - cerr << "In Translate::Translate(name = '" << name << "');" << endl; + cerr << "In Translate::Translate();" << endl; #endif } -Translate::Translate(const string& name, const Hash& attrs): Fallback(name, attrs) { +Translate::Translate(const Hash& attrs): Fallback(attrs) { #ifdef DEBUG - cerr << "In Translate::Translate(name = '" << name - << "', attrs = {" /* TODO << attrs */ << "});" << endl; + cerr << "In Translate::Translate(attrs = {" /* TODO << attrs */ << "});" << endl; #endif } -Translate::Translate(const string& name, const Hash& attrs, Widget* content): - Fallback(name, attrs, content) { +Translate::Translate(const Hash& attrs, Widget* content): Fallback(attrs, content) { // FIXME - this->content.push_back(content); #ifdef DEBUG - cerr << "In Translate::Translate(name = '" << name - << "', attrs = {" /* TODO << attrs */ + cerr << "In Translate::Translate(attrs = {" /* TODO << attrs */ << "}, content = {" /* TODO << content */ << "});" << endl; #endif } -Translate::Translate(const string& name, Widget* content, const Hash& attrs): - Fallback(name, content, attrs) { +Translate::Translate(Widget* content, const Hash& attrs): Fallback(content, attrs) { // FIXME - this->content.push_back(content); #ifdef DEBUG - cerr << "In Translate::Translate(name = '" << name - << "', content = {" /* TODO << content */ + cerr << "In Translate::Translate(content = {" /* TODO << content */ << "}, attrs = {" /* TODO << attrs */ << "});" << endl; #endif } diff --git a/translate/translate.h b/translate/translate.h index cf0da38..89a740c 100644 --- a/translate/translate.h +++ b/translate/translate.h @@ -24,44 +24,38 @@ namespace bife { public: /** * Constructor. - * - * @param name Name of the widget. */ - Translate(const string&); + Translate(void); /** * Constructor. * - * @param name Name of the widget. * @param attrs Widget attributes. */ - Translate(const string&, const Hash&); + Translate(const Hash&); /** * Constructor. * - * @param name Name of the widget. * @param attrs Widget attributes. * @param content Content of the widget. */ - Translate(const string&, const Hash&, Widget*); + Translate(const Hash&, Widget*); /** * Constructor. * - * @param name Name of the widget. * @param content Content of the widget. */ - Translate(const string&, Widget*); + //Translate(Widget*); /** * Constructor. * - * @param name Name of the widget. * @param content Content of the widget. * @param attrs Widget attributes. */ - Translate(const string&, Widget*, const Hash&); + Translate(Widget*, const Hash&); /** * Destructor. diff --git a/translate/translate_loader.cpp b/translate/translate_loader.cpp index d59f8d2..9dd4448 100644 --- a/translate/translate_loader.cpp +++ b/translate/translate_loader.cpp @@ -14,19 +14,18 @@ using bife::Hash; using std::string; /** - * Fallback constructor. + * Widget constructor. * - * @param classname Name of the class to construct. - * @param widgetname Name of the widget to construct. - * @param attrs Widget's attributes. - * @return A new Fallback widget. + * @param name Name of the widget to construct. + * @param attrs Widget's attributes. + * @return A new Widget. */ extern "C" -Fallback* fallback_constructor(const string& classname, const string& widgetname, const Hash& attrs) { - string cn = classname; +Widget* bife_widget_constructor(const string& name, const Hash& attrs) { + string cn = name; std::transform(cn.begin(), cn.end(), cn.begin(), std::tolower); if (cn == "translate") { - return new Translate(widgetname, attrs); + return new Translate(attrs); } else { return NULL; } @@ -38,6 +37,6 @@ Fallback* fallback_constructor(const string& classname, const string& widgetname * @param w The widget to destroy. */ extern "C" -void widget_destructor(Widget* w) { +void bife_widget_destructor(Widget* w) { delete w; } -- 2.43.0