mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 17:00:05 +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 <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +29,7 @@ public:
|
||||||
|
|
||||||
int16_t i_position(size_t i) const;
|
int16_t i_position(size_t i) const;
|
||||||
int16_t j_position(size_t i) const;
|
int16_t j_position(size_t i) const;
|
||||||
const std::array<char, 2>& character(size_t i) const;
|
std::string storm_id(size_t i) const;
|
||||||
|
|
||||||
size_t RecordCount() const override;
|
size_t RecordCount() const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +31,9 @@ public:
|
||||||
uint16_t packet_code() const;
|
uint16_t packet_code() const;
|
||||||
uint16_t length_of_block() const;
|
uint16_t length_of_block() const;
|
||||||
std::optional<uint16_t> value_of_text() 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;
|
size_t data_size() const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ struct StormIdSymbol
|
||||||
{
|
{
|
||||||
int16_t iPosition_;
|
int16_t iPosition_;
|
||||||
int16_t jPosition_;
|
int16_t jPosition_;
|
||||||
std::array<char, 2> character_;
|
std::string stormId_;
|
||||||
|
|
||||||
StormIdSymbol() : iPosition_ {0}, jPosition_ {0}, character_ {0} {}
|
StormIdSymbol() : iPosition_ {0}, jPosition_ {0}, stormId_ {} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class StormIdSymbolPacketImpl
|
class StormIdSymbolPacketImpl
|
||||||
|
|
@ -55,9 +55,9 @@ int16_t StormIdSymbolPacket::j_position(size_t i) const
|
||||||
return p->symbol_[i].jPosition_;
|
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
|
size_t StormIdSymbolPacket::RecordCount() const
|
||||||
|
|
@ -85,9 +85,11 @@ bool StormIdSymbolPacket::ParseData(std::istream& is)
|
||||||
{
|
{
|
||||||
StormIdSymbol& s = p->symbol_[i];
|
StormIdSymbol& s = p->symbol_[i];
|
||||||
|
|
||||||
|
s.stormId_.resize(2);
|
||||||
|
|
||||||
is.read(reinterpret_cast<char*>(&s.iPosition_), 2);
|
is.read(reinterpret_cast<char*>(&s.iPosition_), 2);
|
||||||
is.read(reinterpret_cast<char*>(&s.jPosition_), 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.iPosition_ = ntohs(s.iPosition_);
|
||||||
s.jPosition_ = ntohs(s.jPosition_);
|
s.jPosition_ = ntohs(s.jPosition_);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public:
|
||||||
valueOfText_ {0},
|
valueOfText_ {0},
|
||||||
startI_ {0},
|
startI_ {0},
|
||||||
startJ_ {0},
|
startJ_ {0},
|
||||||
characters_ {}
|
text_ {}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~TextAndSpecialSymbolPacketImpl() = default;
|
~TextAndSpecialSymbolPacketImpl() = default;
|
||||||
|
|
@ -35,7 +35,7 @@ public:
|
||||||
int16_t startI_;
|
int16_t startI_;
|
||||||
int16_t startJ_;
|
int16_t startJ_;
|
||||||
|
|
||||||
std::vector<char> characters_;
|
std::string text_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextAndSpecialSymbolPacket::TextAndSpecialSymbolPacket() :
|
TextAndSpecialSymbolPacket::TextAndSpecialSymbolPacket() :
|
||||||
|
|
@ -71,6 +71,21 @@ std::optional<uint16_t> TextAndSpecialSymbolPacket::value_of_text() const
|
||||||
return value;
|
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
|
size_t TextAndSpecialSymbolPacket::data_size() const
|
||||||
{
|
{
|
||||||
return p->lengthOfBlock_ + 4u;
|
return p->lengthOfBlock_ + 4u;
|
||||||
|
|
@ -133,8 +148,8 @@ bool TextAndSpecialSymbolPacket::Parse(std::istream& is)
|
||||||
|
|
||||||
if (blockValid)
|
if (blockValid)
|
||||||
{
|
{
|
||||||
p->characters_.resize(textLength);
|
p->text_.resize(textLength);
|
||||||
is.read(reinterpret_cast<char*>(p->characters_.data()), textLength);
|
is.read(p->text_.data(), textLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::streampos isEnd = is.tellg();
|
std::streampos isEnd = is.tellg();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue