From 8a79a020ebc50a553c4db5f49c141bb804893409 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 20 Dec 2010 16:12:25 +0000 Subject: [PATCH] Created storage library --- indexer/data_header.hpp | 5 +- indexer/indexer.pro | 3 - indexer/indexer_tests/indexer_tests.pro | 1 - indexer/indexer_tool/indexer_tool.cpp | 5 +- indexer/indexer_tool/indexer_tool.pro | 2 +- indexer/indexer_tool/update_generator.cpp | 26 +++---- map/map.pro | 6 -- map/map_tests/map_tests.pro | 1 - omim.pro | 1 + qt/draw_widget.cpp | 5 +- qt/draw_widget.hpp | 4 +- qt/mainwindow.hpp | 4 +- qt/qt.pro | 2 +- qt/update_dialog.cpp | 10 +-- qt/update_dialog.hpp | 12 ++-- {map => storage}/countries.cpp | 0 {map => storage}/countries.hpp | 0 {indexer => storage}/country.cpp | 4 +- {indexer => storage}/country.hpp | 12 ++-- storage/data_header.cpp | 47 +++++++++++++ storage/data_header.hpp | 69 +++++++++++++++++++ storage/data_header_reader.cpp | 54 +++++++++++++++ storage/data_header_reader.hpp | 17 +++++ {indexer => storage}/defines.hpp | 0 {map => storage}/simple_tree.hpp | 0 {map => storage}/storage.cpp | 4 +- {map => storage}/storage.hpp | 6 +- storage/storage.pro | 20 ++++++ .../storage_tests}/country_test.cpp | 16 +++-- .../storage_tests}/simple_tree_test.cpp | 0 storage/storage_tests/storage_tests.pro | 19 +++++ 31 files changed, 289 insertions(+), 66 deletions(-) rename {map => storage}/countries.cpp (100%) rename {map => storage}/countries.hpp (100%) rename {indexer => storage}/country.cpp (98%) rename {indexer => storage}/country.hpp (93%) create mode 100644 storage/data_header.cpp create mode 100644 storage/data_header.hpp create mode 100644 storage/data_header_reader.cpp create mode 100644 storage/data_header_reader.hpp rename {indexer => storage}/defines.hpp (100%) rename {map => storage}/simple_tree.hpp (100%) rename {map => storage}/storage.cpp (99%) rename {map => storage}/storage.hpp (96%) create mode 100644 storage/storage.pro rename {indexer/indexer_tests => storage/storage_tests}/country_test.cpp (67%) rename {map/map_tests => storage/storage_tests}/simple_tree_test.cpp (100%) create mode 100644 storage/storage_tests/storage_tests.pro diff --git a/indexer/data_header.hpp b/indexer/data_header.hpp index 936248d9a7..3d719deca2 100644 --- a/indexer/data_header.hpp +++ b/indexer/data_header.hpp @@ -2,8 +2,6 @@ #include "../base/std_serialization.hpp" -#include "../indexer/defines.hpp" - #include "../coding/streams_sink.hpp" #include "../geometry/rect2d.hpp" @@ -18,6 +16,9 @@ namespace feature /// All file sizes are in bytes class DataHeader { + /// @TODO move version somewhere else + static int32_t const MAPS_MAJOR_VERSION_BINARY_FORMAT = 1; + private: typedef tuple< pair // boundary; diff --git a/indexer/indexer.pro b/indexer/indexer.pro index ab0b925bfc..a8c4b82ed7 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -38,7 +38,6 @@ SOURCES += \ feature_visibility.cpp \ data_header.cpp \ data_header_reader.cpp \ - country.cpp \ HEADERS += \ feature.hpp \ @@ -67,6 +66,4 @@ HEADERS += \ feature_visibility.hpp \ data_header.hpp \ data_header_reader.hpp \ - country.hpp \ - defines.hpp \ tree_structure.hpp \ diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index f597267dea..3e2ae1842d 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -32,6 +32,5 @@ SOURCES += \ sort_and_merge_intervals_test.cpp \ feature_test.cpp \ data_header_test.cpp \ - country_test.cpp \ feature_bucketer_test.cpp \ diff --git a/indexer/indexer_tool/indexer_tool.cpp b/indexer/indexer_tool/indexer_tool.cpp index 1078e423c6..4f63d0e94c 100644 --- a/indexer/indexer_tool/indexer_tool.cpp +++ b/indexer/indexer_tool/indexer_tool.cpp @@ -10,7 +10,8 @@ #include "../index_builder.hpp" #include "../osm_decl.hpp" #include "../data_header.hpp" -#include "../defines.hpp" + +#include "../../storage/defines.hpp" #include "../../platform/platform.hpp" @@ -140,7 +141,7 @@ int main(int argc, char ** argv) if (FLAGS_generate_index) { LOG(LINFO, ("Generating index for", datFile)); - string const indexFile = mapinfo::IndexFileForDatFile(datFile); + string const indexFile = storage::IndexFileForDatFile(datFile); if (!indexer::BuildIndexFromDatFile(indexFile, datFile, FLAGS_intermediate_data_path + FLAGS_output)) { diff --git a/indexer/indexer_tool/indexer_tool.pro b/indexer/indexer_tool/indexer_tool.pro index a4254d5ee1..4161af3020 100644 --- a/indexer/indexer_tool/indexer_tool.pro +++ b/indexer/indexer_tool/indexer_tool.pro @@ -1,7 +1,7 @@ # Indexer binary ROOT_DIR = ../.. -DEPENDENCIES = map indexer platform geometry coding base gflags expat sgitess version +DEPENDENCIES = map storage indexer platform geometry coding base gflags expat sgitess version include($$ROOT_DIR/common.pri) diff --git a/indexer/indexer_tool/update_generator.cpp b/indexer/indexer_tool/update_generator.cpp index a289f74e51..57051b52ee 100644 --- a/indexer/indexer_tool/update_generator.cpp +++ b/indexer/indexer_tool/update_generator.cpp @@ -4,8 +4,8 @@ #include "../../platform/platform.hpp" -#include "../../indexer/country.hpp" -#include "../../indexer/defines.hpp" +#include "../../storage/country.hpp" +#include "../../storage/defines.hpp" #include "../../base/string_utils.hpp" #include "../../base/logging.hpp" @@ -25,10 +25,12 @@ #define DIR_SEP '/' #endif +using namespace storage; + namespace update { typedef vector TCellIds; - typedef pair TCountryCells; + typedef pair TCountryCells; typedef vector TCountryCellsContainer; string ChopExtension(string const & nameWithExtension) @@ -92,7 +94,7 @@ namespace update string fullPath = path + *itGroup + DIR_SEP + *itCountry + DIR_SEP + *itRegion; if (LoadCountryCells(fullPath, cells)) { - outCells.push_back(TCountryCells(mapinfo::Country(ChopExtension(*itGroup), + outCells.push_back(TCountryCells(Country(ChopExtension(*itGroup), ChopExtension(*itCountry), ChopExtension(*itRegion)), cells)); @@ -113,7 +115,7 @@ namespace update string fullPath = path + *itGroup + DIR_SEP + *itCountry; if (LoadCountryCells(fullPath, cells)) { - outCells.push_back(TCountryCells(mapinfo::Country(ChopExtension(*itGroup), + outCells.push_back(TCountryCells(Country(ChopExtension(*itGroup), ChopExtension(*itCountry), ""), cells)); @@ -145,11 +147,11 @@ namespace update // data file uint64_t fileSize = 0; CHECK(GetPlatform().GetFileSize(m_path + m_file, fileSize), ("Non-existing file?")); - cells.first.AddUrl(mapinfo::TUrl(m_url + m_file, fileSize)); + cells.first.AddUrl(TUrl(m_url + m_file, fileSize)); // index file - string const indexFileName = mapinfo::IndexFileForDatFile(m_file); + string const indexFileName = IndexFileForDatFile(m_file); CHECK(GetPlatform().GetFileSize(m_path + indexFileName, fileSize), ("Non-existing file?")); - cells.first.AddUrl(mapinfo::TUrl(m_url + indexFileName, fileSize)); + cells.first.AddUrl(TUrl(m_url + indexFileName, fileSize)); break; } } @@ -158,10 +160,10 @@ namespace update class CountryAdder { - mapinfo::TCountriesContainer & m_countries; + TCountriesContainer & m_countries; public: - CountryAdder(mapinfo::TCountriesContainer & outCountries) + CountryAdder(TCountriesContainer & outCountries) : m_countries(outCountries) {} void operator()(TCountryCells const & cells) { @@ -173,7 +175,7 @@ namespace update class GroupSorter { public: - void operator()(mapinfo::TCountriesContainer::value_type & toSort) + void operator()(TCountriesContainer::value_type & toSort) { sort(toSort.second.begin(), toSort.second.end()); } @@ -204,7 +206,7 @@ namespace update } // save update list - mapinfo::TCountriesContainer countries; + TCountriesContainer countries; for_each(countriesCells.begin(), countriesCells.end(), CountryAdder(countries)); // sort groups diff --git a/map/map.pro b/map/map.pro index 2ca7621717..a1cbd82243 100644 --- a/map/map.pro +++ b/map/map.pro @@ -18,11 +18,8 @@ HEADERS += \ draw_processor.hpp \ draw_info.hpp \ window_handle.hpp \ - storage.hpp \ render_queue.hpp \ render_queue_routine.hpp \ - simple_tree.hpp \ - countries.hpp \ SOURCES += \ feature_vec_model.cpp \ @@ -30,11 +27,8 @@ SOURCES += \ navigator.cpp \ drawer_yg.cpp \ draw_processor.cpp \ - storage.cpp \ render_queue.cpp \ render_queue_routine.cpp \ - countries.cpp \ - !iphonesimulator-g++42 { !iphonedevice-g++42 { diff --git a/map/map_tests/map_tests.pro b/map/map_tests/map_tests.pro index 9ac9bba602..d3772e7a03 100644 --- a/map/map_tests/map_tests.pro +++ b/map/map_tests/map_tests.pro @@ -20,4 +20,3 @@ SOURCES += \ ../../testing/testingmain.cpp \ navigator_test.cpp \ map_foreach_test.cpp \ - simple_tree_test.cpp \ diff --git a/omim.pro b/omim.pro index e643101c20..a5132797a1 100644 --- a/omim.pro +++ b/omim.pro @@ -12,6 +12,7 @@ SUBDIRS = 3party \ platform platform/platform_tests \ yg \ indexer \ + storage storage/storage_tests \ map \ map/map_tests \ version \ diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 069158a711..d1f04854fc 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -1,17 +1,18 @@ #include "draw_widget.hpp" #include "proxystyle.hpp" -#include "../map/storage.hpp" +#include "../storage/storage.hpp" #include #include #include "../base/start_mem_debug.hpp" +using namespace storage; namespace qt { - DrawWidget::DrawWidget(QWidget * pParent, mapinfo::Storage & storage) + DrawWidget::DrawWidget(QWidget * pParent, Storage & storage) : base_type(pParent), m_handle(new handle_t(this)), m_framework(m_handle), diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp index bce80cbac1..01207daa10 100644 --- a/qt/draw_widget.hpp +++ b/qt/draw_widget.hpp @@ -12,7 +12,7 @@ class FileReader; template class ReaderSource; class FileWriter; -namespace mapinfo { class Storage; } +namespace storage { class Storage; } class QSlider; @@ -49,7 +49,7 @@ namespace qt void ScaleChanged(int action); public: - DrawWidget(QWidget * pParent, mapinfo::Storage & storage); + DrawWidget(QWidget * pParent, storage::Storage & storage); void SetScaleControl(QSlider * pScale); diff --git a/qt/mainwindow.hpp b/qt/mainwindow.hpp index 0b0162f1e1..95882fc53b 100644 --- a/qt/mainwindow.hpp +++ b/qt/mainwindow.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../map/storage.hpp" +#include "../storage/storage.hpp" #include @@ -19,7 +19,7 @@ namespace qt QDockWidget * m_pClassifDock; //FindTableWnd * m_pFindTable; - mapinfo::Storage m_Storage; + storage::Storage m_Storage; Q_OBJECT diff --git a/qt/qt.pro b/qt/qt.pro index f85840095f..4aa4637274 100644 --- a/qt/qt.pro +++ b/qt/qt.pro @@ -1,6 +1,6 @@ # Main application in qt. ROOT_DIR = .. -DEPENDENCIES = map indexer platform yg geometry coding base freetype expat version +DEPENDENCIES = map storage indexer yg platform geometry coding base freetype expat version include($$ROOT_DIR/common.pri) diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index 3ee5f45db6..70ec013699 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -9,7 +9,7 @@ #include #include -using namespace mapinfo; +using namespace storage; enum { @@ -42,7 +42,7 @@ namespace qt }; //////////////////////////////////////////////////////////////////////////////// - UpdateDialog::UpdateDialog(QWidget * parent, mapinfo::Storage & storage) + UpdateDialog::UpdateDialog(QWidget * parent, Storage & storage) : QDialog(parent), m_storage(storage) { // table with countries list @@ -141,7 +141,7 @@ namespace qt } QColor rowColor; - mapinfo::TStatus status = m_storage.CountryStatus(index); + TStatus status = m_storage.CountryStatus(index); switch (status) { case ENotDownloaded: rowColor = COLOR_NOTDOWNLOADED; break; @@ -209,12 +209,12 @@ namespace qt m_table->sortByColumn(KItemIndexCountry); } - void UpdateDialog::OnCountryChanged(mapinfo::TIndex const & index) + void UpdateDialog::OnCountryChanged(TIndex const & index) { UpdateRowWithCountryInfo(index); } - void UpdateDialog::OnCountryDownloadProgress(mapinfo::TIndex const & index, TDownloadProgress const & progress) + void UpdateDialog::OnCountryDownloadProgress(TIndex const & index, TDownloadProgress const & progress) { int row = GetRowByGroupAndCountryIndex(*m_table, index); if (row != -1) diff --git a/qt/update_dialog.hpp b/qt/update_dialog.hpp index 5e1db36f2a..dfdc2244a5 100644 --- a/qt/update_dialog.hpp +++ b/qt/update_dialog.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../map/storage.hpp" +#include "../storage/storage.hpp" #include @@ -14,13 +14,13 @@ namespace qt Q_OBJECT public: - UpdateDialog(QWidget * parent, mapinfo::Storage & storage); + UpdateDialog(QWidget * parent, storage::Storage & storage); ~UpdateDialog(); /// @name Called from storage to notify GUI //@{ - void OnCountryChanged(mapinfo::TIndex const & index); - void OnCountryDownloadProgress(mapinfo::TIndex const & index, + void OnCountryChanged(storage::TIndex const & index); + void OnCountryDownloadProgress(storage::TIndex const & index, TDownloadProgress const & progress); //@} @@ -29,10 +29,10 @@ namespace qt private: void FillTable(); - void UpdateRowWithCountryInfo(mapinfo::TIndex const & index); + void UpdateRowWithCountryInfo(storage::TIndex const & index); private: QTableWidget * m_table; - mapinfo::Storage & m_storage; + storage::Storage & m_storage; }; } // namespace qt diff --git a/map/countries.cpp b/storage/countries.cpp similarity index 100% rename from map/countries.cpp rename to storage/countries.cpp diff --git a/map/countries.hpp b/storage/countries.hpp similarity index 100% rename from map/countries.hpp rename to storage/countries.hpp diff --git a/indexer/country.cpp b/storage/country.cpp similarity index 98% rename from indexer/country.cpp rename to storage/country.cpp index b502b58326..f63f1fef11 100644 --- a/indexer/country.cpp +++ b/storage/country.cpp @@ -10,7 +10,7 @@ #include "../indexer/data_header.hpp" #include "../indexer/data_header_reader.hpp" -namespace mapinfo +namespace storage { string FileNameFromUrl(string const & url) { @@ -104,7 +104,7 @@ namespace mapinfo //////////////////////////////////////////////////////////////////////// - template TArchive & operator << (TArchive & ar, mapinfo::Country const & country) + template TArchive & operator << (TArchive & ar, storage::Country const & country) { ar << country.m_group; ar << country.m_country; diff --git a/indexer/country.hpp b/storage/country.hpp similarity index 93% rename from indexer/country.hpp rename to storage/country.hpp index 36d757426d..85fcf3dffe 100644 --- a/indexer/country.hpp +++ b/storage/country.hpp @@ -1,20 +1,20 @@ #pragma once +#include "defines.hpp" + #include "../base/std_serialization.hpp" #include "../coding/streams_sink.hpp" #include "../geometry/rect2d.hpp" -#include "../indexer/defines.hpp" - #include "../std/string.hpp" #include "../std/vector.hpp" class Reader; class Writer; -namespace mapinfo +namespace storage { typedef pair TUrl; typedef vector TUrlContainer; @@ -27,8 +27,8 @@ namespace mapinfo /// Serves as a proxy between GUI and downloaded files class Country { - template friend TArchive & operator << (TArchive & ar, mapinfo::Country const & country); - template friend TArchive & operator >> (TArchive & ar, mapinfo::Country & country); + template friend TArchive & operator << (TArchive & ar, storage::Country const & country); + template friend TArchive & operator >> (TArchive & ar, storage::Country & country); private: /// Europe, Asia etc. @@ -67,7 +67,7 @@ namespace mapinfo uint64_t RemoteSize() const; }; - template TArchive & operator >> (TArchive & ar, mapinfo::Country & country) + template TArchive & operator >> (TArchive & ar, storage::Country & country) { ar >> country.m_group; ar >> country.m_country; diff --git a/storage/data_header.cpp b/storage/data_header.cpp new file mode 100644 index 0000000000..4b3805b2c7 --- /dev/null +++ b/storage/data_header.cpp @@ -0,0 +1,47 @@ +#include "data_header.hpp" + +#include "../base/string_utils.hpp" + +#include "../platform/platform.hpp" + +#include "../coding/file_writer.hpp" + +#include "../indexer/cell_id.hpp" + +#include "../base/start_mem_debug.hpp" + +namespace feature +{ + + DataHeader::DataHeader() + { + Reset(); + } + + namespace + { + struct do_reset + { + void operator() (string & t, int) { t.clear(); } + void operator() (uint64_t & t, int) { t = 0; } + void operator() (pair &, int) {} + }; + } + + void DataHeader::Reset() + { + do_reset doReset; + for_each_tuple(m_params, doReset); + } + + m2::RectD const DataHeader::Bounds() const + { + return Int64ToRect(Get()); + } + + void DataHeader::SetBounds(m2::RectD const & r) + { + Set(RectToInt64(r)); + } + +} diff --git a/storage/data_header.hpp b/storage/data_header.hpp new file mode 100644 index 0000000000..fa7decf310 --- /dev/null +++ b/storage/data_header.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include "../base/std_serialization.hpp" + +#include "../storage/defines.hpp" + +#include "../coding/streams_sink.hpp" + +#include "../geometry/rect2d.hpp" + +#include "../std/string.hpp" +#include "../std/tuple.hpp" + +#include "../base/start_mem_debug.hpp" + +namespace feature +{ + /// All file sizes are in bytes + class DataHeader + { + private: + typedef tuple< + pair // boundary; + > params_t; + params_t m_params; + + enum param_t { EBoundary }; + + template + typename tuple_element::type const & Get() const { return m_params.get(); } + template + void Set(T const & t) { m_params.get() = t; } + + public: + DataHeader(); + + /// Zeroes all fields + void Reset(); + + m2::RectD const Bounds() const; + void SetBounds(m2::RectD const & r); + + /// @name Serialization + //@{ + template void Save(TWriter & writer) const + { + stream::SinkWriterStream w(writer); + w << MAPS_MAJOR_VERSION_BINARY_FORMAT; + serial::save_tuple(w, m_params); + } + /// @return false if header can't be read (invalid or newer version format) + template bool Load(TReader & reader) + { + stream::SinkReaderStream r(reader); + + uint32_t ver; + r >> ver; + if (ver > MAPS_MAJOR_VERSION_BINARY_FORMAT) + return false; + Reset(); + serial::load_tuple(r, m_params); + return true; + } + //@} + }; + +} + +#include "../base/stop_mem_debug.hpp" diff --git a/storage/data_header_reader.cpp b/storage/data_header_reader.cpp new file mode 100644 index 0000000000..be77ac65bc --- /dev/null +++ b/storage/data_header_reader.cpp @@ -0,0 +1,54 @@ +#include "data_header_reader.hpp" +#include "data_header.hpp" + +#include "../coding/file_reader.hpp" +#include "../coding/file_writer.hpp" + +#include "../base/start_mem_debug.hpp" + +namespace feature +{ + uint64_t GetSkipHeaderSize(Reader const & reader) + { + uint64_t const headerSize = ReadPrimitiveFromPos(reader, 0); + return headerSize + sizeof(uint64_t); + } + + uint64_t ReadDataHeader(string const & datFileName, feature::DataHeader & outHeader) + { + try + { + FileReader reader(datFileName); + + uint64_t const toSkip = GetSkipHeaderSize(reader); + + ReaderSource src(reader); + src.Skip(sizeof(uint64_t)); + + outHeader.Load(src); + + return toSkip; + } + catch (Reader::Exception const & e) + { + ASSERT(false, ("Error reading header from dat file", e.what())); + return 0; + } + } + + void WriteDataHeader(Writer & writer, feature::DataHeader const & header) + { + typedef vector TBuffer; + TBuffer buffer; + MemWriter w(buffer); + + header.Save(w); + + uint64_t const sz = buffer.size(); + WriteToSink(writer, sz); + + if (sz > 0) + writer.Write(&buffer[0], buffer.size()); + } + +} diff --git a/storage/data_header_reader.hpp b/storage/data_header_reader.hpp new file mode 100644 index 0000000000..c731d10e57 --- /dev/null +++ b/storage/data_header_reader.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../base/base.hpp" + +#include "../std/string.hpp" + +class Writer; +class Reader; + +namespace feature +{ + class DataHeader; + + /// @return total header size, which should be skipped for data read, or 0 if error + uint64_t GetSkipHeaderSize(Reader const & reader); + uint64_t ReadDataHeader(string const & datFileName, feature::DataHeader & outHeader); + void WriteDataHeader(Writer & writer, feature::DataHeader const & header); +} diff --git a/indexer/defines.hpp b/storage/defines.hpp similarity index 100% rename from indexer/defines.hpp rename to storage/defines.hpp diff --git a/map/simple_tree.hpp b/storage/simple_tree.hpp similarity index 100% rename from map/simple_tree.hpp rename to storage/simple_tree.hpp diff --git a/map/storage.cpp b/storage/storage.cpp similarity index 99% rename from map/storage.cpp rename to storage/storage.cpp index 4edf19f65a..f9da514e7a 100644 --- a/map/storage.cpp +++ b/storage/storage.cpp @@ -12,7 +12,7 @@ #include "../base/start_mem_debug.hpp" -namespace mapinfo +namespace storage { static bool IsMapValid(string const & datFile) { @@ -266,7 +266,7 @@ namespace mapinfo { GetDownloadManager().DownloadFile( it->first.c_str(), - (GetPlatform().WritablePathForFile(mapinfo::FileNameFromUrl(it->first))).c_str(), + (GetPlatform().WritablePathForFile(FileNameFromUrl(it->first))).c_str(), boost::bind(&Storage::OnMapDownloadFinished, this, _1, _2), boost::bind(&Storage::OnMapDownloadProgress, this, _1, _2), true); // enabled resume support by default diff --git a/map/storage.hpp b/storage/storage.hpp similarity index 96% rename from map/storage.hpp rename to storage/storage.hpp index 88fc3286a5..39ce834dac 100644 --- a/map/storage.hpp +++ b/storage/storage.hpp @@ -3,8 +3,8 @@ #include "../platform/download_manager.hpp" #include "../platform/platform.hpp" -#include "../indexer/defines.hpp" -#include "../indexer/country.hpp" +#include "../storage/defines.hpp" +#include "../storage/country.hpp" #include "../std/vector.hpp" #include "../std/map.hpp" @@ -13,7 +13,7 @@ #include -namespace mapinfo +namespace storage { /// Used in GUI enum TStatus diff --git a/storage/storage.pro b/storage/storage.pro new file mode 100644 index 0000000000..ed9dfe27ce --- /dev/null +++ b/storage/storage.pro @@ -0,0 +1,20 @@ +# Storage library. + +TARGET = storage +TEMPLATE = lib +CONFIG += staticlib + +ROOT_DIR = .. +DEPENDENCIES = platform geometry coding base + +include($$ROOT_DIR/common.pri) + +SOURCES += \ + country.cpp \ + storage.cpp \ + +HEADERS += \ + defines.hpp \ + country.hpp \ + simple_tree.hpp \ + storage.hpp \ diff --git a/indexer/indexer_tests/country_test.cpp b/storage/storage_tests/country_test.cpp similarity index 67% rename from indexer/indexer_tests/country_test.cpp rename to storage/storage_tests/country_test.cpp index 1b67c2d008..181e218c8b 100644 --- a/indexer/indexer_tests/country_test.cpp +++ b/storage/storage_tests/country_test.cpp @@ -7,29 +7,31 @@ #include "../../base/start_mem_debug.hpp" +using namespace storage; + UNIT_TEST(CountrySerialization) { string const TEST_URL = "http://someurl.com/somemap.dat"; uint64_t const TEST_SIZE = 123456790; char const * TEST_FILE_NAME = "some_temporary_update_file.tmp"; - mapinfo::Country c("North America", "USA", "Alaska"); - c.AddUrl(mapinfo::TUrl(TEST_URL, TEST_SIZE)); + Country c("North America", "USA", "Alaska"); + c.AddUrl(TUrl(TEST_URL, TEST_SIZE)); { - mapinfo::TCountriesContainer countries; + TCountriesContainer countries; countries[c.Group()].push_back(c); FileWriter writer(TEST_FILE_NAME); - mapinfo::SaveCountries(countries, writer); + SaveCountries(countries, writer); } - mapinfo::TCountriesContainer loadedCountries; + TCountriesContainer loadedCountries; { - TEST( mapinfo::LoadCountries(loadedCountries, TEST_FILE_NAME), ()); + TEST( LoadCountries(loadedCountries, TEST_FILE_NAME), ()); } TEST_GREATER(loadedCountries.size(), 0, ()); - mapinfo::Country const & c2 = loadedCountries.begin()->second.front(); + Country const & c2 = loadedCountries.begin()->second.front(); TEST_EQUAL(c.Group(), loadedCountries.begin()->first, ()); TEST_EQUAL(c.Group(), c2.Group(), ()); TEST_EQUAL(c.Name(), c2.Name(), ()); diff --git a/map/map_tests/simple_tree_test.cpp b/storage/storage_tests/simple_tree_test.cpp similarity index 100% rename from map/map_tests/simple_tree_test.cpp rename to storage/storage_tests/simple_tree_test.cpp diff --git a/storage/storage_tests/storage_tests.pro b/storage/storage_tests/storage_tests.pro new file mode 100644 index 0000000000..4dd164ee52 --- /dev/null +++ b/storage/storage_tests/storage_tests.pro @@ -0,0 +1,19 @@ +# Storage library tests. + +TARGET = storage_tests +CONFIG += console +CONFIG -= app_bundle +TEMPLATE = app + +ROOT_DIR = ../.. +DEPENDENCIES = storage geometry platform coding base + +include($$ROOT_DIR/common.pri) + +QT += core + +HEADERS += + +SOURCES += \ + ../../testing/testingmain.cpp \ +# simple_tree_test.cpp \