diff options
author | Denis Koronchik <denis@mapswithme.com> | 2014-09-19 13:54:38 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:28:26 +0300 |
commit | 8150a4c98d9e54589df6c4b2ba46e26c22b6f487 (patch) | |
tree | 7c95aeb7a10a5316cdb24cc50e59e75281a1ba56 /coding/file_container.hpp | |
parent | 4cc394fb712d59558d1634175dd27a91a9206c86 (diff) |
[core] Refactoring of FilesMappingContainer Handle: using move semantics to control ownership.
Diffstat (limited to 'coding/file_container.hpp')
-rw-r--r-- | coding/file_container.hpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/coding/file_container.hpp b/coding/file_container.hpp index a9d8011098..96f1dfe518 100644 --- a/coding/file_container.hpp +++ b/coding/file_container.hpp @@ -4,6 +4,7 @@ #include "../std/vector.hpp" #include "../std/string.hpp" +#include "../std/noncopyable.hpp" class FilesContainerBase @@ -119,26 +120,42 @@ public: explicit FilesMappingContainer(string const & fName); ~FilesMappingContainer(); - class Handle + class Handle : private noncopyable { + void Reset(); + public: Handle() : m_base(0), m_origBase(0), m_size(0), m_origSize(0) { } - Handle(char const * base, char const * alignBase, uint64_t size, uint64_t origSize) : m_base(base), m_origBase(alignBase), m_size(size), m_origSize(origSize) { } - + Handle(Handle && h) + { + Assign(std::move(h)); + } ~Handle(); + void Assign(Handle && h); + void Unmap(); - bool IsValid() const { return (m_base != 0 && m_size > 0); } + bool IsValid() const { return (m_base != 0); } uint64_t GetSize() const { return m_size; } - char const * GetData() const { return m_base; } + + template <class T> T const * GetData() const + { + ASSERT_EQUAL(m_size % sizeof(T), 0, ()); + return reinterpret_cast<T const *>(m_base); + } + template <class T> size_t GetDataCount() const + { + ASSERT_EQUAL(m_size % sizeof(T), 0, ()); + return (m_size / sizeof(T)); + } private: char const * m_base; |