Factor out storage::TIndex to separate module.

This commit is contained in:
vng 2012-12-13 13:28:22 +03:00 committed by Alex Zolotarev
parent 01ee887acd
commit 0280b0b129
5 changed files with 62 additions and 45 deletions

17
storage/index.cpp Normal file
View file

@ -0,0 +1,17 @@
#include "index.hpp"
#include "../std/sstream.hpp"
namespace storage
{
// GCC bug? Can't move initialization to hpp file (linker error).
const int TIndex::INVALID = -1;
string DebugPrint(TIndex const & r)
{
ostringstream out;
out << "storage::TIndex(" << r.m_group << ", " << r.m_country << ", " << r.m_region << ")";
return out.str();
}
}

41
storage/index.hpp Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include "../std/string.hpp"
namespace storage
{
struct TIndex
{
static int const INVALID;
int m_group;
int m_country;
int m_region;
TIndex(int group = INVALID, int country = INVALID, int region = INVALID)
: m_group(group), m_country(country), m_region(region) {}
bool operator==(TIndex const & other) const
{
return (m_group == other.m_group &&
m_country == other.m_country &&
m_region == other.m_region);
}
bool operator!=(TIndex const & other) const
{
return !(*this == other);
}
bool operator<(TIndex const & other) const
{
if (m_group != other.m_group)
return m_group < other.m_group;
else if (m_country != other.m_country)
return m_country < other.m_country;
return m_region < other.m_region;
}
};
string DebugPrint(TIndex const & r);
}

View file

@ -28,15 +28,6 @@ using namespace downloader;
namespace storage
{
const int TIndex::INVALID = -1;
string DebugPrint(TIndex const & r)
{
ostringstream out;
out << "storage::TIndex(" << r.m_group << ", " << r.m_country << ", " << r.m_region << ")";
return out.str();
}
/*
static string ErrorString(DownloadResultT res)
{

View file

@ -1,6 +1,7 @@
#pragma once
#include "../storage/country.hpp"
#include "country.hpp"
#include "index.hpp"
#include "../platform/http_request.hpp"
@ -27,41 +28,6 @@ namespace storage
EOnDiskOutOfDate
};
struct TIndex
{
static int const INVALID;
int m_group;
int m_country;
int m_region;
TIndex(int group = INVALID, int country = INVALID, int region = INVALID)
: m_group(group), m_country(country), m_region(region) {}
bool operator==(TIndex const & other) const
{
return (m_group == other.m_group &&
m_country == other.m_country &&
m_region == other.m_region);
}
bool operator!=(TIndex const & other) const
{
return !(*this == other);
}
bool operator<(TIndex const & other) const
{
if (m_group != other.m_group)
return m_group < other.m_group;
else if (m_country != other.m_country)
return m_country < other.m_country;
return m_region < other.m_region;
}
};
string DebugPrint(TIndex const & r);
/// Can be used to store local maps and/or maps available for download
class Storage
{

View file

@ -19,9 +19,11 @@ HEADERS += \
country_polygon.hpp \
country_info.hpp \
country_decl.hpp \
index.hpp \
SOURCES += \
country.cpp \
storage.cpp \
country_info.cpp \
country_decl.cpp \
index.cpp \