mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:30:06 +00:00
Adding event begin and event end functions for segments
This commit is contained in:
parent
0fa3f2162b
commit
803dfdd455
2 changed files with 30 additions and 7 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
#include <scwx/awips/ugc.hpp>
|
#include <scwx/awips/ugc.hpp>
|
||||||
#include <scwx/awips/wmo_header.hpp>
|
#include <scwx/awips/wmo_header.hpp>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -57,6 +58,7 @@ struct SegmentHeader
|
||||||
|
|
||||||
struct Segment
|
struct Segment
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<WmoHeader> wmoHeader_ {};
|
||||||
std::optional<SegmentHeader> header_ {};
|
std::optional<SegmentHeader> header_ {};
|
||||||
std::vector<std::string> productContent_ {};
|
std::vector<std::string> productContent_ {};
|
||||||
std::optional<CodedLocation> codedLocation_ {};
|
std::optional<CodedLocation> codedLocation_ {};
|
||||||
|
|
@ -73,6 +75,9 @@ struct Segment
|
||||||
|
|
||||||
Segment(Segment&&) noexcept = default;
|
Segment(Segment&&) noexcept = default;
|
||||||
Segment& operator=(Segment&&) noexcept = default;
|
Segment& operator=(Segment&&) noexcept = default;
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point event_begin() const;
|
||||||
|
std::chrono::system_clock::time_point event_end() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextProductMessageImpl;
|
class TextProductMessageImpl;
|
||||||
|
|
|
||||||
|
|
@ -104,16 +104,14 @@ std::shared_ptr<const Segment> TextProductMessage::segment(size_t s) const
|
||||||
return p->segments_[s];
|
return p->segments_[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::system_clock::time_point
|
std::chrono::system_clock::time_point Segment::event_begin() const
|
||||||
TextProductMessage::segment_event_begin(std::size_t s) const
|
|
||||||
{
|
{
|
||||||
std::chrono::system_clock::time_point eventBegin {};
|
std::chrono::system_clock::time_point eventBegin {};
|
||||||
|
|
||||||
auto& header = segment(s)->header_;
|
if (header_.has_value() && !header_->vtecString_.empty())
|
||||||
if (header.has_value() && !header->vtecString_.empty())
|
|
||||||
{
|
{
|
||||||
// Determine event begin from P-VTEC string
|
// Determine event begin from P-VTEC string
|
||||||
eventBegin = header->vtecString_[0].pVtec_.event_begin();
|
eventBegin = header_->vtecString_[0].pVtec_.event_begin();
|
||||||
|
|
||||||
// If event begin is 000000T0000Z
|
// If event begin is 000000T0000Z
|
||||||
if (eventBegin == std::chrono::system_clock::time_point {})
|
if (eventBegin == std::chrono::system_clock::time_point {})
|
||||||
|
|
@ -122,13 +120,13 @@ TextProductMessage::segment_event_begin(std::size_t s) const
|
||||||
|
|
||||||
// Determine event end from P-VTEC string
|
// Determine event end from P-VTEC string
|
||||||
system_clock::time_point eventEnd =
|
system_clock::time_point eventEnd =
|
||||||
header->vtecString_[0].pVtec_.event_end();
|
header_->vtecString_[0].pVtec_.event_end();
|
||||||
|
|
||||||
auto endDays = floor<days>(eventEnd);
|
auto endDays = floor<days>(eventEnd);
|
||||||
year_month_day endDate {endDays};
|
year_month_day endDate {endDays};
|
||||||
|
|
||||||
// Determine WMO date/time
|
// Determine WMO date/time
|
||||||
std::string wmoDateTime = wmo_header()->date_time();
|
std::string wmoDateTime = wmoHeader_->date_time();
|
||||||
|
|
||||||
bool wmoDateTimeValid = false;
|
bool wmoDateTimeValid = false;
|
||||||
unsigned int dayOfMonth = 0;
|
unsigned int dayOfMonth = 0;
|
||||||
|
|
@ -189,6 +187,25 @@ TextProductMessage::segment_event_begin(std::size_t s) const
|
||||||
return eventBegin;
|
return eventBegin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point Segment::event_end() const
|
||||||
|
{
|
||||||
|
std::chrono::system_clock::time_point eventEnd {};
|
||||||
|
|
||||||
|
if (header_.has_value() && !header_->vtecString_.empty())
|
||||||
|
{
|
||||||
|
// Determine event begin from P-VTEC string
|
||||||
|
eventEnd = header_->vtecString_[0].pVtec_.event_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point
|
||||||
|
TextProductMessage::segment_event_begin(std::size_t s) const
|
||||||
|
{
|
||||||
|
return segment(s)->event_begin();
|
||||||
|
}
|
||||||
|
|
||||||
size_t TextProductMessage::data_size() const
|
size_t TextProductMessage::data_size() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -211,6 +228,7 @@ bool TextProductMessage::Parse(std::istream& is)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Segment> segment = std::make_shared<Segment>();
|
std::shared_ptr<Segment> segment = std::make_shared<Segment>();
|
||||||
|
segment->wmoHeader_ = p->wmoHeader_;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue