forked from Mirrors/openclonk
Rewrote PropList output string sorting to get rid of C4Set<T>::Sort()
C4Set<T>::Sort() breaks the internals of the class which Guenther doesn't like. Now the sorted list is returned as a list of pointers into the original set.
parent
ef674b1779
commit
140dc97b24
|
@ -330,16 +330,13 @@ void C4PropList::AppendDataString(StdStrBuf * out, const char * delim, int depth
|
|||
DataString.Append("...");
|
||||
return;
|
||||
}
|
||||
C4Set<C4Property> sorted_props = Properties;
|
||||
sorted_props.Sort();
|
||||
const C4Property * p = sorted_props.First();
|
||||
while (p)
|
||||
std::list<const C4Property *> sorted_props = Properties.GetSortedListOfElementPointers();
|
||||
for (std::list<const C4Property *>::const_iterator p = sorted_props.begin(); p != sorted_props.end(); ++p)
|
||||
{
|
||||
DataString.Append(p->Key->GetData());
|
||||
if (p != sorted_props.begin()) DataString.Append(delim);
|
||||
DataString.Append((*p)->Key->GetData());
|
||||
DataString.Append(" = ");
|
||||
DataString.Append(p->Value.GetDataString(depth - 1));
|
||||
p = sorted_props.Next(p);
|
||||
if (p) DataString.Append(delim);
|
||||
DataString.Append((*p)->Value.GetDataString(depth - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -254,10 +254,21 @@ public:
|
|||
Size = Size2;
|
||||
Table = Table2;
|
||||
}
|
||||
void Sort()
|
||||
static bool SortFunc(const T *p1, const T*p2)
|
||||
{
|
||||
// sort by keys
|
||||
std::sort(&Table[0], &Table[Capacity]);
|
||||
// elements are guarantueed to be non-NULL
|
||||
return *p1<*p2;
|
||||
}
|
||||
std::list<const T *> GetSortedListOfElementPointers() const
|
||||
{
|
||||
// return a list of pointers to all elements in this set sorted by the standard less-than operation
|
||||
// of the elements
|
||||
// elements of resulting lists are guarantueed to be non-NULL
|
||||
// list remains valid as long as this set is not changed
|
||||
std::list<const T *> result;
|
||||
for (const T *p = First(); p; p = Next(p)) result.push_back(p);
|
||||
result.sort(C4Set<T>::SortFunc);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue