mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
# 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
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
#pragma once
|
||
|
||
#include <mutex>
|
||
|
||
#include <pugixml.hpp>
|
||
|
||
/*
|
||
* TODO combine this header and its CPP file with editor/editor_storage.hpp and its CPP counterpart,
|
||
* give it an appropriate namespace and place it where both editor and traffic can use it.
|
||
* `traff_storage` is essentially copied from `editor_storage` with just a few modifications:
|
||
* - namespace
|
||
* - instead of relying on a hardcoded file name, `LocalStorage` is initialized with a file name
|
||
* - log output, variable names and comments changed to be use case neutral (no API changes)
|
||
* - refactoring: no global `using namespace` (no API changes)
|
||
* Apart from the first two points, this file can serve as a drop-in replacement for `editor_storage`.
|
||
* Traffic uses only `LocalStorage`, the rest has been kept to ease migration to a unified storage
|
||
* component.
|
||
*/
|
||
|
||
namespace traffxml
|
||
{
|
||
/**
|
||
* @brief Storage interface for XML data.
|
||
*/
|
||
class StorageBase
|
||
{
|
||
public:
|
||
virtual ~StorageBase() = default;
|
||
|
||
virtual bool Save(pugi::xml_document const & doc) = 0;
|
||
virtual bool Load(pugi::xml_document & doc) = 0;
|
||
virtual bool Reset() = 0;
|
||
};
|
||
|
||
/**
|
||
* @brief Class which saves/loads XML data to/from local file.
|
||
* @note this class IS thread-safe.
|
||
*/
|
||
class LocalStorage : public StorageBase
|
||
{
|
||
public:
|
||
/**
|
||
* @brief Constructs a `LocalStorage` instance.
|
||
* @param fileName The file name and path where the file in question will be persisted. It is
|
||
* interpreted relative to the platform-specific path; absolute paths are not supported as some
|
||
* platforms restrict applications’ access to files outside their designated path.
|
||
*/
|
||
LocalStorage(std::string const & fileName)
|
||
: m_fileName(fileName)
|
||
{}
|
||
|
||
// StorageBase overrides:
|
||
bool Save(pugi::xml_document const & doc) override;
|
||
bool Load(pugi::xml_document & doc) override;
|
||
bool Reset() override;
|
||
|
||
private:
|
||
std::string m_fileName;
|
||
std::mutex m_mutex;
|
||
};
|
||
|
||
/**
|
||
* @brief Class which saves/loads data to/from xml_document class instance.
|
||
* @note this class is NOT thread-safe.
|
||
*/
|
||
class InMemoryStorage : public StorageBase
|
||
{
|
||
public:
|
||
// StorageBase overrides:
|
||
bool Save(pugi::xml_document const & doc) override;
|
||
bool Load(pugi::xml_document & doc) override;
|
||
bool Reset() override;
|
||
|
||
private:
|
||
pugi::xml_document m_doc;
|
||
};
|
||
} // namespace traffxml
|