mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -55,11 +55,12 @@ namespace routes_builder
|
||||
// RoutesBuilder::Params ---------------------------------------------------------------------------
|
||||
|
||||
RoutesBuilder::Params::Params(VehicleType type, ms::LatLon const & start, ms::LatLon const & finish)
|
||||
: Params(type, {mercator::FromLatLon(start), mercator::FromLatLon(finish)})
|
||||
: Params(type, {mercator::FromLatLon(start), mercator::FromLatLon(finish)})
|
||||
{}
|
||||
|
||||
RoutesBuilder::Params::Params(VehicleType type, std::vector<m2::PointD> && checkpoints)
|
||||
: m_type(type), m_checkpoints(std::move(checkpoints))
|
||||
: m_type(type)
|
||||
, m_checkpoints(std::move(checkpoints))
|
||||
{}
|
||||
|
||||
// static
|
||||
@@ -139,10 +140,8 @@ RoutesBuilder::Result RoutesBuilder::ProcessTask(Params const & params)
|
||||
std::future<RoutesBuilder::Result> RoutesBuilder::ProcessTaskAsync(Params const & params)
|
||||
{
|
||||
// Should be copyable to workaround MSVC bug (https://developercommunity.visualstudio.com/t/108672)
|
||||
auto task = [processor = std::make_shared<Processor>(m_numMwmIds, m_dataSourcesStorage, m_cpg, m_cig)](Params const & params) -> Result
|
||||
{
|
||||
return (*processor)(params);
|
||||
};
|
||||
auto task = [processor = std::make_shared<Processor>(m_numMwmIds, m_dataSourcesStorage, m_cpg, m_cig)](
|
||||
Params const & params) -> Result { return (*processor)(params); };
|
||||
return m_threadPool.Submit(std::move(task), params);
|
||||
}
|
||||
|
||||
@@ -229,19 +228,16 @@ std::vector<ms::LatLon> RoutesBuilder::Route::GetWaypoints() const
|
||||
|
||||
// RoutesBuilder::Processor ------------------------------------------------------------------------
|
||||
|
||||
RoutesBuilder::Processor::Processor(std::shared_ptr<NumMwmIds> numMwmIds,
|
||||
DataSourceStorage & dataSourceStorage,
|
||||
RoutesBuilder::Processor::Processor(std::shared_ptr<NumMwmIds> numMwmIds, DataSourceStorage & dataSourceStorage,
|
||||
std::weak_ptr<storage::CountryParentGetter> cpg,
|
||||
std::weak_ptr<storage::CountryInfoGetter> cig)
|
||||
: m_numMwmIds(std::move(numMwmIds))
|
||||
, m_dataSourceStorage(dataSourceStorage)
|
||||
, m_cpg(std::move(cpg))
|
||||
, m_cig(std::move(cig))
|
||||
{
|
||||
}
|
||||
: m_numMwmIds(std::move(numMwmIds))
|
||||
, m_dataSourceStorage(dataSourceStorage)
|
||||
, m_cpg(std::move(cpg))
|
||||
, m_cig(std::move(cig))
|
||||
{}
|
||||
|
||||
RoutesBuilder::Processor::Processor(Processor && rhs) noexcept
|
||||
: m_dataSourceStorage(rhs.m_dataSourceStorage)
|
||||
RoutesBuilder::Processor::Processor(Processor && rhs) noexcept : m_dataSourceStorage(rhs.m_dataSourceStorage)
|
||||
{
|
||||
m_start = rhs.m_start;
|
||||
m_finish = rhs.m_finish;
|
||||
@@ -261,12 +257,14 @@ void RoutesBuilder::Processor::InitRouter(VehicleType type)
|
||||
return;
|
||||
|
||||
auto const & cig = m_cig;
|
||||
auto const countryFileGetter = [cig](m2::PointD const & pt) {
|
||||
auto const countryFileGetter = [cig](m2::PointD const & pt)
|
||||
{
|
||||
auto const cigSharedPtr = cig.lock();
|
||||
return cigSharedPtr->GetRegionCountryId(pt);
|
||||
};
|
||||
|
||||
auto const getMwmRectByName = [cig](std::string const & countryId) {
|
||||
auto const getMwmRectByName = [cig](std::string const & countryId)
|
||||
{
|
||||
auto const cigSharedPtr = cig.lock();
|
||||
return cigSharedPtr->GetLimitRectForLeaf(countryId);
|
||||
};
|
||||
@@ -275,24 +273,15 @@ void RoutesBuilder::Processor::InitRouter(VehicleType type)
|
||||
if (!m_dataSource)
|
||||
m_dataSource = m_dataSourceStorage.GetDataSource();
|
||||
|
||||
m_router = std::make_unique<IndexRouter>(type,
|
||||
loadAltitudes,
|
||||
*m_cpg.lock(),
|
||||
countryFileGetter,
|
||||
getMwmRectByName,
|
||||
m_numMwmIds,
|
||||
MakeNumMwmTree(*m_numMwmIds, *m_cig.lock()),
|
||||
*m_trafficCache,
|
||||
m_router = std::make_unique<IndexRouter>(type, loadAltitudes, *m_cpg.lock(), countryFileGetter, getMwmRectByName,
|
||||
m_numMwmIds, MakeNumMwmTree(*m_numMwmIds, *m_cig.lock()), *m_trafficCache,
|
||||
*m_dataSource);
|
||||
}
|
||||
|
||||
RoutesBuilder::Result
|
||||
RoutesBuilder::Processor::operator()(Params const & params)
|
||||
RoutesBuilder::Result RoutesBuilder::Processor::operator()(Params const & params)
|
||||
{
|
||||
InitRouter(params.m_type);
|
||||
SCOPE_GUARD(returnDataSource, [&]() {
|
||||
m_dataSourceStorage.PushDataSource(std::move(m_dataSource));
|
||||
});
|
||||
SCOPE_GUARD(returnDataSource, [&]() { m_dataSourceStorage.PushDataSource(std::move(m_dataSource)); });
|
||||
|
||||
LOG(LINFO, ("Start building route, checkpoints:", params.m_checkpoints));
|
||||
|
||||
@@ -306,8 +295,8 @@ RoutesBuilder::Processor::operator()(Params const & params)
|
||||
{
|
||||
m_delegate->SetTimeout(params.m_timeoutSeconds);
|
||||
base::Timer timer;
|
||||
resultCode = m_router->CalculateRoute(params.m_checkpoints, m2::PointD::Zero(),
|
||||
false /* adjustToPrevRoute */, *m_delegate, route);
|
||||
resultCode = m_router->CalculateRoute(params.m_checkpoints, m2::PointD::Zero(), false /* adjustToPrevRoute */,
|
||||
*m_delegate, route);
|
||||
|
||||
if (resultCode != RouterResultCode::NoError)
|
||||
break;
|
||||
|
||||
@@ -99,14 +99,11 @@ public:
|
||||
std::future<Result> ProcessTaskAsync(Params const & params);
|
||||
|
||||
private:
|
||||
|
||||
class Processor
|
||||
{
|
||||
public:
|
||||
Processor(std::shared_ptr<NumMwmIds> numMwmIds,
|
||||
DataSourceStorage & dataSourceStorage,
|
||||
std::weak_ptr<storage::CountryParentGetter> cpg,
|
||||
std::weak_ptr<storage::CountryInfoGetter> cig);
|
||||
Processor(std::shared_ptr<NumMwmIds> numMwmIds, DataSourceStorage & dataSourceStorage,
|
||||
std::weak_ptr<storage::CountryParentGetter> cpg, std::weak_ptr<storage::CountryInfoGetter> cig);
|
||||
|
||||
Processor(Processor && rhs) noexcept;
|
||||
|
||||
@@ -131,8 +128,7 @@ private:
|
||||
|
||||
base::ComputationalThreadPool m_threadPool;
|
||||
|
||||
std::shared_ptr<storage::CountryParentGetter> m_cpg =
|
||||
std::make_shared<storage::CountryParentGetter>();
|
||||
std::shared_ptr<storage::CountryParentGetter> m_cpg = std::make_shared<storage::CountryParentGetter>();
|
||||
|
||||
std::shared_ptr<storage::CountryInfoGetter> m_cig =
|
||||
storage::CountryInfoReader::CreateCountryInfoGetter(GetPlatform());
|
||||
|
||||
@@ -14,17 +14,18 @@
|
||||
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
DEFINE_uint64(threads, 0,
|
||||
"The number of threads. std::thread::hardware_concurrency() is used by default.");
|
||||
DEFINE_uint64(threads, 0, "The number of threads. std::thread::hardware_concurrency() is used by default.");
|
||||
|
||||
DEFINE_string(routes_file, "", "Path to file with routes in format: \n\t"
|
||||
"first_start_lat first_start_lon first_finish_lat first_finish_lon\n\t"
|
||||
"second_start_lat second_start_lon second_finish_lat second_finish_lon\n\t"
|
||||
"...");
|
||||
DEFINE_string(routes_file, "",
|
||||
"Path to file with routes in format: \n\t"
|
||||
"first_start_lat first_start_lon first_finish_lat first_finish_lon\n\t"
|
||||
"second_start_lat second_start_lon second_finish_lat second_finish_lon\n\t"
|
||||
"...");
|
||||
|
||||
DEFINE_string(dump_path, "", "Path where routes will be dumped after building."
|
||||
"Useful for intermediate results, because routes building "
|
||||
"is a long process.");
|
||||
DEFINE_string(dump_path, "",
|
||||
"Path where routes will be dumped after building."
|
||||
"Useful for intermediate results, because routes building "
|
||||
"is a long process.");
|
||||
|
||||
DEFINE_string(data_path, "", "Data path.");
|
||||
DEFINE_string(resources_path, "", "Resources path.");
|
||||
@@ -34,8 +35,9 @@ DEFINE_string(api_token, "", "Token for chosen api.");
|
||||
|
||||
DEFINE_uint64(start_from, 0, "The line number from which the tool should start reading.");
|
||||
|
||||
DEFINE_int32(timeout, 10 * 60, "Timeout in seconds for each route building. "
|
||||
"0 means without timeout (default: 10 minutes).");
|
||||
DEFINE_int32(timeout, 10 * 60,
|
||||
"Timeout in seconds for each route building. "
|
||||
"0 means without timeout (default: 10 minutes).");
|
||||
|
||||
DEFINE_bool(verbose, false, "Verbose logging (default: false)");
|
||||
|
||||
@@ -71,9 +73,7 @@ int Main(int argc, char ** argv)
|
||||
|
||||
CHECK_GREATER_OR_EQUAL(FLAGS_timeout, 0, ("Timeout should be greater than zero."));
|
||||
|
||||
CHECK(!FLAGS_routes_file.empty(),
|
||||
("\n\n\t--routes_file is required.",
|
||||
"\n\nType --help for usage."));
|
||||
CHECK(!FLAGS_routes_file.empty(), ("\n\n\t--routes_file is required.", "\n\nType --help for usage."));
|
||||
|
||||
if (!FLAGS_data_path.empty())
|
||||
GetPlatform().SetWritableDirForTests(FLAGS_data_path);
|
||||
@@ -82,10 +82,8 @@ int Main(int argc, char ** argv)
|
||||
GetPlatform().SetResourceDir(FLAGS_resources_path);
|
||||
|
||||
CHECK(IsLocalBuild() || IsApiBuild(),
|
||||
("\n\n\t--routes_file empty is:", FLAGS_routes_file.empty(),
|
||||
"\n\t--api_name empty is:", FLAGS_api_name.empty(),
|
||||
"\n\t--api_token empty is:", FLAGS_api_token.empty(),
|
||||
"\n\nType --help for usage."));
|
||||
("\n\n\t--routes_file empty is:", FLAGS_routes_file.empty(), "\n\t--api_name empty is:", FLAGS_api_name.empty(),
|
||||
"\n\t--api_token empty is:", FLAGS_api_token.empty(), "\n\nType --help for usage."));
|
||||
|
||||
CHECK(!FLAGS_dump_path.empty(),
|
||||
("\n\n\t--dump_path is empty. It makes no sense to run this tool. No result will be saved.",
|
||||
@@ -96,19 +94,16 @@ int Main(int argc, char ** argv)
|
||||
if (Platform::IsFileExistsByFullPath(FLAGS_dump_path))
|
||||
CheckDirExistence(FLAGS_dump_path);
|
||||
else
|
||||
CHECK_EQUAL(Platform::MkDir(FLAGS_dump_path), Platform::EError::ERR_OK,());
|
||||
CHECK_EQUAL(Platform::MkDir(FLAGS_dump_path), Platform::EError::ERR_OK, ());
|
||||
|
||||
if (IsLocalBuild())
|
||||
{
|
||||
auto const launchesNumber = static_cast<uint32_t>(FLAGS_launches_number);
|
||||
if (launchesNumber > 1)
|
||||
{
|
||||
LOG(LINFO,
|
||||
("Benchmark mode is activated. Each route will be built", launchesNumber, "times."));
|
||||
}
|
||||
LOG(LINFO, ("Benchmark mode is activated. Each route will be built", launchesNumber, "times."));
|
||||
|
||||
BuildRoutes(FLAGS_routes_file, FLAGS_dump_path, FLAGS_start_from, FLAGS_threads, FLAGS_timeout,
|
||||
FLAGS_vehicle_type, FLAGS_verbose, launchesNumber);
|
||||
BuildRoutes(FLAGS_routes_file, FLAGS_dump_path, FLAGS_start_from, FLAGS_threads, FLAGS_timeout, FLAGS_vehicle_type,
|
||||
FLAGS_verbose, launchesNumber);
|
||||
}
|
||||
|
||||
if (IsApiBuild())
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
namespace routing
|
||||
{
|
||||
namespace routes_builder
|
||||
@@ -63,14 +62,9 @@ routing::VehicleType ConvertVehicleTypeFromString(std::string const & str)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void BuildRoutes(std::string const & routesPath,
|
||||
std::string const & dumpPath,
|
||||
uint64_t startFrom,
|
||||
uint64_t threadsNumber,
|
||||
uint32_t timeoutPerRouteSeconds,
|
||||
std::string const & vehicleTypeStr,
|
||||
bool verbose,
|
||||
uint32_t launchesNumber)
|
||||
void BuildRoutes(std::string const & routesPath, std::string const & dumpPath, uint64_t startFrom,
|
||||
uint64_t threadsNumber, uint32_t timeoutPerRouteSeconds, std::string const & vehicleTypeStr,
|
||||
bool verbose, uint32_t launchesNumber)
|
||||
{
|
||||
CHECK(Platform::IsFileExistsByFullPath(routesPath), ("Can not find file:", routesPath));
|
||||
CHECK(!dumpPath.empty(), ("Empty dumpPath."));
|
||||
@@ -132,8 +126,7 @@ void BuildRoutes(std::string const & routesPath,
|
||||
|
||||
RoutesBuilder::Result::Dump(result, fullPath);
|
||||
|
||||
double const curPercent =
|
||||
static_cast<double>(shiftIndex + 1) / (tasks.size() + startFrom) * 100.0;
|
||||
double const curPercent = static_cast<double>(shiftIndex + 1) / (tasks.size() + startFrom) * 100.0;
|
||||
|
||||
if (curPercent - lastPercent > 1.0 || shiftIndex + 1 == tasks.size())
|
||||
{
|
||||
@@ -165,10 +158,8 @@ std::optional<std::tuple<ms::LatLon, ms::LatLon, int32_t>> ParseApiLine(std::ifs
|
||||
return {{start, finish, utcOffset}};
|
||||
}
|
||||
|
||||
void BuildRoutesWithApi(std::unique_ptr<api::RoutingApi> routingApi,
|
||||
std::string const & routesPath,
|
||||
std::string const & dumpPath,
|
||||
int64_t startFrom)
|
||||
void BuildRoutesWithApi(std::unique_ptr<api::RoutingApi> routingApi, std::string const & routesPath,
|
||||
std::string const & dumpPath, int64_t startFrom)
|
||||
{
|
||||
std::ifstream input(routesPath);
|
||||
CHECK(input.good(), ("Error during opening:", routesPath));
|
||||
@@ -188,7 +179,8 @@ void BuildRoutesWithApi(std::unique_ptr<api::RoutingApi> routingApi,
|
||||
return ms;
|
||||
};
|
||||
|
||||
auto const drop = [&]() {
|
||||
auto const drop = [&]()
|
||||
{
|
||||
rps = 0;
|
||||
timer.Reset();
|
||||
};
|
||||
@@ -271,8 +263,7 @@ void BuildRoutesWithApi(std::unique_ptr<api::RoutingApi> routingApi,
|
||||
dump();
|
||||
}
|
||||
|
||||
std::unique_ptr<routing_quality::api::RoutingApi> CreateRoutingApi(std::string const & name,
|
||||
std::string const & token)
|
||||
std::unique_ptr<routing_quality::api::RoutingApi> CreateRoutingApi(std::string const & name, std::string const & token)
|
||||
{
|
||||
if (name == "mapbox")
|
||||
return std::make_unique<routing_quality::api::mapbox::MapboxApi>(token);
|
||||
@@ -283,4 +274,4 @@ std::unique_ptr<routing_quality::api::RoutingApi> CreateRoutingApi(std::string c
|
||||
UNREACHABLE();
|
||||
}
|
||||
} // namespace routes_builder
|
||||
} // routing
|
||||
} // namespace routing
|
||||
|
||||
@@ -13,21 +13,13 @@ namespace routing
|
||||
{
|
||||
namespace routes_builder
|
||||
{
|
||||
void BuildRoutes(std::string const & routesPath,
|
||||
std::string const & dumpPath,
|
||||
uint64_t startFrom,
|
||||
uint64_t threadsNumber,
|
||||
uint32_t timeoutPerRouteSeconds,
|
||||
std::string const & vehicleType,
|
||||
bool verbose,
|
||||
void BuildRoutes(std::string const & routesPath, std::string const & dumpPath, uint64_t startFrom,
|
||||
uint64_t threadsNumber, uint32_t timeoutPerRouteSeconds, std::string const & vehicleType, bool verbose,
|
||||
uint32_t launchesNumber);
|
||||
|
||||
void BuildRoutesWithApi(std::unique_ptr<routing_quality::api::RoutingApi> routingApi,
|
||||
std::string const & routesPath,
|
||||
std::string const & dumpPath,
|
||||
int64_t startFrom);
|
||||
void BuildRoutesWithApi(std::unique_ptr<routing_quality::api::RoutingApi> routingApi, std::string const & routesPath,
|
||||
std::string const & dumpPath, int64_t startFrom);
|
||||
|
||||
std::unique_ptr<routing_quality::api::RoutingApi> CreateRoutingApi(std::string const & name,
|
||||
std::string const & token);
|
||||
std::unique_ptr<routing_quality::api::RoutingApi> CreateRoutingApi(std::string const & name, std::string const & token);
|
||||
} // namespace routes_builder
|
||||
} // routing
|
||||
} // namespace routing
|
||||
|
||||
Reference in New Issue
Block a user