2010-06-22 01:53:19 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
2010-06-22 01:53:19 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. 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.
|
|
|
|
*
|
|
|
|
* 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 HOLDER 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.
|
|
|
|
*
|
2010-06-22 01:53:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "indexpatterns.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/log.h"
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2010-11-25 23:42:24 +01:00
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
void IndexPatterns::SetPatterns(Patterns * ppatterns)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-08-26 01:53:49 +02:00
|
|
|
patterns = ppatterns;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
Ezc::Pattern * IndexPatterns::Get(const std::wstring & file, size_t lang)
|
2010-06-22 01:53:19 +02:00
|
|
|
{
|
|
|
|
Tab::iterator i = tab.find(file);
|
|
|
|
|
|
|
|
if( i == tab.end() )
|
|
|
|
return 0;
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
return patterns->Get(i->second.index, lang);
|
2010-06-22 01:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
void IndexPatterns::Add(const std::wstring & file)
|
2010-06-22 01:53:19 +02:00
|
|
|
{
|
2011-08-26 01:53:49 +02:00
|
|
|
std::pair<Tab::iterator, bool> res = tab.insert( std::make_pair(file, Template()) );
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
Template & tmpl = res.first->second;
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
// mark the pattern to not delete
|
|
|
|
tmpl.to_delete = false;
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
if( res.second )
|
|
|
|
tmpl.index = patterns->Add(file);
|
2010-06-22 01:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IndexPatterns::MarkAllToDelete()
|
|
|
|
{
|
|
|
|
Tab::iterator i;
|
|
|
|
|
|
|
|
for(i=tab.begin() ; i!=tab.end() ; ++i)
|
|
|
|
i->second.to_delete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
void IndexPatterns::DeleteMarked()
|
|
|
|
{
|
|
|
|
Tab::iterator i = tab.begin();
|
|
|
|
Tab::iterator next;
|
|
|
|
|
|
|
|
while( i != tab.end() )
|
|
|
|
{
|
|
|
|
next = i;
|
|
|
|
++next;
|
|
|
|
|
|
|
|
if( i->second.to_delete )
|
2011-08-26 01:53:49 +02:00
|
|
|
{
|
|
|
|
patterns->Erase(i->second.index);
|
2010-06-22 01:53:19 +02:00
|
|
|
tab.erase(i);
|
2011-08-26 01:53:49 +02:00
|
|
|
}
|
2010-06-22 01:53:19 +02:00
|
|
|
|
|
|
|
i = next;
|
|
|
|
}
|
|
|
|
}
|
2011-08-27 05:12:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IndexPatterns::Clear()
|
|
|
|
{
|
|
|
|
tab.clear();
|
|
|
|
}
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|