updated group plugin to the new pikotools api (child spaces were removed)

This commit is contained in:
Tomasz Sowa 2021-06-28 20:58:39 +02:00
parent 4569198b9d
commit ba60f9da8a
2 changed files with 86 additions and 95 deletions

View File

@ -59,28 +59,33 @@ void Groups::Reindex()
group_index_tab.clear();
size_t seti = 0;
pt::Space::TableType * child_table = space.find_child_space_table();
pt::Space::TableType * sets_table = space.get_table(L"sets");
if( child_table )
if( sets_table )
{
while( seti < child_table->size() )
for(size_t i = 0 ; i < sets_table->size() ; ++i)
{
pt::Space & sp = *(*child_table)[seti];
std::wstring * name = sp.get_wstr(pt::Space::child_spaces_name);
pt::Space * set = (*sets_table)[i];
const std::wstring * set_name = set->get_wstr(L"name");
pt::Space::TableType * set_groups = set->get_table(L"groups");
sort_by = set->to_wstr(L"sort_by");
sort_asc = set->is_equal(L"sort_asc", L"true");
if( name )
if( set_name && set_groups )
{
if( set_index.find(*name) == set_index.end() )
std::wstring key = set->to_wstr(L"key", L"value");
if( set_index.find(*set_name) == set_index.end() )
{
set_index[*name] = seti;
set_index[*set_name] = seti;
group_index_tab.push_back(GroupIndex());
ReindexGroups(group_index_tab.back(), sp);
ReindexGroups(group_index_tab.back(), *set_name, *set_groups, key);
seti += 1;
}
else
{
slog << logerror << "set: " << name << " already defined (skipping)" << logend;
space.remove_child_space(seti);
slog << logerror << "set: " << set_name << " already defined (skipping)" << logend;
//space.remove_child_space(seti);
}
}
}
@ -88,24 +93,19 @@ void Groups::Reindex()
}
void Groups::ReindexGroups(GroupIndex & group_index, pt::Space & set)
void Groups::ReindexGroups(GroupIndex & group_index, const std::wstring & set_name, pt::Space::TableType & groups, const std::wstring & key)
{
size_t i, v;
pt::Space::TableType * child_table = set.find_child_space_table();
if( child_table )
for(i=0 ; i < groups.size() ; ++i)
{
for( i=0 ; i < child_table->size() ; ++i )
{
pt::Space * group = (*child_table)[i];
std::wstring key = group->to_wstr(L"key", L"value");
pt::Space::TableType * group_child_table = group->find_child_space_table();
pt::Space::TableType * group = groups[i]->get_table();
if( group_child_table )
if( group )
{
for(v=0 ; v < group_child_table->size() ; )
for(v=0 ; v < group->size() ; ++v)
{
std::wstring * vali = (*group_child_table)[v]->get_wstr(key.c_str());
std::wstring * vali = (*group)[v]->get_wstr(key.c_str());
if( vali )
{
@ -114,26 +114,20 @@ void Groups::ReindexGroups(GroupIndex & group_index, pt::Space & set)
if( g == group_index.end() )
{
group_index[*vali] = i;
v += 1;
}
else
{
slog << logwarning << "set: " << group->get_child_space_name()
slog << logwarning << "set: " << set_name
<< " has a group with a duplicated value: "
<< *vali << " (skipping)" << logend;
group->remove_child_space(v);
}
}
else
{
log << log1 << "key: " << key << " was not found" << logend;
slog << logwarning << "set: " << group->get_child_space_name()
slog << logwarning << "set: " << set_name
<< " has a group without a value (skipping)" << logend;
group->remove_child_space(v);
}
}
}
@ -143,17 +137,12 @@ void Groups::ReindexGroups(GroupIndex & group_index, pt::Space & set)
}
void Groups::SortValues(pt::Space & group)
void Groups::SortValues(pt::Space::TableType & group)
{
sort_by = group.to_wstr(L"sort_by");
sort_asc = group.is_equal(L"sort_asc", L"true");
pt::Space::TableType * child_table = group.find_child_space_table();
if( !sort_by.empty() && child_table )
if( !sort_by.empty() )
{
group.to_list(L"sort", sort_value, true);
std::sort(child_table->begin(), child_table->end(), SortFunHelper(this));
//group.to_list(L"sort", sort_value, true);
std::sort(group.begin(), group.end(), SortFunHelper(this));
}
}
@ -167,20 +156,26 @@ bool Groups::SortFunHelper::operator()(pt::Space * sp1, pt::Space * sp2)
return false;
if( groups->sort_asc )
return SortValue(*val1) < SortValue(*val2);
return *val1 < *val2;
else
return SortValue(*val1) > SortValue(*val2);
return *val1 > *val2;
// CHECKME I am not sure how it was sorted, for what was SortValue(...)
// if( groups->sort_asc )
// return SortValue(*val1) < SortValue(*val2);
// else
// return SortValue(*val1) > SortValue(*val2);
}
size_t Groups::SortFunHelper::SortValue(const std::wstring & val)
{
for(size_t i=0 ; i<groups->sort_value.size() ; ++i)
if( val == groups->sort_value[i] )
return i;
return std::numeric_limits<size_t>::max();
}
//size_t Groups::SortFunHelper::SortValue(const std::wstring & val)
//{
// for(size_t i=0 ; i<groups->sort_value.size() ; ++i)
// if( val == groups->sort_value[i] )
// return i;
//
//return std::numeric_limits<size_t>::max();
//}
@ -210,18 +205,19 @@ return false;
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option)
{
pt::Space * groups = space.find_child_space(seti);
pt::Space::TableType * sets = space.get_table(L"sets");
if( groups )
if( sets && seti < sets->size() )
{
pt::Space * value = groups->find_child_space(groupi);
pt::Space::TableType * groups = (*sets)[seti]->get_table(L"groups");;
if( value )
if( groups && groupi < groups->size() )
{
pt::Space * value_child = value->find_child_space(valuei);
pt::Space::TableType * group = (*groups)[groupi]->get_table();
if( value_child )
if( group && valuei < group->size() )
{
pt::Space * value_child = (*group)[valuei];
const std::wstring * res = value_child->get_wstr(option);
if( res )
@ -242,25 +238,23 @@ const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei
size_t Groups::Size(size_t seti, size_t groupi)
{
pt::Space * groups = space.find_child_space(seti);
pt::Space::TableType * sets_table = space.get_table(L"sets");
if( groups )
if( sets_table && seti < sets_table->size() )
{
pt::Space * group = groups->find_child_space(groupi);
pt::Space::TableType * groups_table = (*sets_table)[seti]->get_table(L"groups");
if( group )
return group->child_spaces_size();
if( groups_table && groupi < groups_table->size() )
{
pt::Space * value = (*groups_table)[groupi];
return value->table_size();
}
}
return 0;
}
void Groups::Clear()
{
space.clear();
@ -269,11 +263,6 @@ void Groups::Clear()
}
}

View File

@ -88,15 +88,17 @@ private:
/*
our space:
set1 (
set1 = (
# group1
# group1 table
(
( value = "value1"
other = "foo" )
# first object
{ value = "value1"
other = "foo" }
( value = "something"
other = "x" )
# second object
{ value = "something"
other = "x" }
)
# group2
@ -104,7 +106,7 @@ private:
)
) # end of set1
) # end of set1 table
# we can have more sets
# sets should have a unique name
@ -136,20 +138,20 @@ private:
std::wstring sort_by;
bool sort_asc;
std::vector<std::wstring> sort_value;
//std::vector<std::wstring> sort_value;
struct SortFunHelper
{
Groups * groups;
SortFunHelper(Groups * pgroups) : groups(pgroups) {};
size_t SortValue(const std::wstring & val);
//size_t SortValue(const std::wstring & val);
bool operator()(pt::Space * sp1, pt::Space * sp2);
};
void ReindexGroups(GroupIndex & group_index, pt::Space & set);
void SortValues(pt::Space & group);
void ReindexGroups(GroupIndex & group_index, const std::wstring & set_name, pt::Space::TableType & groups, const std::wstring & key);
void SortValues(pt::Space::TableType & group);
};