updated to the new pikotools api: changed the way how child_spaces are created in Space class

This commit is contained in:
2021-05-21 17:17:17 +02:00
parent fe67b5d72a
commit f1b9d1b870
9 changed files with 277 additions and 262 deletions

View File

@@ -59,24 +59,27 @@ void Groups::Reindex()
group_index_tab.clear();
size_t seti = 0;
if( space.child_spaces )
{
while( seti < space.child_spaces->size() )
{
pt::Space & sp = *(*space.child_spaces)[seti];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name )
if( child_table )
{
while( seti < child_table->size() )
{
pt::Space & sp = *(*child_table)[seti];
std::wstring * name = sp.get_wstr(pt::Space::child_spaces_name);
if( name )
{
if( set_index.find(*sp.name) == set_index.end() )
if( set_index.find(*name) == set_index.end() )
{
set_index[*sp.name] = seti;
set_index[*name] = seti;
group_index_tab.push_back(GroupIndex());
ReindexGroups(group_index_tab.back(), sp);
seti += 1;
}
else
{
slog << logerror << "set: " << sp.name << " already defined (skipping)" << logend;
slog << logerror << "set: " << name << " already defined (skipping)" << logend;
space.remove_child_space(seti);
}
}
@@ -87,25 +90,22 @@ void Groups::Reindex()
void Groups::ReindexGroups(GroupIndex & group_index, pt::Space & set)
{
size_t i, v;
size_t i, v;
pt::Space::TableType * child_table = set.find_child_space_table();
if( set.child_spaces )
if( child_table )
{
// loop through all groups in the set
for( i=0 ; i < set.child_spaces->size() ; ++i )
for( i=0 ; i < child_table->size() ; ++i )
{
pt::Space & group = *(*set.child_spaces)[i];
// !! IMPROVE ME will be safer to copy the value out
// if we used accidently the group.Text later the key
// would be overwritten
std::wstring key = group.to_wstr(L"key", L"value");
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();
if( group.child_spaces )
if( group_child_table )
{
// loop through all values in the group
for(v=0 ; v<group.child_spaces->size() ; )
for(v=0 ; v < group_child_table->size() ; )
{
std::wstring * vali = (*group.child_spaces)[v]->get_wstr(key.c_str());
std::wstring * vali = (*group_child_table)[v]->get_wstr(key.c_str());
if( vali )
{
@@ -118,24 +118,26 @@ size_t i, v;
}
else
{
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
slog << logwarning << "set: " << group->get_child_space_name()
<< " has a group with a duplicated value: "
<< *vali << " (skipping)" << logend;
group.remove_child_space(v);
group->remove_child_space(v);
}
}
else
{
log << log1 << "key: " << key << " was not found" << logend;
slog << logwarning << "set: " << set.name
<< " has a group without a value (skipping)" << logend;
slog << logwarning << "set: " << group->get_child_space_name()
<< " has a group without a value (skipping)" << logend;
group.remove_child_space(v);
group->remove_child_space(v);
}
}
}
SortValues(group);
SortValues(*group);
}
}
}
@@ -146,10 +148,12 @@ void Groups::SortValues(pt::Space & group)
sort_by = group.to_wstr(L"sort_by");
sort_asc = group.is_equal(L"sort_asc", L"true");
if( !sort_by.empty() && group.child_spaces )
pt::Space::TableType * child_table = group.find_child_space_table();
if( !sort_by.empty() && child_table )
{
group.to_list(L"sort", sort_value, true);
std::sort(group.child_spaces->begin(), group.child_spaces->end(), SortFunHelper(this));
std::sort(child_table->begin(), child_table->end(), SortFunHelper(this));
}
}
@@ -206,26 +210,27 @@ return false;
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option)
{
if( space.child_spaces && seti < space.child_spaces->size() )
pt::Space * groups = space.find_child_space(seti);
if( groups )
{
pt::Space & groups = *(*space.child_spaces)[seti];
pt::Space * value = groups->find_child_space(groupi);
if( groups.child_spaces && groupi < groups.child_spaces->size() )
if( value )
{
pt::Space & value = *(*groups.child_spaces)[groupi];
pt::Space * value_child = value->find_child_space(valuei);
if( value.child_spaces && valuei < value.child_spaces->size() )
if( value_child )
{
const std::wstring * res = (*value.child_spaces)[valuei]->get_wstr(option);
const std::wstring * res = value_child->get_wstr(option);
if( res )
return *res;
}
}
}
return empty_str;
return empty_str;
}
@@ -237,15 +242,17 @@ const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei
size_t Groups::Size(size_t seti, size_t groupi)
{
if( space.child_spaces && seti < space.child_spaces->size() )
{
pt::Space & groups = *(*space.child_spaces)[seti];
pt::Space * groups = space.find_child_space(seti);
if( groups.child_spaces && groupi < groups.child_spaces->size() )
return (*groups.child_spaces)[groupi]->child_spaces->size();
if( groups )
{
pt::Space * group = groups->find_child_space(groupi);
if( group )
return group->child_spaces_size();
}
return 0;
return 0;
}