Files
comaps/libs/traffxml/traff_storage.cpp
mvglasow 38e98df6cc Merge commit '05cc660641' into traffic
# Conflicts:
#	CMakeLists.txt
#	android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java
#	android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.hpp
#	android/sdk/src/main/cpp/app/organicmaps/sdk/OrganicMaps.cpp
#	android/sdk/src/main/cpp/app/organicmaps/sdk/util/Config.cpp
#	libs/indexer/data_source.hpp
#	libs/indexer/feature.hpp
#	libs/indexer/ftypes_matcher.hpp
#	libs/map/framework.cpp
#	libs/map/traffic_manager.cpp
#	libs/routing/absent_regions_finder.cpp
#	libs/routing/edge_estimator.hpp
#	libs/routing/index_router.cpp
#	libs/routing/index_router.hpp
#	libs/routing/routing_session.hpp
#	libs/routing_common/num_mwm_id.hpp
#	libs/traffic/traffic_info.cpp
#	qt/mainwindow.hpp
#	qt/preferences_dialog.cpp
#	tools/openlr/helpers.hpp
#	tools/openlr/openlr_decoder.cpp
#	tools/openlr/openlr_decoder.hpp
#	tools/openlr/openlr_stat/openlr_stat.cpp
#	tools/openlr/router.hpp
#	tools/openlr/score_candidate_paths_getter.cpp
#	tools/openlr/score_candidate_paths_getter.hpp
#	xcode/CoMaps.xcworkspace/contents.xcworkspacedata
2025-09-10 21:22:40 +03:00

77 lines
1.8 KiB
C++

#include "traffxml/traff_storage.hpp"
#include "platform/platform.hpp"
#include "coding/internal/file_data.hpp"
#include "base/logging.hpp"
#include <string>
namespace
{
std::string GetFilePath(std::string const & fileName) { return GetPlatform().WritablePathForFile(fileName); }
} // namespace
namespace traffxml
{
// StorageLocal ------------------------------------------------------------------------------------
bool LocalStorage::Save(pugi::xml_document const & doc)
{
auto const filePath = GetFilePath(m_fileName);
std::lock_guard<std::mutex> guard(m_mutex);
return base::WriteToTempAndRenameToFile(filePath, [&doc](std::string const & fileName) {
return doc.save_file(fileName.data(), " " /* indent */);
});
}
bool LocalStorage::Load(pugi::xml_document & doc)
{
auto const filePath = GetFilePath(m_fileName);
std::lock_guard<std::mutex> guard(m_mutex);
auto const result = doc.load_file(filePath.c_str());
/*
* Note: status_file_not_found is ok for our use cases:
* - editor: if a user has never made any edits.
* - traffic: if no traffic information has ever been retrieved (first run)
*/
if (result != pugi::status_ok && result != pugi::status_file_not_found)
{
LOG(LERROR, ("Can't load file from disk:", filePath));
return false;
}
return true;
}
bool LocalStorage::Reset()
{
std::lock_guard<std::mutex> guard(m_mutex);
return base::DeleteFileX(GetFilePath(m_fileName));
}
// StorageMemory -----------------------------------------------------------------------------------
bool InMemoryStorage::Save(pugi::xml_document const & doc)
{
m_doc.reset(doc);
return true;
}
bool InMemoryStorage::Load(pugi::xml_document & doc)
{
doc.reset(m_doc);
return true;
}
bool InMemoryStorage::Reset()
{
m_doc.reset();
return true;
}
} // namespace traffxml