winix/plugins/groupitem/groups.cpp

120 lines
1.7 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "groups.h"
#include "core/log.h"
namespace GroupItem
{
size_t Groups::AddGroup()
{
groups_tab.push_back(paths_names.size());
return groups_tab.size()-1;
}
void Groups::AddPath(const std::wstring & path)
{
if( groups_tab.empty() )
{
log << log1 << "GroupItem: cannot add a path (there are not any groups)" << logend;
return;
}
size_t group_index = groups_tab.size()-1;
std::pair<PathsMap::iterator, bool> res = paths_map.insert(std::make_pair(path, group_index));
if( !res.second )
return;
paths_names.push_back(&(res.first->first));
}
size_t Groups::Find(const std::wstring & path)
{
log << "mapa: " << logend;
PathsMap::iterator a = paths_map.begin();
for( ; a != paths_map.end() ; ++a )
{
log << a->first << " -> " << a->second << logend;
}
PathsMap::iterator i = paths_map.find(path);
if( i == paths_map.end() )
return groups_tab.size();
return i->second;
}
size_t Groups::Size()
{
return groups_tab.size();
}
size_t Groups::GroupSize(size_t group_index)
{
if( group_index >= groups_tab.size() )
return 0;
if( group_index+1 == groups_tab.size() )
return paths_names.size() - groups_tab[group_index];
return groups_tab[group_index+1] - groups_tab[group_index];
}
const std::wstring & Groups::GroupPath(size_t group_index, size_t path_index)
{
if( group_index >= groups_tab.size() )
return empty_str;
size_t index = groups_tab[group_index] + path_index;
if( index >= paths_names.size() )
return empty_str;
return *paths_names[index];
}
void Groups::Clear()
{
paths_map.clear();
groups_tab.clear();
paths_names.clear();
}
}