mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:50:06 +00:00 
			
		
		
		
	Use strings instead of character arrays where warranted
This commit is contained in:
		
							parent
							
								
									798b348d8b
								
							
						
					
					
						commit
						09649c0fe7
					
				
					 4 changed files with 36 additions and 14 deletions
				
			
		|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #include <cstdint> | ||||
| #include <memory> | ||||
| #include <string> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -26,9 +27,9 @@ public: | |||
|    StormIdSymbolPacket(StormIdSymbolPacket&&) noexcept; | ||||
|    StormIdSymbolPacket& operator=(StormIdSymbolPacket&&) noexcept; | ||||
| 
 | ||||
|    int16_t                    i_position(size_t i) const; | ||||
|    int16_t                    j_position(size_t i) const; | ||||
|    const std::array<char, 2>& character(size_t i) const; | ||||
|    int16_t     i_position(size_t i) const; | ||||
|    int16_t     j_position(size_t i) const; | ||||
|    std::string storm_id(size_t i) const; | ||||
| 
 | ||||
|    size_t RecordCount() const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #include <cstdint> | ||||
| #include <memory> | ||||
| #include <string> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -30,6 +31,9 @@ public: | |||
|    uint16_t                packet_code() const; | ||||
|    uint16_t                length_of_block() const; | ||||
|    std::optional<uint16_t> value_of_text() const; | ||||
|    int16_t                 start_i() const; | ||||
|    int16_t                 start_j() const; | ||||
|    std::string             text() const; | ||||
| 
 | ||||
|    size_t data_size() const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,11 +17,11 @@ static const std::string logPrefix_ = | |||
| 
 | ||||
| struct StormIdSymbol | ||||
| { | ||||
|    int16_t             iPosition_; | ||||
|    int16_t             jPosition_; | ||||
|    std::array<char, 2> character_; | ||||
|    int16_t     iPosition_; | ||||
|    int16_t     jPosition_; | ||||
|    std::string stormId_; | ||||
| 
 | ||||
|    StormIdSymbol() : iPosition_ {0}, jPosition_ {0}, character_ {0} {} | ||||
|    StormIdSymbol() : iPosition_ {0}, jPosition_ {0}, stormId_ {} {} | ||||
| }; | ||||
| 
 | ||||
| class StormIdSymbolPacketImpl | ||||
|  | @ -55,9 +55,9 @@ int16_t StormIdSymbolPacket::j_position(size_t i) const | |||
|    return p->symbol_[i].jPosition_; | ||||
| } | ||||
| 
 | ||||
| const std::array<char, 2>& StormIdSymbolPacket::character(size_t i) const | ||||
| std::string StormIdSymbolPacket::storm_id(size_t i) const | ||||
| { | ||||
|    return p->symbol_[i].character_; | ||||
|    return p->symbol_[i].stormId_; | ||||
| } | ||||
| 
 | ||||
| size_t StormIdSymbolPacket::RecordCount() const | ||||
|  | @ -85,9 +85,11 @@ bool StormIdSymbolPacket::ParseData(std::istream& is) | |||
|       { | ||||
|          StormIdSymbol& s = p->symbol_[i]; | ||||
| 
 | ||||
|          s.stormId_.resize(2); | ||||
| 
 | ||||
|          is.read(reinterpret_cast<char*>(&s.iPosition_), 2); | ||||
|          is.read(reinterpret_cast<char*>(&s.jPosition_), 2); | ||||
|          is.read(reinterpret_cast<char*>(s.character_.data()), 2); | ||||
|          is.read(s.stormId_.data(), 2); | ||||
| 
 | ||||
|          s.iPosition_ = ntohs(s.iPosition_); | ||||
|          s.jPosition_ = ntohs(s.jPosition_); | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ public: | |||
|        valueOfText_ {0}, | ||||
|        startI_ {0}, | ||||
|        startJ_ {0}, | ||||
|        characters_ {} | ||||
|        text_ {} | ||||
|    { | ||||
|    } | ||||
|    ~TextAndSpecialSymbolPacketImpl() = default; | ||||
|  | @ -35,7 +35,7 @@ public: | |||
|    int16_t  startI_; | ||||
|    int16_t  startJ_; | ||||
| 
 | ||||
|    std::vector<char> characters_; | ||||
|    std::string text_; | ||||
| }; | ||||
| 
 | ||||
| TextAndSpecialSymbolPacket::TextAndSpecialSymbolPacket() : | ||||
|  | @ -71,6 +71,21 @@ std::optional<uint16_t> TextAndSpecialSymbolPacket::value_of_text() const | |||
|    return value; | ||||
| } | ||||
| 
 | ||||
| int16_t TextAndSpecialSymbolPacket::start_i() const | ||||
| { | ||||
|    return p->startI_; | ||||
| } | ||||
| 
 | ||||
| int16_t TextAndSpecialSymbolPacket::start_j() const | ||||
| { | ||||
|    return p->startJ_; | ||||
| } | ||||
| 
 | ||||
| std::string TextAndSpecialSymbolPacket::text() const | ||||
| { | ||||
|    return p->text_; | ||||
| } | ||||
| 
 | ||||
| size_t TextAndSpecialSymbolPacket::data_size() const | ||||
| { | ||||
|    return p->lengthOfBlock_ + 4u; | ||||
|  | @ -133,8 +148,8 @@ bool TextAndSpecialSymbolPacket::Parse(std::istream& is) | |||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       p->characters_.resize(textLength); | ||||
|       is.read(reinterpret_cast<char*>(p->characters_.data()), textLength); | ||||
|       p->text_.resize(textLength); | ||||
|       is.read(p->text_.data(), textLength); | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd = is.tellg(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat