Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgorshenin <y.gorshenin@corp.mail.ru>2015-07-01 16:48:58 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:53:27 +0300
commita7bcdb5ae8b8e75c1a3806b00b19f3b80c72c5b3 (patch)
treee24caedef110b579fcedc15d29c62cc43e3f6d9c /indexer/mwm_set.hpp
parente0470160313b3ed0bc396ffec72b16fded6b8520 (diff)
Revert "[storage, framework, index] Storage redesign. Plain strings are replaced to CountryFile and LocalCountryFile."
Diffstat (limited to 'indexer/mwm_set.hpp')
-rw-r--r--indexer/mwm_set.hpp86
1 files changed, 42 insertions, 44 deletions
diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp
index dfc225f4c4..25682c16b0 100644
--- a/indexer/mwm_set.hpp
+++ b/indexer/mwm_set.hpp
@@ -2,9 +2,6 @@
#include "indexer/mwm_version.hpp"
-#include "platform/country_file.hpp"
-#include "platform/local_country_file.hpp"
-
#include "geometry/rect2d.hpp"
#include "base/macros.hpp"
@@ -34,9 +31,10 @@ public:
enum Status
{
- STATUS_REGISTERED, ///< Mwm is registered and up to date.
- STATUS_MARKED_TO_DEREGISTER, ///< Mwm is marked to be deregistered as soon as possible.
- STATUS_DEREGISTERED, ///< Mwm is deregistered.
+ STATUS_UP_TO_DATE, ///< Mwm is registered and up-to-date
+ STATUS_MARKED_TO_DEREGISTER, ///< Mwm is marked to be deregistered as soon as possible
+ STATUS_DEREGISTERED, ///< Mwm is deregistered
+ STATUS_PENDING_UPDATE ///< Mwm is registered but there're a pending update to it
};
MwmInfo();
@@ -48,32 +46,31 @@ public:
inline Status GetStatus() const { return m_status; }
- inline bool IsUpToDate() const { return IsRegistered(); }
-
inline bool IsRegistered() const
{
- return m_status == STATUS_REGISTERED;
+ return m_status == STATUS_UP_TO_DATE || m_status == STATUS_PENDING_UPDATE;
}
- inline platform::LocalCountryFile const & GetLocalFile() const { return m_file; }
-
- inline string GetCountryName() const { return m_file.GetCountryFile().GetNameWithoutExt(); }
+ inline bool IsUpToDate() const { return m_status == STATUS_UP_TO_DATE; }
- inline int64_t GetVersion() const { return m_file.GetVersion(); }
+ inline string const & GetFileName() const { return m_fileName; }
MwmTypeT GetType() const;
private:
inline void SetStatus(Status status) { m_status = status; }
- platform::LocalCountryFile m_file; ///< Path to the mwm file.
- Status m_status; ///< Current country status.
- uint8_t m_lockCount; ///< Number of locks.
+ string m_fileName; ///< Path to the mwm file.
+ Status m_status; ///< Current country status.
+ uint8_t m_lockCount; ///< Number of locks.
};
class MwmSet
{
public:
+ using TMwmFileName = string;
+ using TMwmInfoTable = map<TMwmFileName, shared_ptr<MwmInfo>>;
+
struct MwmId
{
public:
@@ -97,9 +94,9 @@ public:
friend ostream & operator<<(ostream & os, MwmId const & id)
{
if (id.m_info.get())
- os << "MwmId [" << id.m_info->GetCountryName() << "]";
+ os << "MwmId[" << id.m_info->GetFileName() << "]";
else
- os << "MwmId [invalid]";
+ os << "MwmId[invalid]";
return os;
}
@@ -155,43 +152,41 @@ public:
/// Registers a new map.
///
- /// \return A pair of an MwmLock and a flag. There are three cases:
- /// * the map is newer than the newest registered - returns
- /// active lock and set flag.
- /// * the map is older than the newest registered - returns inactive lock and
- /// unset flag.
- /// * the version of the map equals to the version of the newest registered -
- /// returns active lock and unset flag.
+ /// \return A pair of an MwmLock and a flag. MwmLock is locked iff the
+ /// map with fileName was created or already exists. Flag
+ /// is set when the map was registered for a first
+ /// time. Thus, there are three main cases:
///
- /// *NOTE* When a new version for the same country is registered,
- /// all previous versions will be automatically deregistered.
+ /// * the map already exists - returns active lock and unset flag
+ /// * the map was already registered - returns active lock and set flag
+ /// * the map can't be registered - returns inactive lock and unset flag
+ //@{
protected:
- WARN_UNUSED_RESULT pair<MwmLock, bool> RegisterImpl(platform::LocalCountryFile const & localFile);
+ WARN_UNUSED_RESULT pair<MwmLock, bool> RegisterImpl(TMwmFileName const & fileName);
public:
- WARN_UNUSED_RESULT pair<MwmLock, bool> Register(platform::LocalCountryFile const & localFile);
+ WARN_UNUSED_RESULT pair<MwmLock, bool> Register(TMwmFileName const & fileName);
//@}
/// @name Remove mwm.
//@{
protected:
- /// Deregisters a map from internal records.
+ /// Deregisters a map from the set when it's possible. Note that an
+ /// underlying file is not deleted.
///
- /// \param countryFile A countryFile denoting a map to be deregistered.
- /// \return True if the map was successfully deregistered. If map is locked
- /// now, returns false.
+ /// @return true when the map was deregistered.
//@{
bool DeregisterImpl(MwmId const & id);
- bool DeregisterImpl(platform::CountryFile const & countryFile);
+ bool DeregisterImpl(TMwmFileName const & ofileName);
//@}
public:
- bool Deregister(platform::CountryFile const & countryFile);
+ bool Deregister(TMwmFileName const & fileName);
void DeregisterAll();
//@}
- /// Returns true when country is registered and can be used.
- bool IsLoaded(platform::CountryFile const & countryFile) const;
+ /// @param[in] file File name without extension.
+ bool IsLoaded(TMwmFileName const & fileName) const;
/// Get ids of all mwms. Some of them may be with not active status.
/// In that case, LockValue returns NULL.
@@ -199,14 +194,14 @@ public:
void ClearCache();
- MwmId GetMwmIdByCountryFile(platform::CountryFile const & countryFile) const;
+ MwmId GetMwmIdByFileName(TMwmFileName const & fileName) const;
- MwmLock GetMwmLockByCountryFile(platform::CountryFile const & countryFile);
+ MwmLock GetMwmLockByFileName(TMwmFileName const & fileName);
protected:
/// @return True when file format version was successfully read to MwmInfo.
- virtual bool GetVersion(platform::LocalCountryFile const & localFile, MwmInfo & info) const = 0;
- virtual TMwmValueBasePtr CreateValue(platform::LocalCountryFile const & localFile) const = 0;
+ virtual bool GetVersion(TMwmFileName const & fileName, MwmInfo & info) const = 0;
+ virtual TMwmValueBasePtr CreateValue(string const & name) const = 0;
void Cleanup();
@@ -231,7 +226,7 @@ protected:
/// Find mwm with a given name.
/// @precondition This function is always called under mutex m_lock.
- MwmId GetMwmIdByCountryFileImpl(platform::CountryFile const & countryFile) const;
+ MwmId GetMwmIdByFileNameImpl(TMwmFileName const & fileName) const;
/// @precondition This function is always called under mutex m_lock.
WARN_UNUSED_RESULT inline MwmLock GetLock(MwmId const & id)
@@ -241,9 +236,12 @@ protected:
// This method is called under m_lock when mwm is removed from a
// registry.
- virtual void OnMwmDeregistered(platform::LocalCountryFile const & localFile) {}
+ virtual void OnMwmDeleted(shared_ptr<MwmInfo> const & info) {}
+
+ // This method is called under m_lock when mwm is ready for update.
+ virtual void OnMwmReadyForUpdate(shared_ptr<MwmInfo> const & info) {}
- map<string, vector<shared_ptr<MwmInfo>>> m_info;
+ TMwmInfoTable m_info;
mutable mutex m_lock;
};