]> git.llucax.com Git - software/bife/bife++.git/commitdiff
Added initial Widget, Container and Fallback implementation.
authorLeandro Lucarella <llucax@gmail.com>
Wed, 13 Aug 2003 06:52:06 +0000 (06:52 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 13 Aug 2003 06:52:06 +0000 (06:52 +0000)
Makefile
container.cpp [new file with mode: 0644]
container.h [new file with mode: 0644]
fallback.cpp [new file with mode: 0644]
fallback.h [new file with mode: 0644]
widget.cpp [new file with mode: 0644]
widget.h [new file with mode: 0644]

index 70a59e603cc9660d5ac4febdeaadfaf045d68c00..c5a5901b48d918a480bbbe135e301a784f0bcc85 100644 (file)
--- 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
 
 
 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 (file)
index 0000000..8cfa82b
--- /dev/null
@@ -0,0 +1,68 @@
+// 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();
+}
diff --git a/container.h b/container.h
new file mode 100644 (file)
index 0000000..41ac0a6
--- /dev/null
@@ -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 <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
diff --git a/fallback.cpp b/fallback.cpp
new file mode 100644 (file)
index 0000000..e8e1bbc
--- /dev/null
@@ -0,0 +1,64 @@
+// 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();
+}
+*/
diff --git a/fallback.h b/fallback.h
new file mode 100644 (file)
index 0000000..a754ac1
--- /dev/null
@@ -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 <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
diff --git a/widget.cpp b/widget.cpp
new file mode 100644 (file)
index 0000000..67853b5
--- /dev/null
@@ -0,0 +1,43 @@
+// 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();
+}
+
diff --git a/widget.h b/widget.h
new file mode 100644 (file)
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 <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