completely rewritten

* Ezc is now a namespace
 * added Ezc::Pattern
 * added Ezc::Generator
added [if-one]
fixed a problem with memory lack


git-svn-id: svn://ttmath.org/publicrep/cgi/ezc/trunk@7 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2007-01-26 19:29:36 +00:00
parent 043a5f2131
commit e42117714a
2 changed files with 815 additions and 580 deletions

File diff suppressed because it is too large Load Diff

195
src/ezc.h
View File

@ -1,3 +1,40 @@
/*
* This file is a part of EZC -- Easy templating in C++
* and is distributed under the (new) BSD licence.
* Author: Tomasz Sowa <t.sowa@slimaczek.pl>
*/
/*
* Copyright (c) 2007, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name Tomasz Sowa nor the names of contributors to this
* project may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef headerfileezc
#define headerfileezc
@ -10,16 +47,100 @@
#include <cstring>
class Ezc
namespace Ezc
{
std::string CreateMsg(const char * type, const char * arg = 0);
class Pattern
{
public:
struct Info
void ParseFile(std::string file_name);
void ParseFile(const char * file_name);
void Directory(const char * d);
void Directory(const std::string & d);
struct Item
{
enum ItemType
{
item_none, item_container, item_text, item_ifany, item_for, item_else,
item_end, item_err, item_normal, item_ifindex, item_include, item_is, item_ifone
};
ItemType type;
std::string text;
std::vector<Item*> item_table;
std::vector<std::string> directives;
Item();
Item(const Item & i);
Item & operator=(const Item & i);
void CopyItemTable(const Item & i);
~Item();
Item * AddItem(const Item * porg = 0);
Item * AddItem(const Item & porg);
void ClearItems();
ItemType LastItemType();
void DeleteLastItem();
void Clear();
};
Item item_root;
private:
const char * itext;
std::string directory;
bool CheckFileName(const char * name);
std::string ReadFile(const char * name);
int ReadCharInText();
void SkipWhiteCharacters();
std::string ReadDirective();
std::string ReadString();
std::string ReadDirectiveOrString();
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
void ReadDirectiveIfany(Item & item);
void ReadDirectiveIfone(Item & item);
void ReadDirectiveIs(Item & item);
void ReadDirectiveIfindex(Item & item);
void ReadDirectiveFor(Item & item);
void ReadDirectiveInclude(Item & item);
void CreateTreeReadItemDirective(Item & item);
void CreateTreeReadItemText(Item & item);
bool CreateTreeReadItem(Item & item);
void CreateTreeReadIf(Item & item);
void CreateTreeReadFor(Item & item);
void CreateTree(Item & item);
void CreateTreeReadInclude(Item & item);
}; // Pattern
struct Info
{
std::string text;
bool result;
int iter;
};
Info();
};
class Generator
{
private:
typedef void (*UserFunction)(Info &);
struct UserInfo
@ -30,64 +151,34 @@ public:
typedef std::map<std::string, UserInfo> UserInfoTable;
UserInfoTable user_info_table;
public:
Ezc();
void Init();
void CreateTree(const char * file);
std::string MakeText();
void Insert(const std::string & key, UserFunction ufunction);
std::string & Generate(Pattern & data);
std::string & String();
void Clear();
private:
struct Item
{
enum ItemType
{
item_none, item_container, item_text, item_ifany, item_for, item_else,
item_end, item_err, item_normal, item_ifindex, item_include, item_is
};
ItemType type;
std::string text;
std::vector<Item*> item_table;
UserInfoTable user_info_table;
std::string otext;
std::vector<std::string> directives;
Item();
~Item();
Item * AddItem(const Item & porg);
void ReadFile(const char * name, std::string & result);
void SkipWhiteCharacters(const char * & itext);
void ReadDirective(const char * & itext, std::string & directive);
void ReadString(const char * & itext, std::string & directive);
void ReadDirectiveOrString(const char * & itext, std::string & directive);
void ClearTable();
ItemType LastItemType();
bool ReadChar(const char * & itext, char & result);
void CreateTreeReadItemDirectiveCheckEnding(const char * & itext);
void CreateTreeReadItemDirective(const char * & itext);
void CreateTreeReadItemText(const char * & itext);
bool CreateTreeReadItem(const char * & itext);
void CreateTreeReadIf(const char * & itext);
void CreateTreeReadFor(const char * & itext);
bool CreateTreeReadDeleteLastEndItem();
void CreateTreeReadInclude();
void CreateTree(const char * & itext);
bool Find(const std::string & key, UserInfo ** user_info);
void MakeTextIf_go(Pattern::Item & item, bool result);
bool MakeTextIfindexnumber(Pattern::Item & item, UserInfo * user_info, bool & result);
void MakeTextIfany(Pattern::Item & item);
void MakeTextIfone(Pattern::Item & item);
void MakeTextIfindex(Pattern::Item & item);
void MakeTextFor(Pattern::Item & item);
void MakeTextContainer(Pattern::Item & item);
void MakeTextNormal(Pattern::Item & item);
void MakeTextIs(Pattern::Item & item);
void MakeText(Pattern::Item & item);
void MakeTextIfany(std::string & otext, UserInfoTable & user_info_table);
void MakeTextIfindex(std::string & otext, UserInfoTable & user_info_table);
void MakeTextFor(std::string & otext, UserInfoTable & user_info_table);
void MakeTextContainer(std::string & otext, UserInfoTable & user_info_table);
void MakeTextMsgCantFind(std::string & otext, std::string & key);
void MakeTextNormal(std::string & otext, UserInfoTable & user_info_table);
void MakeTextIs(std::string & otext, UserInfoTable & user_info_table);
void MakeText(std::string & otext,UserInfoTable & user_info_table);
};
}; // Generator
Item item_root;
std::string input;
std::string output;
};
} // namespace Ezc
#endif