mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 13:30:06 +00:00
Use ranges instead of vectors for listing text products
This commit is contained in:
parent
7a8a0302e0
commit
e82fa93fb0
2 changed files with 34 additions and 17 deletions
|
|
@ -4,10 +4,20 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <boost/outcome/result.hpp>
|
#include <boost/outcome/result.hpp>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# pragma warning(push)
|
||||||
|
# pragma warning(disable : 4702)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <range/v3/view/any_view.hpp>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace scwx::provider
|
namespace scwx::provider
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -30,10 +40,10 @@ public:
|
||||||
ListTextProducts(std::chrono::sys_time<std::chrono::days> date,
|
ListTextProducts(std::chrono::sys_time<std::chrono::days> date,
|
||||||
std::optional<std::string_view> cccc = {},
|
std::optional<std::string_view> cccc = {},
|
||||||
std::optional<std::string_view> pil = {});
|
std::optional<std::string_view> pil = {});
|
||||||
static boost::outcome_v2::result<std::vector<std::string>>
|
static boost::outcome_v2::result<std::vector<std::string>> ListTextProducts(
|
||||||
ListTextProducts(std::vector<std::chrono::sys_time<std::chrono::days>> dates,
|
ranges::any_view<std::chrono::sys_time<std::chrono::days>> dates,
|
||||||
std::vector<std::string_view> ccccs = {},
|
ranges::any_view<std::string_view> ccccs = {},
|
||||||
std::vector<std::string_view> pils = {});
|
ranges::any_view<std::string_view> pils = {});
|
||||||
|
|
||||||
static std::vector<std::shared_ptr<awips::TextProductFile>>
|
static std::vector<std::shared_ptr<awips::TextProductFile>>
|
||||||
LoadTextProducts(const std::vector<std::string>& textProducts);
|
LoadTextProducts(const std::vector<std::string>& textProducts);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@
|
||||||
|
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
#include <cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
|
#include <range/v3/range/conversion.hpp>
|
||||||
#include <range/v3/view/cartesian_product.hpp>
|
#include <range/v3/view/cartesian_product.hpp>
|
||||||
|
#include <range/v3/view/single.hpp>
|
||||||
|
|
||||||
#if (__cpp_lib_chrono < 201907L)
|
#if (__cpp_lib_chrono < 201907L)
|
||||||
# include <date/date.h>
|
# include <date/date.h>
|
||||||
|
|
@ -50,17 +52,18 @@ IemApiProvider::ListTextProducts(std::chrono::sys_time<std::chrono::days> date,
|
||||||
std::string_view pil =
|
std::string_view pil =
|
||||||
optionalPil.has_value() ? optionalPil.value() : std::string_view {};
|
optionalPil.has_value() ? optionalPil.value() : std::string_view {};
|
||||||
|
|
||||||
return ListTextProducts(
|
const auto dateArray = std::array {date};
|
||||||
std::vector<std::chrono::sys_time<std::chrono::days>> {date},
|
const auto ccccArray = std::array {cccc};
|
||||||
{cccc},
|
const auto pilArray = std::array {pil};
|
||||||
{pil});
|
|
||||||
|
return ListTextProducts(dateArray, ccccArray, pilArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::outcome_v2::result<std::vector<std::string>>
|
boost::outcome_v2::result<std::vector<std::string>>
|
||||||
IemApiProvider::ListTextProducts(
|
IemApiProvider::ListTextProducts(
|
||||||
std::vector<std::chrono::sys_time<std::chrono::days>> dates,
|
ranges::any_view<std::chrono::sys_time<std::chrono::days>> dates,
|
||||||
std::vector<std::string_view> ccccs,
|
ranges::any_view<std::string_view> ccccs,
|
||||||
std::vector<std::string_view> pils)
|
ranges::any_view<std::string_view> pils)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
|
@ -75,20 +78,24 @@ IemApiProvider::ListTextProducts(
|
||||||
# define kDateFormat "%Y-%m-%d"
|
# define kDateFormat "%Y-%m-%d"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ccccs.empty())
|
if (ccccs.begin() == ccccs.end())
|
||||||
{
|
{
|
||||||
ccccs.push_back({});
|
ccccs = ranges::views::single(std::string_view {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pils.empty())
|
if (pils.begin() == pils.end())
|
||||||
{
|
{
|
||||||
pils.push_back({});
|
pils = ranges::views::single(std::string_view {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto dv = ranges::to<std::vector>(dates);
|
||||||
|
const auto cv = ranges::to<std::vector>(ccccs);
|
||||||
|
const auto pv = ranges::to<std::vector>(pils);
|
||||||
|
|
||||||
std::vector<cpr::AsyncResponse> responses {};
|
std::vector<cpr::AsyncResponse> responses {};
|
||||||
|
|
||||||
for (const auto& [date, cccc, pil] :
|
for (const auto& [date, cccc, pil] :
|
||||||
ranges::views::cartesian_product(dates, ccccs, pils))
|
ranges::views::cartesian_product(dv, cv, pv))
|
||||||
{
|
{
|
||||||
auto parameters =
|
auto parameters =
|
||||||
cpr::Parameters {{"date", df::format(kDateFormat, date)}};
|
cpr::Parameters {{"date", df::format(kDateFormat, date)}};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue