-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
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#include "container.h"
+#include <sstream>
+
+using std::stringstream;
+
+#ifdef DEBUG
+#include <iostream>
+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();
+}
--- /dev/null
+// 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 <vector>
+#include <string>
+
+using std::string;
+
+/**
+ * Base Container Class.
+ *
+ * @todo
+ */
+class Container: public Widget {
+ // Typedefs
+ protected:
+ typedef std::vector<Widget> 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
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#include "fallback.h"
+#include <sstream>
+
+using std::stringstream;
+
+#ifdef DEBUG
+#include <iostream>
+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();
+}
+*/
--- /dev/null
+// 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 <vector>
+#include <string>
+
+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
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#include "widget.h"
+#include <sstream>
+
+using std::stringstream;
+
+#ifdef DEBUG
+#include <iostream>
+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();
+}
+
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#ifndef BIFE_WIDGET_H
+#define BIFE_WIDGET_H
+
+#include "hit.h"
+#include "hash.h"
+#include <string>
+
+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