/* * This file is a part of EZC -- Easy templating in C++ * and is distributed under the (new) BSD licence. * Author: Tomasz Sowa */ /* * 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. */ /* * version 0.9.0 * */ #ifndef headerfileezc #define headerfileezc #include #include #include #include #include #include #include namespace Ezc { std::string CreateMsg(const char * type, const char * arg = 0); void SplitUnixDirectory(const char * name, std::string & dir, std::string & file); void SplitUnixDirectory(const std::string & name, std::string & dir, std::string & file); class Pattern { public: void ParseFile(const 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, item_comment }; ItemType type; std::string text; std::vector item_table; std::vector 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 ReadDirectiveComment(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 { UserFunction user_function; int iter; }; typedef std::map UserInfoTable; public: void Insert(const std::string & key, UserFunction ufunction); std::string & Generate(Pattern & data); std::string & String(); void Clear(); private: UserInfoTable user_info_table; std::string otext; 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); }; // Generator } // namespace Ezc #endif