Files
MuditaOS/module-services/service-db/EntryPath.cpp
Adam Dobrowolski b38adceced [EGD-6019] Minimum settings ownership lifetime fixups
added weakptr link to settings and checks
    it wont crash on deinitialized setings now
Pseuto UT are passing
Added:
    - deregistration on Settings destrution
    - weak referencing of Service to not crash Settings on missuse
    - Proxy as initialization parameter to Settings
Unused code removed
Enabled tests to be written for Settings
Removed dependency from freertos in test global file
EntryPath tests updated and compilation slimed
2021-05-18 13:25:54 +02:00

41 lines
1.2 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "service-db/EntryPath.hpp"
#include <Split.hpp>
#include <tuple>
namespace settings
{
void EntryPath::parse(const std::string &dbPath)
{
auto parts = utils::split(dbPath, "\\", false);
if (1 == parts.size()) {
variable = dbPath;
scope = SettingsScope::Global;
}
else {
mode = parts[0];
service = parts[1];
profile = parts[2];
variable = parts[3];
scope = SettingsScope::AppLocal;
}
}
bool operator<(const EntryPath &lhs, const EntryPath &rhs) noexcept
{
if (lhs.scope != rhs.scope) {
return lhs.scope < rhs.scope;
}
// Scopes are equal - compare other internals.
if (lhs.scope == SettingsScope::AppLocal) {
return std::tie(lhs.scope, lhs.mode, lhs.service, lhs.profile, lhs.variable) <
std::tie(rhs.scope, rhs.mode, rhs.service, rhs.profile, rhs.variable);
}
return lhs.variable < rhs.variable;
}
} // namespace settings