mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:00:08 +00:00
Text product files
This commit is contained in:
parent
55d856a745
commit
e5c40b9eb5
7 changed files with 172 additions and 4 deletions
38
wxdata/include/scwx/awips/text_product_file.hpp
Normal file
38
wxdata/include/scwx/awips/text_product_file.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/awips/text_product_message.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace awips
|
||||
{
|
||||
|
||||
class TextProductFileImpl;
|
||||
|
||||
class TextProductFile
|
||||
{
|
||||
public:
|
||||
explicit TextProductFile();
|
||||
~TextProductFile();
|
||||
|
||||
TextProductFile(const TextProductFile&) = delete;
|
||||
TextProductFile& operator=(const TextProductFile&) = delete;
|
||||
|
||||
TextProductFile(TextProductFile&&) noexcept;
|
||||
TextProductFile& operator=(TextProductFile&&) noexcept;
|
||||
|
||||
size_t message_count() const;
|
||||
std::shared_ptr<TextProductMessage> message(size_t i) const;
|
||||
|
||||
bool LoadFile(const std::string& filename);
|
||||
bool LoadData(std::istream& is);
|
||||
|
||||
private:
|
||||
std::unique_ptr<TextProductFileImpl> p;
|
||||
};
|
||||
|
||||
} // namespace awips
|
||||
} // namespace scwx
|
||||
86
wxdata/source/scwx/awips/text_product_file.cpp
Normal file
86
wxdata/source/scwx/awips/text_product_file.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include <scwx/awips/text_product_file.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace awips
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "[scwx::awips::text_product_file] ";
|
||||
|
||||
class TextProductFileImpl
|
||||
{
|
||||
public:
|
||||
explicit TextProductFileImpl() : messages_ {} {};
|
||||
~TextProductFileImpl() = default;
|
||||
|
||||
std::vector<std::shared_ptr<TextProductMessage>> messages_;
|
||||
};
|
||||
|
||||
TextProductFile::TextProductFile() : p(std::make_unique<TextProductFileImpl>())
|
||||
{
|
||||
}
|
||||
TextProductFile::~TextProductFile() = default;
|
||||
|
||||
TextProductFile::TextProductFile(TextProductFile&&) noexcept = default;
|
||||
TextProductFile&
|
||||
TextProductFile::operator=(TextProductFile&&) noexcept = default;
|
||||
|
||||
size_t TextProductFile::message_count() const
|
||||
{
|
||||
return p->messages_.size();
|
||||
}
|
||||
|
||||
std::shared_ptr<TextProductMessage> TextProductFile::message(size_t i) const
|
||||
{
|
||||
return p->messages_[i];
|
||||
}
|
||||
|
||||
bool TextProductFile::LoadFile(const std::string& filename)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")";
|
||||
bool fileValid = true;
|
||||
|
||||
std::ifstream f(filename, std::ios_base::in | std::ios_base::binary);
|
||||
if (!f.good())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Could not open file for reading: " << filename;
|
||||
fileValid = false;
|
||||
}
|
||||
|
||||
if (fileValid)
|
||||
{
|
||||
fileValid = LoadData(f);
|
||||
}
|
||||
|
||||
return fileValid;
|
||||
}
|
||||
|
||||
bool TextProductFile::LoadData(std::istream& is)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data";
|
||||
|
||||
while (!is.eof())
|
||||
{
|
||||
std::shared_ptr<TextProductMessage> message =
|
||||
TextProductMessage::Create(is);
|
||||
|
||||
if (message != nullptr)
|
||||
{
|
||||
p->messages_.push_back(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return !p->messages_.empty();
|
||||
}
|
||||
|
||||
} // namespace awips
|
||||
} // namespace scwx
|
||||
|
|
@ -3,9 +3,11 @@ project(scwx-data)
|
|||
find_package(Boost)
|
||||
|
||||
set(HDR_AWIPS include/scwx/awips/message.hpp
|
||||
include/scwx/awips/text_product_file.hpp
|
||||
include/scwx/awips/text_product_message.hpp
|
||||
include/scwx/awips/wmo_header.hpp)
|
||||
set(SRC_AWIPS source/scwx/awips/message.cpp
|
||||
source/scwx/awips/text_product_file.cpp
|
||||
source/scwx/awips/text_product_message.cpp
|
||||
source/scwx/awips/wmo_header.cpp)
|
||||
set(HDR_COMMON include/scwx/common/characters.hpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue