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:
tomasz.sowa committed 2010-11-25 22:39:58 +00:00
1 parent 5108495540
commit 0b09b5454f
6 files changed
+195 -152

No files matched your search

+44 -3
View File
@@ -41,9 +41,13 @@
#include <string>
#include "item.h"
#include "functions.h"
#include "stringconv.h"
#include "utf8.h"
#ifdef EZC_USE_WINIX_LOGGER
#include "core/log.h"
#endif
namespace Ezc
@@ -98,14 +102,18 @@ public:
void SetCommentary(const wchar_t * com_start, const wchar_t * com_stop);
void SetCommentary(const std::wstring & com_start, const std::wstring & com_stop);
void CreateMsg(std::wstring & out, const char * type, const char * arg = 0);
void CreateMsg(std::wstring & out, const wchar_t * type, const wchar_t * arg = 0);
static bool IsWhite(wchar_t c);
Item item_root;
template<class StreamType>
void CacheFunctions(Functions<StreamType> & fun)
{
CacheFunctions(item_root, fun);
}
void ClearCache();
private:
@@ -203,6 +211,39 @@ private:
void CreateTreeReadInclude(Item & item);
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
template<class StreamType>
void CacheFunctions(Item & item, Functions<StreamType> & fun)
{
typename Functions<StreamType>::Function * ezc_fun;
for(size_t f = 0; f < item.functions.size() ; ++f)
{
if( fun.Find(item.functions[f].name, &ezc_fun) )
{
item.functions[f].fun_cache = ezc_fun;
}
else
{
item.functions[f].fun_cache = 0;
#ifdef EZC_USE_WINIX_LOGGER
log << log1 << "Ezc: unknown function: " << item.functions[f].name << logend;
#endif
}
// one exception (if_index is putting its argument on the functions stack)
if( item.type == Item::item_ifindex )
break;
}
for(size_t i = 0; i < item.item_tab.size() ; ++i)
CacheFunctions(*item.item_tab[i], fun);
}
void ClearCache(Item & item);
}; // class Pattern