mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 17:50:04 +00:00 
			
		
		
		
	Text product files
This commit is contained in:
		
							parent
							
								
									55d856a745
								
							
						
					
					
						commit
						e5c40b9eb5
					
				
					 7 changed files with 172 additions and 4 deletions
				
			
		
							
								
								
									
										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
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat