From 22a67f92aba3f9c1f24b91f19ef7ed0361fb010b Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 13 Aug 2003 06:52:06 +0000 Subject: [PATCH] Added initial Widget, Container and Fallback implementation. --- Makefile | 13 ++++++-- container.cpp | 68 +++++++++++++++++++++++++++++++++++++++++ container.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ fallback.cpp | 64 +++++++++++++++++++++++++++++++++++++++ fallback.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ widget.cpp | 43 ++++++++++++++++++++++++++ widget.h | 59 ++++++++++++++++++++++++++++++++++++ 7 files changed, 409 insertions(+), 2 deletions(-) create mode 100644 container.cpp create mode 100644 container.h create mode 100644 fallback.cpp create mode 100644 fallback.h create mode 100644 widget.cpp create mode 100644 widget.h diff --git a/Makefile b/Makefile index 70a59e6..c5a5901 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,14 @@ -CPPFLAGS=-g3 + +#CPPFLAGS=-g3 -Wall -DDEBUG +CPPFLAGS=-O3 -Wall + +TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o all: main -main: hit.o ghit.o chit.o +main: $(TAGETS) + +hit.o: hit.h hit.cpp + +clean: + @rm -f *.o main diff --git a/container.cpp b/container.cpp new file mode 100644 index 0000000..8cfa82b --- /dev/null +++ b/container.cpp @@ -0,0 +1,68 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#include "container.h" +#include + +using std::stringstream; + +#ifdef DEBUG +#include +using std::cerr; +using std::endl; +#endif + +Container::Container(void) { +#ifdef DEBUG + cerr << "In Container::Container();" << endl; +#endif +} + +Container::Container(Hash attrs): Widget(attrs) { +#ifdef DEBUG + cerr << "In Container::Container(attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Container::Container(Hash attrs, Widget& content): Widget(attrs) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Container::Container(attrs = {" /* TODO << attrs */ + << "}, content = {" /* TODO << content */ << "});" << endl; +#endif +} + +Container::Container(Widget& content, Hash attrs): Widget(attrs) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Container::Container(content = {" /* TODO << content */ + << "}, attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Container::~Container(void) { +#ifdef DEBUG + cerr << "In Container destructor." << endl; +#endif +} + +/* +string Container::render(HIT& hit) { + stringstream out; + out << "container = attributes: ["; + for (Hash::iterator i = attrs.begin(); i != --attrs.end(); i++) { + out << i->first << ": " << i->second << ", "; + } + Hash::iterator i = --attrs.end(); + out << i->first << ": " << i->second << "] "; + out << "content: [" << renderContent(hit) << "]"; + return out.str(); +} +*/ + +string Container::renderContent(HIT& hit) { + stringstream out; + for (Content::iterator i = content.begin(); i != content.end(); i++) { + out << i->render(hit); + } + return out.str(); +} diff --git a/container.h b/container.h new file mode 100644 index 0000000..41ac0a6 --- /dev/null +++ b/container.h @@ -0,0 +1,81 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#ifndef BIFE_CONTAINER_H +#define BIFE_CONTAINER_H + +#include "widget.h" +#include "hit.h" +#include "hash.h" +#include +#include + +using std::string; + +/** + * Base Container Class. + * + * @todo + */ +class Container: public Widget { + // Typedefs + protected: + typedef std::vector Content; + + // Attributes. + protected: + /// Content. + Content content; + + // Methods. + public: + /** + * Constructor. + */ + Container(void); + + /** + * Constructor. + * + * @param attrs Widget attributes. + */ + Container(Hash); + + /** + * Constructor. + * + * @param attrs Widget attributes. + * @param content Content of the widget. + */ + Container(Hash, Widget&); + + /** + * Constructor. + * + * @param content Content of the widget. + * @param attrs Widget attributes. + */ + Container(Widget&, Hash); + + /** + * Destructor. + */ + virtual ~Container(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&) = 0; + + /** + * Renders the widget using a HIT template. + * + * @param hit HIT template to use to render de widget. + * @return Rendered widget. + */ + string renderContent(HIT&); +}; + +#endif diff --git a/fallback.cpp b/fallback.cpp new file mode 100644 index 0000000..e8e1bbc --- /dev/null +++ b/fallback.cpp @@ -0,0 +1,64 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#include "fallback.h" +#include + +using std::stringstream; + +#ifdef DEBUG +#include +using std::cerr; +using std::endl; +#endif + +Fallback::Fallback(string name) { + root = NULL; +#ifdef DEBUG + cerr << "In Fallback::Fallback(name = '" << name << "');" << endl; +#endif +} + +Fallback::Fallback(string name, Hash attrs): Container(attrs) { +#ifdef DEBUG + cerr << "In Fallback::Fallback(name = '" << name + << "', attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Fallback::Fallback(string name, Hash attrs, Widget& content): Container(attrs) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Fallback::Fallback(name = '" << name + << "', attrs = {" /* TODO << attrs */ + << "}, content = {" /* TODO << content */ << "});" << endl; +#endif +} + +Fallback::Fallback(string name, Widget& content, Hash attrs): Container(attrs) { + // FIXME - this->content.push_back(content); +#ifdef DEBUG + cerr << "In Fallback::Fallback(name = '" << name + << "', content = {" /* TODO << content */ + << "}, attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Fallback::~Fallback(void) { +#ifdef DEBUG + cerr << "In Fallback destructor." << endl; +#endif +} + +/* +string Fallback::render(HIT& hit) { + stringstream out; + out << "Fallback = attributes: ["; + for (Hash::iterator i = attrs.begin(); i != --attrs.end(); i++) { + out << i->first << ": " << i->second << ", "; + } + Hash::iterator i = --attrs.end(); + out << i->first << ": " << i->second << "] "; + out << "content: [" << renderContent(hit) << "]"; + return out.str(); +} +*/ diff --git a/fallback.h b/fallback.h new file mode 100644 index 0000000..a754ac1 --- /dev/null +++ b/fallback.h @@ -0,0 +1,83 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#ifndef BIFE_FALLBACK_H +#define BIFE_FALLBACK_H + +#include "container.h" +#include "widget.h" +#include "hit.h" +#include "hash.h" +#include +#include + +using std::string; + +/** + * Base Fallback Widget. + * + * @todo + */ +class Fallback: public Container { + // Attributes. + protected: + /// Root widget. + Widget* root; + + // Methods. + public: + /** + * Constructor. + * + * @param name Name of the widget. + */ + Fallback(string); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param attrs Widget attributes. + */ + Fallback(string, Hash); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param attrs Widget attributes. + * @param content Content of the widget. + */ + Fallback(string, Hash, Widget&); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + */ + Fallback(string, Widget&); + + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + * @param attrs Widget attributes. + */ + Fallback(string, Widget&, Hash); + + /** + * Destructor. + */ + virtual ~Fallback(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&) = 0; +}; + +#endif diff --git a/widget.cpp b/widget.cpp new file mode 100644 index 0000000..67853b5 --- /dev/null +++ b/widget.cpp @@ -0,0 +1,43 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#include "widget.h" +#include + +using std::stringstream; + +#ifdef DEBUG +#include +using std::cerr; +using std::endl; +#endif + +Widget::Widget(void) { +#ifdef DEBUG + cerr << "In Widget::Widget();" << endl; +#endif +} + +Widget::Widget(Hash attrs): attrs(attrs) { +#ifdef DEBUG + cerr << "In Widget::Widget(attrs = {" /* TODO << attrs */ << "});" << endl; +#endif +} + +Widget::~Widget(void) { +#ifdef DEBUG + cerr << "In Widget destructor." << endl; +#endif +} + +Widget::operator string(void) const { + stringstream out; + out << string("widget = attributes: ["); + Hash::const_iterator last = attrs.end(); + last--; + for (Hash::const_iterator i = attrs.begin(); i != attrs.end(); i++) { //last; i++) { + out << i->first << ": " << i->second << ", "; + } + out << last->first << ": " << last->second << "]"; + return out.str(); +} + diff --git a/widget.h b/widget.h new file mode 100644 index 0000000..95bc28d --- /dev/null +++ b/widget.h @@ -0,0 +1,59 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#ifndef BIFE_WIDGET_H +#define BIFE_WIDGET_H + +#include "hit.h" +#include "hash.h" +#include + +using std::string; + +/** + * Base Widget Class. + * + * @todo + */ +class Widget { + // Attributes. + public: + /// Widget attributes. + Hash attrs; + + // Methods. + public: + /** + * Constructor. + */ + Widget(void); + + /** + * Constructor. + * + * @param attrs Widget attributes. + */ + Widget(Hash); + + /** + * Destructor. + */ + virtual ~Widget(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&) = 0; + + /** + * Renders the widget using a HIT template. + * + * @param hit HIT template to use to render de widget. + * @return Rendered widget. + */ + virtual operator string(void) const; +}; + +#endif -- 2.43.0