From 8d8860f5938a20b3dbf1011b6b274291c13eeade Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 15 Aug 2003 05:42:35 +0000 Subject: [PATCH] Added a fallback implementation. --- Makefile | 2 +- translate.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++ translate.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 translate.cpp create mode 100644 translate.h diff --git a/Makefile b/Makefile index 402293b..e03f97c 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CPPFLAGS=-g3 -Wall -DDEBUG #CPPFLAGS=-O3 -Wall -TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o +TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o translate.o all: main diff --git a/translate.cpp b/translate.cpp new file mode 100644 index 0000000..d3bb41b --- /dev/null +++ b/translate.cpp @@ -0,0 +1,74 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#include "translate.h" +#include + +using std::stringstream; +using namespace bife; + +#ifdef DEBUG +#include +using std::cerr; +using std::endl; +#endif + +Translate::Translate(const string& name): Fallback(name) { +#ifdef DEBUG + cerr << "In Translate::Translate(name = '" << name << "');" << endl; +#endif +} + +Translate::Translate(const string& name, const Hash& attrs): Fallback(name, attrs) { +#ifdef DEBUG + cerr << "In Translate::Translate(name = '" << name + << "', attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Translate::Translate(const string& name, const Hash& attrs, Widget& content): + Fallback(name, attrs, content) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Translate::Translate(name = '" << name + << "', attrs = {" /* TODO << attrs */ + << "}, content = {" /* TODO << content */ << "});" << endl; +#endif +} + +Translate::Translate(const string& name, Widget& content, const Hash& attrs): + Fallback(name, content, attrs) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Translate::Translate(name = '" << name + << "', content = {" /* TODO << content */ + << "}, attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Translate::~Translate(void) { +#ifdef DEBUG + cerr << "In Translate destructor." << endl; +#endif +} + +string Translate::render(HIT& tpl) { + stringstream out; + if (false /* TODO tpl.exists(name, '')*/) { + Hash a = attrs; + a["CONTENT"] = renderContent(tpl); + out << tpl.parse(name, attrs /* TODO ,"", "" */); + } else { + out << "<" << name; + for (Hash::iterator i = attrs.begin(); i != attrs.end(); i++) { + out << " " << i->first << "=\"" << i->second << "\""; + } + string c = renderContent(tpl); + if (c.empty()) { + out << " />"; + } else { + out << ">" << c << ""; + } + } + return out.str(); +} + diff --git a/translate.h b/translate.h new file mode 100644 index 0000000..8a11499 --- /dev/null +++ b/translate.h @@ -0,0 +1,82 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#ifndef BIFE_TRANSLATE_H +#define BIFE_TRANSLATE_H + +#include "fallback.h" +#include "widget.h" +#include "hit.h" +#include "hash.h" +#include +#include + +namespace bife { + + using std::string; + + /** + * Base Translate Widget. + * + * @todo + */ + class Translate: public Fallback { + // Methods. + public: + /** + * Constructor. + * + * @param name Name of the widget. + */ + Translate(const string&); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param attrs Widget attributes. + */ + Translate(const string&, 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&); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + */ + Translate(const string&, Widget&); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + * @param attrs Widget attributes. + */ + Translate(const string&, Widget&, const Hash&); + + /** + * Destructor. + */ + virtual ~Translate(void); + + /** + * Renders the widget using a HIT template. + * + * @param hit HIT template to use to render de widget. + * @return Rendered widget. + */ + virtual string render(HIT&); + }; + +} + +#endif -- 2.43.0