Refactoring generic message components to awips namespace

This commit is contained in:
Dan Paulat 2022-01-14 19:34:47 -06:00
parent a76103650e
commit 7a9582a689
14 changed files with 64 additions and 65 deletions

View file

@ -1,124 +0,0 @@
#pragma once
#include <array>
#include <execution>
#include <istream>
#include <map>
#include <string>
#ifdef WIN32
# include <WinSock2.h>
#else
# include <arpa/inet.h>
#endif
namespace scwx
{
namespace wsr88d
{
class MessageImpl;
class Message
{
protected:
explicit Message();
Message(const Message&) = delete;
Message& operator=(const Message&) = delete;
Message(Message&&) noexcept;
Message& operator=(Message&&) noexcept;
virtual bool ValidateMessage(std::istream& is, size_t bytesRead) const;
public:
virtual ~Message();
virtual size_t data_size() const = 0;
virtual bool Parse(std::istream& is) = 0;
static void ReadBoolean(std::istream& is, bool& value)
{
std::string data(4, ' ');
is.read(reinterpret_cast<char*>(&data[0]), 4);
value = (data.at(0) == 'T');
}
static void ReadChar(std::istream& is, char& value)
{
std::string data(4, ' ');
is.read(reinterpret_cast<char*>(&data[0]), 4);
value = data.at(0);
}
static float SwapFloat(float f)
{
return ntohf(*reinterpret_cast<uint32_t*>(&f));
}
template<size_t _Size>
static void SwapArray(std::array<float, _Size>& arr, size_t size = _Size)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.begin() + size,
arr.begin(),
[](float f) { return SwapFloat(f); });
}
template<size_t _Size>
static void SwapArray(std::array<int16_t, _Size>& arr, size_t size = _Size)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.begin() + size,
arr.begin(),
[](int16_t u) { return ntohs(u); });
}
template<size_t _Size>
static void SwapArray(std::array<uint16_t, _Size>& arr, size_t size = _Size)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.begin() + size,
arr.begin(),
[](uint16_t u) { return ntohs(u); });
}
template<size_t _Size>
static void SwapArray(std::array<uint32_t, _Size>& arr, size_t size = _Size)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.begin() + size,
arr.begin(),
[](uint32_t u) { return ntohl(u); });
}
template<typename T>
static void SwapMap(std::map<T, float>& m)
{
std::for_each(std::execution::par_unseq,
m.begin(),
m.end(),
[](auto& p) { p.second = SwapFloat(p.second); });
}
static void SwapVector(std::vector<uint16_t>& v)
{
std::transform(std::execution::par_unseq,
v.begin(),
v.end(),
v.begin(),
[](uint16_t u) { return ntohs(u); });
}
private:
std::unique_ptr<MessageImpl> p;
};
} // namespace wsr88d
} // namespace scwx

View file

@ -1,7 +1,7 @@
#pragma once
#include <scwx/awips/message.hpp>
#include <scwx/wsr88d/rda/level2_message_header.hpp>
#include <scwx/wsr88d/message.hpp>
#ifdef WIN32
# include <WinSock2.h>
@ -18,7 +18,7 @@ namespace rda
class Level2MessageImpl;
class Level2Message : public Message
class Level2Message : public awips::Message
{
protected:
explicit Level2Message();

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <scwx/awips/message.hpp>
#include <cstdint>
#include <memory>
@ -14,7 +14,7 @@ namespace rpg
class GraphicAlphanumericBlockImpl;
class GraphicAlphanumericBlock : public Message
class GraphicAlphanumericBlock : public awips::Message
{
public:
explicit GraphicAlphanumericBlock();

View file

@ -1,7 +1,7 @@
#pragma once
#include <scwx/awips/message.hpp>
#include <scwx/wsr88d/rpg/level3_message_header.hpp>
#include <scwx/wsr88d/message.hpp>
namespace scwx
{
@ -12,7 +12,7 @@ namespace rpg
class Level3MessageImpl;
class Level3Message : public Message
class Level3Message : public awips::Message
{
protected:
explicit Level3Message();

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <scwx/awips/message.hpp>
#include <cstdint>
#include <memory>
@ -12,7 +12,7 @@ namespace wsr88d
namespace rpg
{
class Packet : public Message
class Packet : public awips::Message
{
protected:
explicit Packet();

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <scwx/awips/message.hpp>
#include <cstdint>
#include <memory>
@ -14,7 +14,7 @@ namespace rpg
class ProductDescriptionBlockImpl;
class ProductDescriptionBlock : public Message
class ProductDescriptionBlock : public awips::Message
{
public:
explicit ProductDescriptionBlock();

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <scwx/awips/message.hpp>
#include <scwx/wsr88d/rpg/packet.hpp>
#include <cstdint>
@ -15,7 +15,7 @@ namespace rpg
class ProductSymbologyBlockImpl;
class ProductSymbologyBlock : public Message
class ProductSymbologyBlock : public awips::Message
{
public:
explicit ProductSymbologyBlock();

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <scwx/awips/message.hpp>
#include <cstdint>
#include <memory>
@ -14,7 +14,7 @@ namespace rpg
class TabularAlphanumericBlockImpl;
class TabularAlphanumericBlock : public Message
class TabularAlphanumericBlock : public awips::Message
{
public:
explicit TabularAlphanumericBlock();

View file

@ -1,56 +0,0 @@
#pragma once
#include <memory>
#include <string>
namespace scwx
{
namespace wsr88d
{
namespace rpg
{
class WmoHeaderImpl;
/**
* @brief The WMO Header is defined in WMO Manual No. 386, with additional codes
* defined in WMO Codes Manual 306. The NWS summarizes the relevant
* information.
*
* <https://www.roc.noaa.gov/WSR88D/Level_III/Level3Info.aspx>
* <https://www.weather.gov/tg/head>
* <https://www.weather.gov/tg/headef>
* <https://www.weather.gov/tg/bbb>
* <https://www.weather.gov/tg/awips>
*/
class WmoHeader
{
public:
explicit WmoHeader();
~WmoHeader();
WmoHeader(const WmoHeader&) = delete;
WmoHeader& operator=(const WmoHeader&) = delete;
WmoHeader(WmoHeader&&) noexcept;
WmoHeader& operator=(WmoHeader&&) noexcept;
const std::string& sequence_number() const;
const std::string& data_type() const;
const std::string& geographic_designator() const;
const std::string& bulletin_id() const;
const std::string& icao() const;
const std::string& date_time() const;
const std::string& bbb_indicator() const;
const std::string& product_category() const;
const std::string& product_designator() const;
bool Parse(std::istream& is);
private:
std::unique_ptr<WmoHeaderImpl> p;
};
} // namespace rpg
} // namespace wsr88d
} // namespace scwx