From 75426d88281b015f0aa6d203e9cb66c250ba06e0 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 15 Aug 2003 05:40:01 +0000 Subject: [PATCH] Added a basic string widget. --- Makefile | 6 +++--- main.cpp | 17 +++++++++++++++-- string.cpp | 35 +++++++++++++++++++++++++++++++++++ string.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 string.cpp create mode 100644 string.h diff --git a/Makefile b/Makefile index c5a5901..402293b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -#CPPFLAGS=-g3 -Wall -DDEBUG -CPPFLAGS=-O3 -Wall +CPPFLAGS=-g3 -Wall -DDEBUG +#CPPFLAGS=-O3 -Wall -TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o +TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o all: main diff --git a/main.cpp b/main.cpp index b76d296..80de24d 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include "hit.h" #include "ghit.h" #include "chit.h" +#include "string.h" using namespace std; using namespace bife; @@ -38,7 +39,7 @@ int main(void) { cout << "CHIT example:" << endl; cout << "=============" << endl; - CHIT c("././././././", ".tpl.html"); + CHIT chit("././././././", ".tpl.html"); const int n = 65; for (int i = n; i < (n+10); i++) { stringstream ssi, ssc; @@ -46,6 +47,18 @@ int main(void) { ssc << char(i); vars["NOMBRE"] = "Chit gay " + ssc.str(); vars["EDAD"] = ssi.str(); - cout << indent << c.parse("test", vars) << endl; + cout << indent << chit.parse("test", vars) << endl; } + + cout << "bife::String example:" << endl; + cout << "=====================" << endl; + string s = "std::string"; + String a("Un string"); + String b = "Otro string"; + //String c = s; + cout << "s: '" << s << "' - " + << "a: '" << a << "' - " + << "b: '" << b << endl; + cout << "a.render(): '" << a.render(chit) << "' - " + << "b.render(): '" << b.render(chit) << endl; } diff --git a/string.cpp b/string.cpp new file mode 100644 index 0000000..7c76f56 --- /dev/null +++ b/string.cpp @@ -0,0 +1,35 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#include "string.h" +#include + +using std::stringstream; +using namespace bife; + +#ifdef DEBUG +#include +using std::cerr; +using std::endl; +#endif +/* +String::String(void) { +#ifdef DEBUG + cerr << "In String::String()." << endl; +#endif +}*/ + +String::String(const char* str): string(str) { +#ifdef DEBUG + cerr << "In String::String('" << str << "')." << endl; +#endif +} + +String::~String(void) { +#ifdef DEBUG + cerr << "In String destructor." << endl; +#endif +} + +string String::render(HIT& tpl) { + return string(this->c_str()); +} diff --git a/string.h b/string.h new file mode 100644 index 0000000..935369c --- /dev/null +++ b/string.h @@ -0,0 +1,51 @@ +// vim: set expandtab tabstop=4 shiftwidth=4: + +#ifndef BIFE_STRING_H +#define BIFE_STRING_H + +#include "hit.h" +#include "hash.h" +#include "widget.h" +#include + +namespace bife { + + using std::string; + + /** + * Base String Class. + * + * @todo + */ + class String: public Widget, public string { + // Methods. + public: + /** + * Constructor. + */ + //String(void); + + /** + * Constructor. + * + * @param attrs String attributes. + */ + String(const char*); + + /** + * Destructor. + */ + virtual ~String(void); + + /** + * Renders the String using a HIT template. + * + * @param hit HIT template to use to render de String. + * @return Rendered String. + */ + virtual string render(HIT&); + }; + +} + +#endif -- 2.43.0