added: Patterns class (in templates)

ezc patterns are managed by this class
added: some work in groupitem plugin (not finished yet)
changed: ConfParser can read a string from memory now
         (need some testing yet)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@757 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-08-25 23:53:49 +00:00
parent ee6500ac65
commit 5b8a9c0108
46 changed files with 2896 additions and 1715 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -11,102 +11,38 @@
#include "core/log.h"
IndexPatterns::IndexPatterns()
void IndexPatterns::SetPatterns(Patterns * ppatterns)
{
config = 0;
ezc_fun = 0;
patterns = ppatterns;
}
void IndexPatterns::SetConfig(Config * pconfig)
{
config = pconfig;
}
void IndexPatterns::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
{
ezc_fun = fun;
}
Ezc::Pattern * IndexPatterns::GetPattern(const std::wstring & file, size_t lang)
Ezc::Pattern * IndexPatterns::Get(const std::wstring & file, size_t lang)
{
Tab::iterator i = tab.find(file);
if( i == tab.end() )
return 0;
if( lang >= i->second.patterns.size() )
{
log << log1 << "IndexPatterns: there is no a pattern: " << file << ", for lang: " << lang << logend;
return 0;
}
return &i->second.patterns[lang];
return patterns->Get(i->second.index, lang);
}
void IndexPatterns::AddPattern(const std::wstring & file, Locale & locale, LocaleFilter & locale_filter, bool delete_white)
void IndexPatterns::Add(const std::wstring & file)
{
std::pair<Tab::iterator, bool> ins = tab.insert( std::make_pair(file, Template()) );
Tab::iterator i = ins.first;
std::pair<Tab::iterator, bool> res = tab.insert( std::make_pair(file, Template()) );
i->second.to_delete = false;
ReadPattern(i, locale, locale_filter, delete_white);
}
Template & tmpl = res.first->second;
// mark the pattern to not delete
tmpl.to_delete = false;
void IndexPatterns::AddPatternIfNotExists(const std::wstring & file, Locale & locale, LocaleFilter & locale_filter, bool delete_white)
{
Tab::iterator i = tab.find(file);
if( i != tab.end() )
{
i->second.to_delete = false;
return;
}
AddPattern(file, locale, locale_filter, delete_white);
}
void IndexPatterns::AddFileName(const std::wstring & file)
{
tab.insert( std::make_pair(file, Template()) );
}
void IndexPatterns::ReadPattern(Tab::iterator & iter, Locale & locale, LocaleFilter & locale_filter, bool delete_white)
{
size_t i;
size_t len = locale.Size();
Template & templ = iter->second;
templ.patterns.resize(len);
for(i=0 ; i<len ; ++i)
{
templ.patterns[i].UTF8(config->utf8);
templ.patterns[i].DeleteWhiteTextItems(delete_white);
templ.patterns[i].Directory(config->templates_dir, config->templates_dir_default);
templ.patterns[i].ParseFile(iter->first);
if( ezc_fun )
templ.patterns[i].CacheFunctions(*ezc_fun);
locale_filter.Filter(templ.patterns[i], locale, i);
}
}
void IndexPatterns::ReloadPatterns(Locale & locale, LocaleFilter & locale_filter, bool delete_white)
{
Tab::iterator i;
for(i=tab.begin() ; i!=tab.end() ; ++i)
ReadPattern(i, locale, locale_filter, delete_white);
if( res.second )
tmpl.index = patterns->Add(file);
}
@@ -120,6 +56,7 @@ Tab::iterator i;
}
void IndexPatterns::DeleteMarked()
{
Tab::iterator i = tab.begin();
@@ -131,7 +68,10 @@ Tab::iterator next;
++next;
if( i->second.to_delete )
{
patterns->Erase(i->second.index);
tab.erase(i);
}
i = next;
}