Skip to content

Commit

Permalink
libcore: Added multimap remove utility; various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 32079a5 commit 91386cf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
23 changes: 23 additions & 0 deletions doomsday/libs/core/include/de/data/hash.h
Expand Up @@ -123,6 +123,29 @@ class MutableHashIterator
_iter = _hash.erase(_cur);
}
};

template <typename MultiContainer>
inline bool multiRemove(MultiContainer &multi,
const typename MultiContainer::value_type::first_type &key,
const typename MultiContainer::value_type::second_type &value)
{
bool removed = false;
const auto keys = multi.equal_range(key);
for (auto i = keys.first; i != keys.second; )
{
if (i->second == value)
{
i = multi.erase(i);
removed = true;
}
else
{
++i;
}
}
return removed;
}

} // namespace de

#endif // LIBCORE_HASH_H
9 changes: 4 additions & 5 deletions doomsday/libs/core/include/de/data/partition.h
Expand Up @@ -24,7 +24,7 @@
#include "../String"
#include "../Vector"

#include <QTextStream>
#include <sstream>

namespace de {

Expand Down Expand Up @@ -112,10 +112,9 @@ class Partition

String asText() const
{
String str;
QTextStream s(&str);
s << direction.x << "/" << direction.y << " " << origin.asText();
return str;
std::ostringstream s;
s << direction.x << "/" << direction.y << " " << origin;
return s.str();
}
};

Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/core/include/de/data/pathtree.h
Expand Up @@ -431,7 +431,8 @@ inline bool comparePathTreeNodePathsAscending(PathTreeNodeType const *a, PathTre
{
// String pathA(QString(QByteArray::fromPercentEncoding(a->path().toUtf8())));
// String pathB(QString(QByteArray::fromPercentEncoding(b->path().toUtf8())));
return a->path().compareWithoutCase(b->path()) < 0;
return String::fromPercentEncoding(a->path().toString()).compareWithoutCase(
String::fromPercentEncoding(b->path().toString())) < 0;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions doomsday/libs/core/include/de/data/string.h
Expand Up @@ -517,9 +517,13 @@ class DE_PUBLIC String : public IByteArray
inline bool operator==(const String &str) const { return compare(str) == 0; }
inline bool operator!=(const String &str) const { return !(*this == str); }

inline int compare(const char *cstr) const { return cmp_String(&_str, cstr); }
inline int compare(const char *cstr, Sensitivity cs = CaseSensitive) const
{
return cmpSc_String(&_str, cstr, cs);
}
int compare(const CString &str, Sensitivity cs = CaseSensitive) const;
inline int compare(const String &s, Sensitivity cs = CaseSensitive) const {
inline int compare(const String &s, Sensitivity cs = CaseSensitive) const
{
return cmpStringSc_String(&_str, &s._str, cs);
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/core/textapp.cpp
Expand Up @@ -93,7 +93,7 @@ int TextApp::exec(const std::function<void()> &startup)

int code = d->eventLoop.exec([this, startup]() {
d->loop.start();
startup();
if (startup) startup();
});

LOGDEV_NOTE("TextApp event loop exited with code %i") << code;
Expand Down

0 comments on commit 91386cf

Please sign in to comment.