added: Pattern::CacheFunctions(Functions<StreamType> & fun)
you can cache all functions (their addresses) in the pattern
changed: now we have two methods for generating content:
Generator<>::Generate(StreamType & o, Pattern & p, Functions<StreamType> & f);
similar like previous -- Set(...) methods were removed as well as the second ctor
and a second one:
Generate(StreamType & o, Pattern & p);
without functions, the functions should be cached beforehand in the pattern
by calling CacheFunctions() method on the pattern
this gives O(1) complexity when looking for a specific function
previously was O(log n)
git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@329 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
+37
-34
@@ -38,9 +38,6 @@
|
||||
|
||||
#include "pattern.h"
|
||||
|
||||
#ifdef EZC_USE_WINIX_LOGGER
|
||||
#include "core/log.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Ezc
|
||||
@@ -70,6 +67,22 @@ void Pattern::Clear()
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ClearCache()
|
||||
{
|
||||
ClearCache(item_root);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ClearCache(Item & item)
|
||||
{
|
||||
for(size_t f = 0; f < item.functions.size() ; ++f)
|
||||
item.functions[f].fun_cache = 0;
|
||||
|
||||
for(size_t i = 0; i < item.item_tab.size() ; ++i)
|
||||
ClearCache(*item.item_tab[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Pattern::Directory(const char * dir, const char * dir2)
|
||||
{
|
||||
@@ -77,17 +90,17 @@ void Pattern::Directory(const char * dir, const char * dir2)
|
||||
directory2.clear();
|
||||
|
||||
if( dir )
|
||||
AssignString(dir, directory);
|
||||
UTF8ToWide(dir, directory);
|
||||
|
||||
if( dir2 )
|
||||
AssignString(dir2, directory2);
|
||||
UTF8ToWide(dir2, directory2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Pattern::Directory(const std::string & dir)
|
||||
{
|
||||
AssignString(dir, directory);
|
||||
UTF8ToWide(dir, directory);
|
||||
directory2.clear();
|
||||
}
|
||||
|
||||
@@ -95,8 +108,8 @@ void Pattern::Directory(const std::string & dir)
|
||||
|
||||
void Pattern::Directory(const std::string & dir, const std::string & dir2)
|
||||
{
|
||||
AssignString(dir, directory);
|
||||
AssignString(dir2, directory2);
|
||||
UTF8ToWide(dir, directory);
|
||||
UTF8ToWide(dir2, directory2);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +154,7 @@ void Pattern::ParseFile(const std::string & file_name)
|
||||
|
||||
void Pattern::ParseFile(const char * file_name)
|
||||
{
|
||||
AssignString(file_name, item_root.file_name);
|
||||
UTF8ToWide(file_name, item_root.file_name);
|
||||
include_level = 0;
|
||||
CreateTreeReadIncludeSkipAllowFlag(item_root);
|
||||
}
|
||||
@@ -169,7 +182,11 @@ void Pattern::ParseFile(const wchar_t * file_name)
|
||||
|
||||
void Pattern::ParseString(const char * str)
|
||||
{
|
||||
AssignString(str, string_content);
|
||||
if( input_as_utf8 )
|
||||
UTF8ToWide(str, string_content);
|
||||
else
|
||||
AssignString(str, string_content);
|
||||
|
||||
ParseString(string_content.c_str());
|
||||
string_content.clear();
|
||||
}
|
||||
@@ -243,16 +260,16 @@ void Pattern::UTF8(bool utf8)
|
||||
|
||||
void Pattern::SetCommentary(const char * com_start, const char * com_stop)
|
||||
{
|
||||
AssignString(com_start, commentary_start);
|
||||
AssignString(com_stop, commentary_stop);
|
||||
UTF8ToWide(com_start, commentary_start);
|
||||
UTF8ToWide(com_stop, commentary_stop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Pattern::SetCommentary(const std::string & com_start, const std::string & com_stop)
|
||||
{
|
||||
AssignString(com_start, commentary_start);
|
||||
AssignString(com_stop, commentary_stop);
|
||||
UTF8ToWide(com_start, commentary_start);
|
||||
UTF8ToWide(com_stop, commentary_stop);
|
||||
}
|
||||
|
||||
|
||||
@@ -275,23 +292,6 @@ void Pattern::SetCommentary(const std::wstring & com_start, const std::wstring &
|
||||
|
||||
|
||||
|
||||
|
||||
void Pattern::CreateMsg(std::wstring & out, const char * type, const char * arg)
|
||||
{
|
||||
out = commentary_start;
|
||||
out += L"Ezc: ";
|
||||
AssignString(type, out, false);
|
||||
|
||||
if( arg )
|
||||
{
|
||||
out += ' ';
|
||||
AssignString(arg, out, false);
|
||||
}
|
||||
|
||||
out += commentary_stop;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateMsg(std::wstring & out, const wchar_t * type, const wchar_t * arg)
|
||||
{
|
||||
out = commentary_start;
|
||||
@@ -409,12 +409,15 @@ bool Pattern::ReadFileFromDir(const std::wstring & dir, const wchar_t * name, st
|
||||
return false;
|
||||
}
|
||||
|
||||
ReadFile(file, result);
|
||||
|
||||
#ifdef EZC_USE_WINIX_LOGGER
|
||||
log << log3 << "Ezc: read pattern: " << afile_name << logend;
|
||||
if( include_level <= 1 )
|
||||
log << log3 << "Ezc: reading pattern: " << afile_name << logend;
|
||||
else
|
||||
log << log3 << " including pattern: " << afile_name << logend;
|
||||
#endif
|
||||
|
||||
ReadFile(file, result);
|
||||
|
||||
file_name.clear();
|
||||
afile_name.clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user