updated to the new Pikotools api (new Space struct)
This commit is contained in:
@@ -80,14 +80,14 @@ bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
|
||||
PT::Space & space = *groups.GetSpace();
|
||||
conf_parser.SetSpace(space);
|
||||
|
||||
if( conf_parser.ParseString(str) == PT::SpaceParser::ok )
|
||||
if( conf_parser.ParseSpace(str) == PT::SpaceParser::ok )
|
||||
{
|
||||
groups.Reindex();
|
||||
}
|
||||
else
|
||||
{
|
||||
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
|
||||
log << log1 << "Syntax error in line: " << conf_parser.line << logend;
|
||||
slog << logerror << "Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
|
||||
log << log1 << "Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
|
||||
groups.Clear();
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -59,21 +59,27 @@ void Groups::Reindex()
|
||||
group_index_tab.clear();
|
||||
size_t seti = 0;
|
||||
|
||||
while( seti < space.spaces.size() )
|
||||
if( space.child_spaces )
|
||||
{
|
||||
const std::wstring & name = space.spaces[seti]->name;
|
||||
while( seti < space.child_spaces->size() )
|
||||
{
|
||||
PT::Space & sp = *(*space.child_spaces)[seti];
|
||||
|
||||
if( set_index.find(name) == set_index.end() )
|
||||
{
|
||||
set_index[name] = seti;
|
||||
group_index_tab.push_back(GroupIndex());
|
||||
ReindexGroups(group_index_tab.back(), *space.spaces[seti]);
|
||||
seti += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
slog << logerror << "set: " << name << " already defined (skipping)" << logend;
|
||||
space.spaces.erase(space.spaces.begin() + seti);
|
||||
if( sp.name )
|
||||
{
|
||||
if( set_index.find(*sp.name) == set_index.end() )
|
||||
{
|
||||
set_index[*sp.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;
|
||||
space.remove_child_space(seti);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,74 +89,83 @@ void Groups::ReindexGroups(GroupIndex & group_index, PT::Space & set)
|
||||
{
|
||||
size_t i, v;
|
||||
|
||||
// loop through all groups in the set
|
||||
for( i=0 ; i < set.spaces.size() ; ++i )
|
||||
if( set.child_spaces )
|
||||
{
|
||||
PT::Space & group = *set.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
|
||||
const std::wstring & key = group.Text(L"key", L"value");
|
||||
|
||||
// loop through all values in the group
|
||||
for(v=0 ; v<group.spaces.size() ; )
|
||||
// loop through all groups in the set
|
||||
for( i=0 ; i < set.child_spaces->size() ; ++i )
|
||||
{
|
||||
std::wstring * vali = group.spaces[v]->GetFirstValue(key);
|
||||
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");
|
||||
|
||||
if( vali )
|
||||
if( group.child_spaces )
|
||||
{
|
||||
GroupIndex::iterator g = group_index.find(*vali);
|
||||
|
||||
if( g == group_index.end() )
|
||||
// loop through all values in the group
|
||||
for(v=0 ; v<group.child_spaces->size() ; )
|
||||
{
|
||||
group_index[*vali] = i;
|
||||
v += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
|
||||
<< *vali << " (skipping)" << logend;
|
||||
std::wstring * vali = (*group.child_spaces)[v]->get_wstr(key.c_str());
|
||||
|
||||
group.spaces.erase(group.spaces.begin() + v);
|
||||
if( vali )
|
||||
{
|
||||
GroupIndex::iterator g = group_index.find(*vali);
|
||||
|
||||
if( g == group_index.end() )
|
||||
{
|
||||
group_index[*vali] = i;
|
||||
v += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
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: " << set.name
|
||||
<< " has a group without a value (skipping)" << logend;
|
||||
|
||||
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;
|
||||
|
||||
group.spaces.erase(group.spaces.begin() + v);
|
||||
}
|
||||
SortValues(group);
|
||||
}
|
||||
|
||||
SortValues(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Groups::SortValues(PT::Space & group)
|
||||
{
|
||||
sort_by = group.Text(L"sort_by");
|
||||
sort_asc = (group.Text(L"sort_asc", L"true") == L"true");
|
||||
sort_by = group.to_wstr(L"sort_by");
|
||||
sort_asc = group.is_equal(L"sort_asc", L"true");
|
||||
|
||||
if( !sort_by.empty() )
|
||||
if( !sort_by.empty() && group.child_spaces )
|
||||
{
|
||||
group.ListText(L"sort", sort_value);
|
||||
std::sort(group.spaces.begin(), group.spaces.end(), SortFunHelper(this));
|
||||
group.to_list(L"sort", sort_value, true);
|
||||
std::sort(group.child_spaces->begin(), group.child_spaces->end(), SortFunHelper(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Groups::SortFunHelper::operator()(PT::Space * sp1, PT::Space * sp2)
|
||||
{
|
||||
const std::wstring & val1 = sp1->Text(groups->sort_by, L"");
|
||||
const std::wstring & val2 = sp2->Text(groups->sort_by, L"");
|
||||
const std::wstring * val1 = sp1->get_wstr(groups->sort_by.c_str());
|
||||
const std::wstring * val2 = sp2->get_wstr(groups->sort_by.c_str());
|
||||
|
||||
if( !val1 || !val2 )
|
||||
return false;
|
||||
|
||||
if( groups->sort_asc )
|
||||
return SortValue(val1) < SortValue(val2);
|
||||
return SortValue(*val1) < SortValue(*val2);
|
||||
else
|
||||
return SortValue(val1) > SortValue(val2);
|
||||
return SortValue(*val1) > SortValue(*val2);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,16 +206,21 @@ return false;
|
||||
|
||||
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option)
|
||||
{
|
||||
if( seti < space.spaces.size() )
|
||||
if( space.child_spaces && seti < space.child_spaces->size() )
|
||||
{
|
||||
PT::Space & groups = *space.spaces[seti];
|
||||
PT::Space & groups = *(*space.child_spaces)[seti];
|
||||
|
||||
if( groupi < groups.spaces.size() )
|
||||
if( groups.child_spaces && groupi < groups.child_spaces->size() )
|
||||
{
|
||||
PT::Space & value = *groups.spaces[groupi];
|
||||
PT::Space & value = *(*groups.child_spaces)[groupi];
|
||||
|
||||
if( valuei < value.spaces.size() )
|
||||
return value.spaces[valuei]->TextRef(option);
|
||||
if( value.child_spaces && valuei < value.child_spaces->size() )
|
||||
{
|
||||
const std::wstring * res = (*value.child_spaces)[valuei]->get_wstr(option);
|
||||
|
||||
if( res )
|
||||
return *res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -217,12 +237,12 @@ 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( seti < space.spaces.size() )
|
||||
if( space.child_spaces && seti < space.child_spaces->size() )
|
||||
{
|
||||
PT::Space & groups = *space.spaces[seti];
|
||||
PT::Space & groups = *(*space.child_spaces)[seti];
|
||||
|
||||
if( groupi < groups.spaces.size() )
|
||||
return groups.spaces[groupi]->spaces.size();
|
||||
if( groups.child_spaces && groupi < groups.child_spaces->size() )
|
||||
return (*groups.child_spaces)[groupi]->child_spaces->size();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -236,7 +256,7 @@ return 0;
|
||||
|
||||
void Groups::Clear()
|
||||
{
|
||||
space.Clear();
|
||||
space.clear();
|
||||
set_index.clear();
|
||||
group_index_tab.clear();
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
|
||||
std::wstring sort_by;
|
||||
bool sort_asc;
|
||||
PT::Space::Value sort_value;
|
||||
std::vector<std::wstring> sort_value;
|
||||
|
||||
struct SortFunHelper
|
||||
{
|
||||
|
Reference in New Issue
Block a user