Skip to content

Commit

Permalink
Exchanging size_t to uint64_t for mwm and group mwm size in bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bykoianko committed Apr 6, 2016
1 parent 62dc46e commit d13c4b9
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (instancetype)initWithIndexes:(storage::TCountriesVec const &)countriesVec isM
if (self)
{
NSMutableArray * titles = [@[] mutableCopy];
size_t totalRoutingSize = 0;
storage::TMwmSize totalRoutingSize = 0;
auto & s = GetFramework().Storage();
for (auto const & countryId : countriesVec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ - (void)configAllMapsView
s.GetQueuedChildren(parentCountryId, queuedChildren);
if (!queuedChildren.empty())
{
size_t queuedSize = 0;
storage::TMwmSize queuedSize = 0;
for (TCountryId const & countryId : queuedChildren)
{
NodeAttrs nodeAttrs;
Expand Down
12 changes: 5 additions & 7 deletions platform/local_country_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ string LocalCountryFile::GetPath(MapOptions file) const
return my::JoinFoldersToPath(m_directory, GetFileName(m_countryFile.GetName(), file, GetVersion()));
}

uint32_t LocalCountryFile::GetSize(MapOptions filesMask) const
uint64_t LocalCountryFile::GetSize(MapOptions filesMask) const
{
uint64_t size64 = 0;
uint64_t size = 0;
if (HasOptions(filesMask, MapOptions::Map))
size64 += m_mapSize;
size += m_mapSize;
if (!version::IsSingleMwm(GetVersion()) && HasOptions(filesMask, MapOptions::CarRouting))
size64 += m_routingSize;
size += m_routingSize;

uint32_t const size32 = static_cast<uint32_t>(size64);
ASSERT_EQUAL(size32, size64, ());
return size32;
return size;
}

bool LocalCountryFile::operator<(LocalCountryFile const & rhs) const
Expand Down
2 changes: 1 addition & 1 deletion platform/local_country_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LocalCountryFile

// Returns size of a file. Return value may be zero until
// SyncWithDisk() is called.
uint32_t GetSize(MapOptions filesMask) const;
uint64_t GetSize(MapOptions filesMask) const;

// Returns a mask of all known country files. Return value may be
// empty until SyncWithDisk() is called.
Expand Down
2 changes: 1 addition & 1 deletion qt/draw_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void DrawWidget::UpdateCountryStatus(storage::TCountryId const & countryId)

auto status = m_framework->Storage().CountryStatusEx(countryId);

uint64_t sizeInBytes = 0;
storage::TMwmSize sizeInBytes = 0;
if (!countryId.empty())
{
storage::NodeAttrs nodeAttrs;
Expand Down
24 changes: 12 additions & 12 deletions storage/country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ namespace storage
// Mwm subtree attributes. They can be calculated based on information contained in countries.txt.
// The first in the pair is number of mwms in a subtree. The second is sum of sizes of
// all mwms in a subtree.
using TMwmSubtreeAttrs = pair<uint32_t, size_t>;
using TMwmSubtreeAttrs = pair<TMwmCounter, TMwmSize>;

namespace
{
class StoreSingleMwmInterface
{
public:
virtual ~StoreSingleMwmInterface() = default;
virtual Country * InsertToCountryTree(TCountryId const & id, uint32_t mapSize, size_t depth,
virtual Country * InsertToCountryTree(TCountryId const & id, TMwmSize mapSize, size_t depth,
TCountryId const & parent) = 0;
virtual void InsertOldMwmMapping(TCountryId const & newId, TCountryId const & oldId) = 0;
virtual void InsertAffiliation(TCountryId const & countryId, string const & affilation) = 0;
Expand All @@ -50,7 +50,7 @@ class StoreCountriesSingleMwms : public StoreSingleMwmInterface
}

// StoreSingleMwmInterface overrides:
Country * InsertToCountryTree(TCountryId const & id, uint32_t mapSize, size_t depth,
Country * InsertToCountryTree(TCountryId const & id, TMwmSize mapSize, size_t depth,
TCountryId const & parent) override
{
Country country(id, parent);
Expand Down Expand Up @@ -88,7 +88,7 @@ class StoreFile2InfoSingleMwms : public StoreSingleMwmInterface
StoreFile2InfoSingleMwms(map<string, CountryInfo> & file2info) : m_file2info(file2info) {}

// StoreSingleMwmInterface overrides:
Country * InsertToCountryTree(TCountryId const & id, uint32_t /* mapSize */, size_t /* depth */,
Country * InsertToCountryTree(TCountryId const & id, TMwmSize /* mapSize */, size_t /* depth */,
TCountryId const & /* parent */) override
{
CountryInfo info(id);
Expand Down Expand Up @@ -135,8 +135,8 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(size_t depth, json_t * node, TCountryId
// We expect that mwm and routing files should be less than 2GB.
Country * addedNode = store.InsertToCountryTree(id, nodeSize, depth, parent);

uint32_t mwmCounter = 0;
size_t mwmSize = 0;
TMwmCounter mwmCounter = 0;
TMwmSize mwmSize = 0;
vector<json_t *> children;
my::FromJSONObjectOptionalField(node, "g", children);
if (children.empty())
Expand Down Expand Up @@ -181,7 +181,7 @@ class StoreTwoComponentMwmInterface
{
public:
virtual ~StoreTwoComponentMwmInterface() = default;
virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t depth,
virtual Country * Insert(string const & id, TMwmSize mapSize, TMwmSize /* routingSize */, size_t depth,
TCountryId const & parent) = 0;
};

Expand All @@ -197,7 +197,7 @@ class StoreCountriesTwoComponentMwms : public StoreTwoComponentMwmInterface
}

// StoreTwoComponentMwmInterface overrides:
virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t routingSize, size_t depth,
virtual Country * Insert(string const & id, TMwmSize mapSize, TMwmSize routingSize, size_t depth,
TCountryId const & parent) override
{
Country country(id, parent);
Expand All @@ -220,7 +220,7 @@ class StoreFile2InfoTwoComponentMwms : public StoreTwoComponentMwmInterface
StoreFile2InfoTwoComponentMwms(map<string, CountryInfo> & file2info) : m_file2info(file2info) {}

// StoreTwoComponentMwmInterface overrides:
virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t /* depth */,
virtual Country * Insert(string const & id, TMwmSize mapSize, TMwmSize /* routingSize */, size_t /* depth */,
TCountryId const & /* parent */) override
{
if (mapSize == 0)
Expand Down Expand Up @@ -250,11 +250,11 @@ TMwmSubtreeAttrs LoadGroupTwoComponentMwmsImpl(size_t depth, json_t * node, TCou
ASSERT_LESS_OR_EQUAL(0, mwmSize, ());
ASSERT_LESS_OR_EQUAL(0, routingSize, ());

Country * addedNode = store.Insert(file, static_cast<uint32_t>(mwmSize), static_cast<uint32_t>(routingSize),
Country * addedNode = store.Insert(file, static_cast<TMwmSize>(mwmSize), static_cast<TMwmSize>(routingSize),
depth, parent);

uint32_t countryCounter = 0;
size_t countrySize = 0;
TMwmCounter countryCounter = 0;
TMwmSize countrySize = 0;
vector<json_t *> children;
my::FromJSONObjectOptionalField(node, "g", children);
if (children.empty())
Expand Down
10 changes: 5 additions & 5 deletions storage/country.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ class Country
platform::CountryFile m_file;
/// The number of descendant mwm files of |m_name|. Only files (leaves in tree) are counted.
/// If |m_name| is a mwm file name |m_childrenNumber| == 1.
uint32_t m_subtreeMwmNumber;
TMwmCounter m_subtreeMwmNumber;
/// Size of descendant mwm files of |m_name|.
/// If |m_name| is a mwm file name |m_subtreeMwmSizeBytes| is equal to size of the mwm.
size_t m_subtreeMwmSizeBytes;
TMwmSize m_subtreeMwmSizeBytes;

public:
Country() = default;
explicit Country(TCountryId const & name, TCountryId const & parent = kInvalidCountryId)
: m_name(name), m_parent(parent) {}

void SetFile(platform::CountryFile const & file) { m_file = file; }
void SetSubtreeAttrs(uint32_t subtreeMwmNumber, size_t subtreeMwmSizeBytes)
void SetSubtreeAttrs(TMwmCounter subtreeMwmNumber, TMwmSize subtreeMwmSizeBytes)
{
m_subtreeMwmNumber = subtreeMwmNumber;
m_subtreeMwmSizeBytes = subtreeMwmSizeBytes;
}
uint32_t GetSubtreeMwmCounter() const { return m_subtreeMwmNumber; }
size_t GetSubtreeMwmSizeBytes() const { return m_subtreeMwmSizeBytes; }
TMwmCounter GetSubtreeMwmCounter() const { return m_subtreeMwmNumber; }
TMwmSize GetSubtreeMwmSizeBytes() const { return m_subtreeMwmSizeBytes; }
TCountryId GetParent() const { return m_parent; }

/// This function valid for current logic - one file for one country (region).
Expand Down
2 changes: 1 addition & 1 deletion storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs)
if (nodeAttrs.m_status == NodeStatus::OnDisk)
{
// Group or leaf node is on disk and up to date.
size_t const subTreeSizeBytes = node->Value().GetSubtreeMwmSizeBytes();
TMwmSize const subTreeSizeBytes = node->Value().GetSubtreeMwmSizeBytes();
nodeAttrs.m_downloadingProgress.first = subTreeSizeBytes;
nodeAttrs.m_downloadingProgress.second = subTreeSizeBytes;
}
Expand Down
19 changes: 10 additions & 9 deletions storage/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "storage/country.hpp"
#include "storage/country_name_getter.hpp"
#include "storage/country_tree.hpp"
#include "storage/storage_defines.hpp"
#include "storage/index.hpp"
#include "storage/map_files_downloader.hpp"
#include "storage/queued_country.hpp"
Expand Down Expand Up @@ -45,31 +46,31 @@ struct NodeAttrs
/// If the node is expandable (a big country) |m_mwmCounter| is number of mwm files (leaves)
/// belonging to the node. If the node isn't expandable |m_mwmCounter| == 1.
/// Note. For every expandable node |m_mwmCounter| >= 2.
uint32_t m_mwmCounter;
TMwmCounter m_mwmCounter;

/// Number of mwms belonging to the node which have been downloaded.
uint32_t m_localMwmCounter;
TMwmCounter m_localMwmCounter;

/// Number of leaves of the node which have been downloaded
/// plus which is in progress of downloading (zero or one)
/// plus which are staying in queue.
uint32_t m_downloadingMwmCounter;
TMwmCounter m_downloadingMwmCounter;

/// If it's not an expandable node, |m_mwmSize| is size of one mwm according to countries.txt.
/// Otherwise |m_mwmSize| is the sum of all mwm file sizes which belong to the group
/// according to countries.txt.
size_t m_mwmSize;
TMwmSize m_mwmSize;

/// If it's not an expandable node, |m_localMwmSize| is size of one downloaded mwm.
/// Otherwise |m_localNodeSize| is the sum of all mwm file sizes which belong to the group and
/// have been downloaded.
size_t m_localMwmSize;
TMwmSize m_localMwmSize;

/// Size of leaves of the node which have been downloaded
/// plus which is in progress of downloading (zero or one)
/// plus which are staying in queue.
/// \note The size of leaves is the size is written in countries.txt.
size_t m_downloadingMwmSize;
TMwmSize m_downloadingMwmSize;

/// The name of the node in a local language. That means the language dependent on
/// a device locale.
Expand All @@ -88,7 +89,7 @@ struct NodeAttrs
/// Locale language is a language set by Storage::SetLocale().
/// \note Most number of nodes have only first level parent. But in case of a disputed territories
/// an mwm could have two or even more parents. See Country description for details.
vector<CountryIdAndName> m_topmostParentInfo;
vector<CountryIdAndName> m_topmostParentInfo;

/// Progress of downloading for the node expandable or not. It reflects downloading progress in case of
/// downloading and updating mwm.
Expand Down Expand Up @@ -294,8 +295,8 @@ class Storage
{
UpdateInfo() : m_numberOfMwmFilesToUpdate(0), m_totalUpdateSizeInBytes(0) {}

size_t m_numberOfMwmFilesToUpdate;
size_t m_totalUpdateSizeInBytes;
uint32_t m_numberOfMwmFilesToUpdate;
uint64_t m_totalUpdateSizeInBytes;
};

struct StatusCallback
Expand Down
4 changes: 3 additions & 1 deletion storage/storage_defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ namespace storage
};
string DebugPrint(StatusAndError statusAndError);

using TLocalAndRemoteSize = pair<uint64_t, uint64_t>;
using TMwmCounter = uint32_t;
using TMwmSize = uint64_t;
using TLocalAndRemoteSize = pair<TMwmSize, TMwmSize>;

StatusAndError ParseStatus(Status innerStatus);
} // namespace storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void DownloadGroup(Storage & storage, bool oneByOne)
TEST(downloaded.empty(), ());

// Check status for the all children nodes is set to ENotDownloaded.
size_t totalGroupSize = 0;
TMwmSize totalGroupSize = 0;
for (auto const & countryId : children)
{
TEST_EQUAL(Status::ENotDownloaded, storage.CountryStatusEx(countryId), ());
Expand Down
2 changes: 1 addition & 1 deletion storage/storage_tests/storage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void OnCountryDownloaded(TCountryId const & countryId, TLocalFilePtr const local
LOG(LINFO, ("OnCountryDownloaded:", *localFile));
}

TLocalFilePtr CreateDummyMapFile(CountryFile const & countryFile, int64_t version, size_t size)
TLocalFilePtr CreateDummyMapFile(CountryFile const & countryFile, int64_t version, uint64_t size)
{
TLocalFilePtr localFile = PreparePlaceForCountryFiles(version, string() /* dataDir */, countryFile);
TEST(localFile.get(), ("Can't prepare place for", countryFile, "(version", version, ")"));
Expand Down

0 comments on commit d13c4b9

Please sign in to comment.