mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
refs #545 Refactoring: extract method elementsStartingWith.
This commit is contained in:
@@ -117,7 +117,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
CVariantMap map;
|
CVariantMap map;
|
||||||
for (const auto &element : makeRange(m_elements.lowerBound(keyPrefix), m_elements.lowerBound(keyPrefix + QChar(QChar::LastValidCodePoint))))
|
for (const auto &element : elementsStartingWith(keyPrefix))
|
||||||
{
|
{
|
||||||
implementationOf(map).insert(map.cend(), element->m_key, element->m_value);
|
implementationOf(map).insert(map.cend(), element->m_key, element->m_value);
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
CValueCachePacket map;
|
CValueCachePacket map;
|
||||||
for (const auto &element : makeRange(m_elements.lowerBound(keyPrefix), m_elements.lowerBound(keyPrefix + QChar(QChar::LastValidCodePoint))))
|
for (const auto &element : elementsStartingWith(keyPrefix))
|
||||||
{
|
{
|
||||||
map.insert(element->m_key, element->m_value, element->m_timestamp);
|
map.insert(element->m_key, element->m_value, element->m_timestamp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#define BLACKMISC_VALUECACHE_H
|
#define BLACKMISC_VALUECACHE_H
|
||||||
|
|
||||||
#include "blackmisc/valuecacheprivate.h"
|
#include "blackmisc/valuecacheprivate.h"
|
||||||
|
#include "blackmisc/range.h"
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -160,7 +161,23 @@ namespace BlackMisc
|
|||||||
//! of CValueCache instances in all processes including this one. The slot will do its own round-trip detection.
|
//! of CValueCache instances in all processes including this one. The slot will do its own round-trip detection.
|
||||||
void valuesChangedByLocal(const BlackMisc::CValueCachePacket &values);
|
void valuesChangedByLocal(const BlackMisc::CValueCachePacket &values);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Element; // remove forward declaration when elementsStartingWith uses C++14 auto deduced return type
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//! Returns a range referring to all elements which start with the given prefix.
|
||||||
|
//! \todo Use C++14 auto deduced return type.
|
||||||
|
//! @{
|
||||||
|
auto elementsStartingWith(const QString &keyPrefix) -> CRange<QMap<QString, QSharedPointer<Element>>::iterator>
|
||||||
|
{
|
||||||
|
return makeRange(m_elements.lowerBound(keyPrefix), m_elements.lowerBound(keyPrefix + QChar(QChar::LastValidCodePoint)));
|
||||||
|
}
|
||||||
|
auto elementsStartingWith(const QString &keyPrefix) const -> CRange<QMap<QString, QSharedPointer<Element>>::const_iterator>
|
||||||
|
{
|
||||||
|
return makeRange(m_elements.lowerBound(keyPrefix), m_elements.lowerBound(keyPrefix + QChar(QChar::LastValidCodePoint)));
|
||||||
|
}
|
||||||
|
//! @}
|
||||||
|
|
||||||
//! Save specific values to Json files in a given directory.
|
//! Save specific values to Json files in a given directory.
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
CStatusMessage saveToFiles(const QString &directory, const CVariantMap &values) const;
|
CStatusMessage saveToFiles(const QString &directory, const CVariantMap &values) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user