Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Yershov <yershov@corp.mail.ru>2014-12-11 21:37:16 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:35:24 +0300
commitb79ade75a8885d627646c474bbc5f04c268de5ef (patch)
tree3ecde383c0958389e1078b0bde7ba66510ebb237
parentf6576ce2aa557fb53fffd3ebdeaee0af29af6e41 (diff)
Add generator_tool options for work with file instead stdin
-rw-r--r--generator/data_generator.cpp17
-rw-r--r--generator/data_generator.hpp2
-rw-r--r--generator/feature_generator.cpp17
-rw-r--r--generator/feature_generator.hpp2
-rw-r--r--generator/generator_tool/generator_tool.cpp31
-rw-r--r--generator/xml_element.cpp26
-rw-r--r--generator/xml_element.hpp1
-rw-r--r--platform/platform.cpp3
-rw-r--r--platform/platform.hpp5
9 files changed, 87 insertions, 17 deletions
diff --git a/generator/data_generator.cpp b/generator/data_generator.cpp
index 61e9adc965..afabe00940 100644
--- a/generator/data_generator.cpp
+++ b/generator/data_generator.cpp
@@ -112,7 +112,7 @@ public:
};
template <class TNodesHolder>
-bool GenerateImpl(string const & dir)
+bool GenerateImpl(string const & dir, std::string const &osm_filename=std::string())
{
try
{
@@ -121,7 +121,14 @@ bool GenerateImpl(string const & dir)
holder_t holder(nodes, dir);
FirstPassParser<holder_t> parser(holder);
- ParseXMLFromStdIn(parser);
+ if(osm_filename.empty())
+ {
+ ParseXMLFromStdIn(parser);
+ }
+ else
+ {
+ ParseXMLFromFile(parser, osm_filename);
+ }
LOG(LINFO, ("Added points count = ", nodes.GetCount()));
@@ -136,12 +143,12 @@ bool GenerateImpl(string const & dir)
return true;
}
-bool GenerateToFile(string const & dir, bool lightNodes)
+bool GenerateToFile(string const & dir, bool lightNodes, std::string const &osm_filename)
{
if (lightNodes)
- return GenerateImpl<points_in_file_light>(dir);
+ return GenerateImpl<points_in_file_light>(dir, osm_filename);
else
- return GenerateImpl<points_in_file>(dir);
+ return GenerateImpl<points_in_file>(dir, osm_filename);
}
}
diff --git a/generator/data_generator.hpp b/generator/data_generator.hpp
index c836c9feed..5677bff1cc 100644
--- a/generator/data_generator.hpp
+++ b/generator/data_generator.hpp
@@ -4,5 +4,5 @@
namespace data
{
- bool GenerateToFile(string const & dir, bool lightNodes);
+ bool GenerateToFile(string const & dir, bool lightNodes, string const &osm_filename=string());
}
diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp
index b75a45164e..c41ddc5730 100644
--- a/generator/feature_generator.cpp
+++ b/generator/feature_generator.cpp
@@ -419,7 +419,7 @@ public:
}
template <class TNodesHolder>
-bool GenerateImpl(GenerateInfo & info)
+ bool GenerateImpl(GenerateInfo & info, std::string const &osm_filename=std::string())
{
try
{
@@ -435,7 +435,14 @@ bool GenerateImpl(GenerateInfo & info)
info.m_makeCoasts ? classif().GetCoastType() : 0,
info.m_addressFile);
- ParseXMLFromStdIn(parser);
+ if(osm_filename.empty())
+ {
+ ParseXMLFromStdIn(parser);
+ }
+ else
+ {
+ ParseXMLFromFile(parser, osm_filename);
+ }
// Stop if coasts are not merged and FLAG_fail_on_coasts is set
if (!bucketer.Finish())
@@ -451,12 +458,12 @@ bool GenerateImpl(GenerateInfo & info)
return true;
}
-bool GenerateFeatures(GenerateInfo & info, bool lightNodes)
+bool GenerateFeatures(GenerateInfo & info, bool lightNodes, std::string const &osm_filename)
{
if (lightNodes)
- return GenerateImpl<points_in_map>(info);
+ return GenerateImpl<points_in_map>(info, osm_filename);
else
- return GenerateImpl<points_in_file>(info);
+ return GenerateImpl<points_in_file>(info, osm_filename);
}
}
diff --git a/generator/feature_generator.hpp b/generator/feature_generator.hpp
index 2817c3f0be..5eff8e95c2 100644
--- a/generator/feature_generator.hpp
+++ b/generator/feature_generator.hpp
@@ -14,7 +14,7 @@ namespace feature
{
struct GenerateInfo;
- bool GenerateFeatures(GenerateInfo & info, bool lightNodes);
+ bool GenerateFeatures(GenerateInfo & info, bool lightNodes, std::string const &osm_filename=std::string());
// Writes features to dat file.
class FeaturesCollector
diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp
index 4fd83ca6a3..a127c75446 100644
--- a/generator/generator_tool/generator_tool.cpp
+++ b/generator/generator_tool/generator_tool.cpp
@@ -64,6 +64,8 @@ DEFINE_bool(fail_on_coasts, false, "Stop and exit with '255' code if some coastl
DEFINE_string(address_file_name, "", "Output file name for storing full addresses.");
DEFINE_string(export_poly_path, "", "Output dir for osm .poly files created from .borders (countires are read from polygons.lst)");
DEFINE_string(osrm_file_name, "", "Input osrm file to generate routing info");
+DEFINE_string(osm_file_name, "", "Input osm area file");
+DEFINE_string(user_resource_path, "", "User defined resource path for classificator.txt and etc.");
string AddSlashIfNeeded(string const & str)
@@ -90,6 +92,11 @@ int main(int argc, char ** argv)
Platform & pl = GetPlatform();
+ if(!FLAGS_user_resource_path.empty())
+ {
+ pl.AddOptionalPath(FLAGS_user_resource_path);
+ }
+
string const path =
FLAGS_data_path.empty() ? pl.WritableDir() : AddSlashIfNeeded(FLAGS_data_path);
@@ -97,8 +104,16 @@ int main(int argc, char ** argv)
if (FLAGS_preprocess_xml)
{
LOG(LINFO, ("Generating intermediate data ...."));
- if (!data::GenerateToFile(FLAGS_intermediate_data_path, FLAGS_use_light_nodes))
- return -1;
+ if(!FLAGS_osm_file_name.empty())
+ {
+ if (!data::GenerateToFile(FLAGS_intermediate_data_path, FLAGS_use_light_nodes, FLAGS_osm_file_name))
+ return -1;
+ }
+ else
+ {
+ if (!data::GenerateToFile(FLAGS_intermediate_data_path, FLAGS_use_light_nodes))
+ return -1;
+ }
}
feature::GenerateInfo genInfo;
@@ -141,8 +156,16 @@ int main(int argc, char ** argv)
if (!FLAGS_address_file_name.empty())
genInfo.m_addressFile = path + FLAGS_address_file_name;
- if (!feature::GenerateFeatures(genInfo, FLAGS_use_light_nodes))
- return -1;
+ if(!FLAGS_osm_file_name.empty())
+ {
+ if (!feature::GenerateFeatures(genInfo, FLAGS_use_light_nodes, FLAGS_osm_file_name))
+ return -1;
+ }
+ else
+ {
+ if (!feature::GenerateFeatures(genInfo, FLAGS_use_light_nodes))
+ return -1;
+ }
// without --spit_by_polygons, we have empty name country as result - assign it
if (genInfo.m_bucketNames.size() == 1 && genInfo.m_bucketNames[0].empty())
diff --git a/generator/xml_element.cpp b/generator/xml_element.cpp
index a2b4fdccc3..6ce91bc19c 100644
--- a/generator/xml_element.cpp
+++ b/generator/xml_element.cpp
@@ -87,9 +87,35 @@ struct StdinReader
}
};
+struct FileReader
+{
+ FILE *m_file;
+
+ FileReader(std::string const &filename)
+ {
+ m_file = fopen(filename.c_str(),"rb");
+ }
+
+ ~FileReader()
+ {
+ fclose(m_file);
+ }
+
+ uint64_t Read(char * buffer, uint64_t bufferSize)
+ {
+ return fread(buffer, sizeof(char), bufferSize, m_file);
+ }
+};
+
void ParseXMLFromStdIn(BaseOSMParser & parser)
{
StdinReader reader;
(void)ParseXMLSequence(reader, parser);
}
+
+void ParseXMLFromFile(BaseOSMParser & parser, std::string const &osm_filename)
+{
+ FileReader reader(osm_filename);
+ (void)ParseXMLSequence(reader, parser);
+}
diff --git a/generator/xml_element.hpp b/generator/xml_element.hpp
index 1ff0e3591a..95c547e78d 100644
--- a/generator/xml_element.hpp
+++ b/generator/xml_element.hpp
@@ -41,3 +41,4 @@ protected:
};
void ParseXMLFromStdIn(BaseOSMParser & parser);
+void ParseXMLFromFile(BaseOSMParser & parser, std::string const &osm_filename);
diff --git a/platform/platform.cpp b/platform/platform.cpp
index 5f713d53a7..0f5dd2ec3d 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -9,7 +9,7 @@
string Platform::ReadPathForFile(string const & file, string searchScope) const
{
if (searchScope.empty())
- searchScope = "wrf";
+ searchScope = "wrfo";
string fullPath;
for (size_t i = 0; i < searchScope.size(); ++i)
@@ -19,6 +19,7 @@ string Platform::ReadPathForFile(string const & file, string searchScope) const
case 'w': fullPath = m_writableDir + file; break;
case 'r': fullPath = m_resourcesDir + file; break;
case 's': fullPath = m_settingsDir + file; break;
+ case 'o': fullPath = m_optionalDir + file; break;
case 'f': fullPath = file; break;
default : CHECK(false, ("Unsupported searchScope:", searchScope)); break;
}
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 5ba411f4f9..7cda2677c8 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -21,6 +21,9 @@ class Platform
protected:
/// Usually read-only directory for application resources
string m_resourcesDir;
+ /// Optional resource search path
+ string m_optionalDir;
+
/// Writable directory to store downloaded map data
/// @note on some systems it can point to external ejectable storage
string m_writableDir;
@@ -62,6 +65,8 @@ public:
static bool IsFileExistsByFullPath(string const & filePath);
+ /// @return void
+ void AddOptionalPath(string const &path) {m_optionalDir = path;}
/// @return always the same writable dir for current user with slash at the end
string WritableDir() const { return m_writableDir; }
/// @return full path to file in user's writable directory