Add proper typedefs and restore block number printing in CLI.
This commit is contained in:
parent
dfc466fc87
commit
905e6be0c4
6 changed files with 36 additions and 16 deletions
|
@ -19,7 +19,7 @@ void print_blocks (const std::string& mc_path) {
|
|||
|
||||
for (const auto& blk : mc) {
|
||||
if (blk.has_magic()) {
|
||||
std::cout << "Block " << std::setfill(' ') << std::setw(2) << 0 + 1
|
||||
std::cout << "Block " << std::setfill(' ') << std::setw(2) << blk.index() + 1
|
||||
<< ": \"" << blk.title() << '"';
|
||||
if (blk.block_count() > 1) {
|
||||
std::cout << " [" << blk.block_count() << ']';
|
||||
|
|
|
@ -24,8 +24,9 @@ public:
|
|||
using data_type = typename std::conditional<Const, const uint8_t, uint8_t>::type;
|
||||
|
||||
static const constexpr unsigned int FrameSize = 128;
|
||||
static const constexpr std::size_t ToCBlockIndex = 0xff;
|
||||
|
||||
explicit BasicBlock (data_type* beg);
|
||||
BasicBlock (data_type* beg, std::size_t index);
|
||||
~BasicBlock();
|
||||
|
||||
data_type* begin() { return m_begin; }
|
||||
|
@ -44,10 +45,12 @@ public:
|
|||
bool has_magic() const;
|
||||
IconDisplayFlag icon_display_flag() const;
|
||||
int block_count() const;
|
||||
std::size_t index() const { return m_index; }
|
||||
std::string title() const;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> m_icon_palette;
|
||||
std::size_t m_index;
|
||||
data_type* m_begin;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ public:
|
|||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef BasicBlock<Const> value_type;
|
||||
typedef BasicBlock<Const> reference;
|
||||
typedef BasicBlock<Const> pointer;
|
||||
|
||||
BlockIterator (MemoryCardPtr mc, size_type index);
|
||||
BlockIterator (const BlockIterator&) = default;
|
||||
|
@ -28,8 +31,7 @@ public:
|
|||
template <bool Const2>
|
||||
bool operator< (const BlockIterator<Const2>& other) const;
|
||||
|
||||
BasicBlock<Const> operator*();
|
||||
BasicBlock<true> operator*() const;
|
||||
reference operator*();
|
||||
|
||||
BlockIterator& operator++();
|
||||
BlockIterator operator++(int);
|
||||
|
@ -37,6 +39,8 @@ public:
|
|||
BlockIterator operator--(int);
|
||||
template <bool Const2>
|
||||
difference_type operator- (const BlockIterator<Const2>& other);
|
||||
BlockIterator operator+ (std::ptrdiff_t other) const;
|
||||
BlockIterator operator- (std::ptrdiff_t other) const;
|
||||
|
||||
private:
|
||||
MemoryCardPtr m_mc;
|
||||
|
|
|
@ -66,8 +66,9 @@ namespace {
|
|||
} //unnamed namespace
|
||||
|
||||
template <bool Const>
|
||||
BasicBlock<Const>::BasicBlock (data_type* beg) :
|
||||
BasicBlock<Const>::BasicBlock (data_type* beg, std::size_t index) :
|
||||
m_icon_palette(extract_palette(beg, beg + size())),
|
||||
m_index(index),
|
||||
m_begin(beg)
|
||||
{
|
||||
assert(m_begin);
|
||||
|
|
|
@ -39,17 +39,11 @@ bool BlockIterator<Const>::operator< (const BlockIterator<Const2>& other) const
|
|||
}
|
||||
|
||||
template <bool Const>
|
||||
BasicBlock<Const> BlockIterator<Const>::operator*() {
|
||||
auto BlockIterator<Const>::operator*() -> reference {
|
||||
assert(m_mc);
|
||||
return (*m_mc)[m_index];
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
BasicBlock<true> BlockIterator<Const>::operator*() const {
|
||||
assert(m_mc);
|
||||
return const_cast<const MemoryCard&>(*m_mc)[m_index];
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
BlockIterator<Const>& BlockIterator<Const>::operator++() {
|
||||
++m_index;
|
||||
|
@ -82,6 +76,20 @@ auto BlockIterator<Const>::operator- (const BlockIterator<Const2>& other) -> dif
|
|||
return this->m_index - other.m_index;
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
BlockIterator<Const> BlockIterator<Const>::operator+ (std::ptrdiff_t other) const {
|
||||
auto retval = *this;
|
||||
retval.m_index += other;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
BlockIterator<Const> BlockIterator<Const>::operator- (std::ptrdiff_t other) const {
|
||||
auto retval = *this;
|
||||
retval.m_index -= other;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template class BlockIterator<true>;
|
||||
template class BlockIterator<false>;
|
||||
template bool BlockIterator<true>::operator==(const BlockIterator<true>&) const;
|
||||
|
|
|
@ -17,20 +17,24 @@ MemoryCard::~MemoryCard() = default;
|
|||
|
||||
Block MemoryCard::operator[] (std::size_t index) {
|
||||
assert(index < 15);
|
||||
return Block(m_data.data() + (index + 1) * Block::size());
|
||||
return Block(m_data.data() + (index + 1) * Block::size(), index);
|
||||
}
|
||||
|
||||
ConstBlock MemoryCard::operator[] (std::size_t index) const {
|
||||
assert(index < 15);
|
||||
return ConstBlock(m_data.data() + (index + 1) * Block::size());
|
||||
return ConstBlock(m_data.data() + (index + 1) * Block::size(), index);
|
||||
}
|
||||
|
||||
ContentInfo MemoryCard::content_info() const {
|
||||
return {ConstBlock(m_data.data())};
|
||||
return {ConstBlock(m_data.data(), ConstBlock::ToCBlockIndex)};
|
||||
}
|
||||
|
||||
std::size_t MemoryCard::size() const {
|
||||
return 15;
|
||||
return std::count_if(
|
||||
const_iterator(this, 0),
|
||||
const_iterator(this, 15),
|
||||
[](const auto& blk) {return blk.has_magic();}
|
||||
);
|
||||
}
|
||||
|
||||
auto MemoryCard::begin() -> iterator {
|
||||
|
|
Loading…
Add table
Reference in a new issue