diff options
author | Yuri Gorshenin <y@mmaps.me> | 2015-03-31 19:21:39 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:41:35 +0300 |
commit | 9e5ac4ef2a843481e59cbe5295c785a92a374bf9 (patch) | |
tree | f6b29e544a34a4f12138224cdf9341c28ce31702 /indexer/mwm_set.hpp | |
parent | 25f7a7f2f32cc4db8a5bd0106ae4c8f6c6292201 (diff) |
Fixed MwmSet::Register() signature.
Diffstat (limited to 'indexer/mwm_set.hpp')
-rw-r--r-- | indexer/mwm_set.hpp | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 6d045a6877..217c95fbce 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -1,9 +1,11 @@ #pragma once -#include "data_header.hpp" +#include "mwm_version.hpp" #include "../geometry/rect2d.hpp" +#include "../base/macros.hpp" + #include "../std/deque.hpp" #include "../std/mutex.hpp" #include "../std/string.hpp" @@ -31,10 +33,11 @@ public: MwmInfo(); - m2::RectD m_limitRect; ///< Limit rect of mwm. - uint8_t m_minScale; ///< Min zoom level of mwm. - uint8_t m_maxScale; ///< Max zoom level of mwm. - uint8_t m_lockCount; ///< Number of locks. + m2::RectD m_limitRect; ///< Limit rect of mwm. + uint8_t m_minScale; ///< Min zoom level of mwm. + uint8_t m_maxScale; ///< Max zoom level of mwm. + uint8_t m_lockCount; ///< Number of locks. + version::MwmVersion m_version; ///< Mwm file version. inline bool IsRegistered() const { @@ -58,6 +61,8 @@ class MwmSet public: typedef size_t MwmId; + static const MwmId INVALID_MWM_ID; + explicit MwmSet(size_t cacheSize = 5); virtual ~MwmSet() = 0; @@ -71,42 +76,54 @@ public: class MwmLock { public: + MwmLock(); MwmLock(MwmSet & mwmSet, MwmId mwmId); - ~MwmLock(); + MwmLock(MwmSet & mwmSet, string const & fileName); + MwmLock(MwmLock && lock); + virtual ~MwmLock(); - inline MwmValueBase * GetValue() const { return m_pValue; } - inline MwmId GetID() const { return m_id; } + template <typename T> + inline T * GetValue() const + { + return static_cast<T *>(m_value); + } + inline bool IsLocked() const { return m_value; } + inline MwmId GetId() const { return m_mwmId; } + MwmInfo const & GetInfo() const; + + MwmLock & operator=(MwmLock && lock); private: - MwmSet & m_mwmSet; - MwmId m_id; - MwmValueBase * m_pValue; + friend class MwmSet; + + MwmLock(MwmSet & mwmSet, MwmId mwmId, MwmValueBase * value); + + MwmSet * m_mwmSet; + MwmId m_mwmId; + MwmValueBase * m_value; + + NONCOPYABLE(MwmLock); }; /// Registers new map in the set. - /// @param[in] fileName File name (without full path) of country. - /// @param[out] rect Limit rect of country. - /// @param[out] version Version of the file. /// - /// @return True when map is registered, false otherwise - map already - /// exists or it's not possible to get mwm's version. + /// \param fileName File name (without full path) of country. + /// + /// \return A pair of MwmLock and a flag. MwmLock is locked iff map + /// with fileName was created or already exists. Flag is + /// set when a new map was registered. Thus, there are + /// three main cases: + /// * map already exists - returns active lock and unset flag + /// * a new map was registered - returns active lock and set flag + /// * can't register new map - returns inactive lock and unset flag //@{ protected: - bool RegisterImpl(string const & fileName, m2::RectD & rect, - feature::DataHeader::Version & version); + WARN_UNUSED_RESULT pair<MwmLock, bool> RegisterImpl(string const & fileName); public: - bool Register(string const & fileName, m2::RectD & rect, feature::DataHeader::Version & version); + WARN_UNUSED_RESULT pair<MwmLock, bool> Register(string const & fileName); //@} - /// Used in unit tests only. - inline void Register(string const & fileName) - { - m2::RectD dummyRect; - feature::DataHeader::Version dummyVersion; - CHECK(Register(fileName, dummyRect, dummyVersion), ()); - } - /// @name Remove mwm. //@{ protected: @@ -130,14 +147,17 @@ public: /// In that case, LockValue returns NULL. void GetMwmInfo(vector<MwmInfo> & info) const; + /// \return A reference to an MwmInfo corresponding to id. Id must + /// be a valid Mwm id. + MwmInfo const & GetMwmInfo(MwmId id) const; + // Clear caches. void ClearCache(); protected: /// @return True when it's possible to get file format version - in /// this case version is set to the file format version. - virtual bool GetVersion(string const & name, MwmInfo & info, - feature::DataHeader::Version & version) const = 0; + virtual bool GetVersion(string const & name, MwmInfo & info) = 0; virtual MwmValueBase * CreateValue(string const & name) const = 0; void Cleanup(); @@ -146,7 +166,9 @@ private: typedef deque<pair<MwmId, MwmValueBase *> > CacheType; MwmValueBase * LockValue(MwmId id); + MwmValueBase * LockValueImpl(MwmId id); void UnlockValue(MwmId id, MwmValueBase * p); + void UnlockValueImpl(MwmId id, MwmValueBase * p); /// Find first removed mwm or add a new one. /// @precondition This function is always called under mutex m_lock. @@ -160,8 +182,6 @@ private: size_t m_cacheSize; protected: - static const MwmId INVALID_MWM_ID = static_cast<MwmId>(-1); - /// Find mwm with a given name. /// @precondition This function is always called under mutex m_lock. MwmId GetIdByName(string const & name); @@ -169,6 +189,12 @@ protected: /// @precondition This function is always called under mutex m_lock. void ClearCache(MwmId id); + /// @precondition This function is always called under mutex m_lock. + WARN_UNUSED_RESULT inline MwmLock GetLock(MwmId id) + { + return MwmLock(*this, id, LockValueImpl(id)); + } + /// Update given MwmInfo. /// @precondition This function is always called under mutex m_lock. virtual void UpdateMwmInfo(MwmId id); |