From c0e82949e9242609f21b0eef63ad16d4f6462043 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 13 Aug 2003 22:46:34 +0000 Subject: [PATCH 1/1] Added namespace bife. --- chit.cpp | 2 + chit.h | 90 +++++++++++++++++++----------------- container.cpp | 1 + container.h | 122 +++++++++++++++++++++++++----------------------- fallback.cpp | 1 + fallback.h | 126 ++++++++++++++++++++++++++------------------------ ghit.cpp | 2 + ghit.h | 122 +++++++++++++++++++++++++----------------------- hash.h | 6 ++- hit.cpp | 1 + hit.h | 116 ++++++++++++++++++++++++---------------------- main.cpp | 1 + widget.cpp | 1 + widget.h | 100 ++++++++++++++++++++------------------- 14 files changed, 363 insertions(+), 328 deletions(-) diff --git a/chit.cpp b/chit.cpp index 4b09a9d..8ef60eb 100644 --- a/chit.cpp +++ b/chit.cpp @@ -2,6 +2,8 @@ #include "chit.h" +using namespace bife; + #ifdef DEBUG #include using std::cerr; diff --git a/chit.h b/chit.h index 22776f5..434e64e 100644 --- a/chit.h +++ b/chit.h @@ -7,48 +7,52 @@ #include "hash.h" #include -using std::string; - -/** - * Cache enabled GHIT. - * - * GHIT with cache capabilities added. The templates are stored in memory once - * they are readed and reused in succesive parse() calls, avoiding disc reads - * overhead. - * - * @todo See if it's really usefull, since the OS is supposed to be in charge - * of disc cache. - */ -class CHIT: public GHIT { - // Attributes. - protected: - /// Cache storage. - Hash cache; - - // Methods. - protected: - /** - * Gets cached file content. - * - * @param filename Name of the file to get the content. - * @return File content. - */ - virtual string getFileContent(string); - - public: - /** - * Constructor. - * - * @param root Root directory from where to get the templates. - * @param postfix Postfix of the template files. - * @param group Starting group. - */ - CHIT(string = string("."), string = string(".tpl"), string = string("")); - - /** - * Destructor. - */ - virtual ~CHIT(void); -}; +namespace bife { + + using std::string; + + /** + * Cache enabled GHIT. + * + * GHIT with cache capabilities added. The templates are stored in memory once + * they are readed and reused in succesive parse() calls, avoiding disc reads + * overhead. + * + * @todo See if it's really usefull, since the OS is supposed to be in charge + * of disc cache. + */ + class CHIT: public GHIT { + // Attributes. + protected: + /// Cache storage. + Hash cache; + + // Methods. + protected: + /** + * Gets cached file content. + * + * @param filename Name of the file to get the content. + * @return File content. + */ + virtual string getFileContent(string); + + public: + /** + * Constructor. + * + * @param root Root directory from where to get the templates. + * @param postfix Postfix of the template files. + * @param group Starting group. + */ + CHIT(string = string("."), string = string(".tpl"), string = string("")); + + /** + * Destructor. + */ + virtual ~CHIT(void); + }; + +} #endif diff --git a/container.cpp b/container.cpp index 8cfa82b..5375cb1 100644 --- a/container.cpp +++ b/container.cpp @@ -4,6 +4,7 @@ #include using std::stringstream; +using namespace bife; #ifdef DEBUG #include diff --git a/container.h b/container.h index 41ac0a6..9029c8a 100644 --- a/container.h +++ b/container.h @@ -9,73 +9,77 @@ #include #include -using std::string; +namespace bife { -/** - * Base Container Class. - * - * @todo - */ -class Container: public Widget { - // Typedefs - protected: - typedef std::vector Content; + using std::string; - // Attributes. - protected: - /// Content. - Content content; + /** + * Base Container Class. + * + * @todo + */ + class Container: public Widget { + // Typedefs + protected: + typedef std::vector Content; - // Methods. - public: - /** - * Constructor. - */ - Container(void); + // Attributes. + protected: + /// Content. + Content content; - /** - * Constructor. - * - * @param attrs Widget attributes. - */ - Container(Hash); + // Methods. + public: + /** + * Constructor. + */ + Container(void); - /** - * Constructor. - * - * @param attrs Widget attributes. - * @param content Content of the widget. - */ - Container(Hash, Widget&); + /** + * Constructor. + * + * @param attrs Widget attributes. + */ + Container(Hash); - /** - * Constructor. - * - * @param content Content of the widget. - * @param attrs Widget attributes. - */ - Container(Widget&, Hash); + /** + * Constructor. + * + * @param attrs Widget attributes. + * @param content Content of the widget. + */ + Container(Hash, Widget&); - /** - * Destructor. - */ - virtual ~Container(void); + /** + * Constructor. + * + * @param content Content of the widget. + * @param attrs Widget attributes. + */ + Container(Widget&, Hash); - /** - * 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; + /** + * Destructor. + */ + virtual ~Container(void); - /** - * Renders the widget using a HIT template. - * - * @param hit HIT template to use to render de widget. - * @return Rendered widget. - */ - string renderContent(HIT&); -}; + /** + * 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 index e8e1bbc..e8ed815 100644 --- a/fallback.cpp +++ b/fallback.cpp @@ -4,6 +4,7 @@ #include using std::stringstream; +using namespace bife; #ifdef DEBUG #include diff --git a/fallback.h b/fallback.h index a754ac1..58f5cd3 100644 --- a/fallback.h +++ b/fallback.h @@ -10,74 +10,78 @@ #include #include -using std::string; +namespace bife { -/** - * Base Fallback Widget. - * - * @todo - */ -class Fallback: public Container { - // Attributes. - protected: - /// Root widget. - Widget* root; + using std::string; - // Methods. - public: - /** - * Constructor. - * - * @param name Name of the widget. - */ - Fallback(string); + /** + * Base Fallback Widget. + * + * @todo + */ + class Fallback: public Container { + // Attributes. + protected: + /// Root widget. + Widget* root; - /** - * Constructor. - * - * @param name Name of the widget. - * @param attrs Widget attributes. - */ - Fallback(string, Hash); + // Methods. + public: + /** + * Constructor. + * + * @param name Name of the widget. + */ + Fallback(string); - /** - * 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 attrs Widget attributes. + */ + Fallback(string, Hash); - /** - * Constructor. - * - * @param name Name of the widget. - * @param content Content of the widget. - */ - Fallback(string, Widget&); + /** + * 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. - * @param attrs Widget attributes. - */ - Fallback(string, Widget&, Hash); + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + */ + Fallback(string, Widget&); - /** - * Destructor. - */ - virtual ~Fallback(void); + /** + * Constructor. + * + * @param name Name of the widget. + * @param content Content of the widget. + * @param attrs Widget attributes. + */ + Fallback(string, Widget&, Hash); - /** - * 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; -}; + /** + * 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/ghit.cpp b/ghit.cpp index db05833..5243932 100644 --- a/ghit.cpp +++ b/ghit.cpp @@ -2,6 +2,8 @@ #include "ghit.h" +using namespace bife; + #ifdef DEBUG #include using std::cerr; diff --git a/ghit.h b/ghit.h index 32900a6..e362728 100644 --- a/ghit.h +++ b/ghit.h @@ -7,72 +7,76 @@ #include #include -using std::string; +namespace bife { -/** - * Group enabled HIT. - * - * HIT template with groups of templates added. You can specify a template - * group. The group is used as a subdirectory in root template directory, so you - * can group templates together. The default group ('') templates are stored in - * the root directory. - */ -class GHIT: public HIT { - // Typedefs. - protected: - /// Group stack. - typedef std::stack GroupStack; + using std::string; - // Attributes. - protected: - /// Group stack. - GroupStack group; + /** + * Group enabled HIT. + * + * HIT template with groups of templates added. You can specify a template + * group. The group is used as a subdirectory in root template directory, so you + * can group templates together. The default group ('') templates are stored in + * the root directory. + */ + class GHIT: public HIT { + // Typedefs. + protected: + /// Group stack. + typedef std::stack GroupStack; - // Methods. - protected: - /** - * Gets file name based on the blockname and the group. - * - * @param blockname Name of the block to get the filename. - * @return Block's filename. - */ - virtual string getFileName(string); + // Attributes. + protected: + /// Group stack. + GroupStack group; - public: - /** - * Constructor. - * - * @param root Root directory from where to get the templates. - * @param postfix Postfix of the template files. - * @param group Starting group. - */ - GHIT(string = string("."), string = string(".tpl"), string = string("")); + // Methods. + protected: + /** + * Gets file name based on the blockname and the group. + * + * @param blockname Name of the block to get the filename. + * @return Block's filename. + */ + virtual string getFileName(string); - /** - * Destructor. - */ - virtual ~GHIT(void); + public: + /** + * Constructor. + * + * @param root Root directory from where to get the templates. + * @param postfix Postfix of the template files. + * @param group Starting group. + */ + GHIT(string = string("."), string = string(".tpl"), string = string("")); - /** - * Starts working with a new group of templates. - * - * @param group Group of templates to work with. - */ - virtual void pushGroup(string); + /** + * Destructor. + */ + virtual ~GHIT(void); - /** - * Stops working with a group of templates. - * - * @return Last template's group used. - */ - virtual string popGroup(void); + /** + * Starts working with a new group of templates. + * + * @param group Group of templates to work with. + */ + virtual void pushGroup(string); - /** - * Gets the current working group. - * - * @return Current template's group. - */ - virtual string getGroup(void); -}; + /** + * Stops working with a group of templates. + * + * @return Last template's group used. + */ + virtual string popGroup(void); + + /** + * Gets the current working group. + * + * @return Current template's group. + */ + virtual string getGroup(void); + }; + +} #endif diff --git a/hash.h b/hash.h index 08f7adb..d825bdc 100644 --- a/hash.h +++ b/hash.h @@ -6,7 +6,9 @@ #include #include -/// String hash similar to high level languages (like perl, python or php). -typedef std::map Hash; +namespace bife { + /// String hash similar to high level languages (like perl, python or php). + typedef std::map Hash; +} #endif diff --git a/hit.cpp b/hit.cpp index a9bfd66..ad99316 100644 --- a/hit.cpp +++ b/hit.cpp @@ -6,6 +6,7 @@ using std::ifstream; using std::stringbuf; +using namespace bife; #ifdef DEBUG #include diff --git a/hit.h b/hit.h index 5086127..9162460 100644 --- a/hit.h +++ b/hit.h @@ -6,67 +6,71 @@ #include "hash.h" #include -using std::string; +namespace bife { -/** - * Hooks vs IT Template Engine. - * - * Hooks vs IT (HIT) is a simple template implementation, based on hooks - * and IT template systems. - * - * @todo Implementar buffers? - */ -class HIT { - // Attributes. - public: - /// Root directory where to search for templates. - string root; - /// Postfix added to the blockname to convert it to a filename. - string postfix; - // bool search_path = false - // TODO - Para subclases - //Hash buffer; + using std::string; - // Methods. - protected: - /** - * Gets file name based on the blockname. - * - * @param blockname Name of the block to get the filename. - * @return Block's filename. - */ - virtual string getFileName(string); + /** + * Hooks vs IT Template Engine. + * + * Hooks vs IT (HIT) is a simple template implementation, based on hooks + * and IT template systems. + * + * @todo Implementar buffers? + */ + class HIT { + // Attributes. + public: + /// Root directory where to search for templates. + string root; + /// Postfix added to the blockname to convert it to a filename. + string postfix; + // bool search_path = false + // TODO - Para subclases + //Hash buffer; - /** - * Gets file content. - * - * @param filename Name of the file to get the content. - * @return File content. - */ - virtual string getFileContent(string); + // Methods. + protected: + /** + * Gets file name based on the blockname. + * + * @param blockname Name of the block to get the filename. + * @return Block's filename. + */ + virtual string getFileName(string); - public: - /** - * Constructor. - * - * @param root Root directory from where to get the templates. - * @param postfix Postfix of the template files. - */ - HIT(string = string("."), string = string(".tpl")); + /** + * Gets file content. + * + * @param filename Name of the file to get the content. + * @return File content. + */ + virtual string getFileContent(string); - /** - * Destructor. - */ - virtual ~HIT(void); + public: + /** + * Constructor. + * + * @param root Root directory from where to get the templates. + * @param postfix Postfix of the template files. + */ + HIT(string = string("."), string = string(".tpl")); - /** - * Parses a block replacing keys with values in the hash. - * - * @param blockname Name of the block to parse. - * @param vars Hash containing the variable names and their values. - * @return Parsed block with variables replaced. - */ - string parse(string, Hash&); -}; + /** + * Destructor. + */ + virtual ~HIT(void); + + /** + * Parses a block replacing keys with values in the hash. + * + * @param blockname Name of the block to parse. + * @param vars Hash containing the variable names and their values. + * @return Parsed block with variables replaced. + */ + string parse(string, Hash&); + }; + +} #endif diff --git a/main.cpp b/main.cpp index 92fbb6a..b76d296 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,7 @@ #include "chit.h" using namespace std; +using namespace bife; int main(void) { const string indent = " "; diff --git a/widget.cpp b/widget.cpp index 67853b5..46e3d2b 100644 --- a/widget.cpp +++ b/widget.cpp @@ -4,6 +4,7 @@ #include using std::stringstream; +using namespace bife; #ifdef DEBUG #include diff --git a/widget.h b/widget.h index 95bc28d..a054e20 100644 --- a/widget.h +++ b/widget.h @@ -7,53 +7,57 @@ #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; -}; +namespace bife { + + 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