XEnumerator write single item

This commit is contained in:
Dr. Chat 2015-07-27 18:18:05 -05:00
parent e4d9f38b82
commit ee1565b0e8
1 changed files with 18 additions and 2 deletions

View File

@ -29,10 +29,14 @@ class XEnumerator : public XObject {
virtual uint32_t item_count() const = 0;
virtual void WriteItems(uint8_t* buffer) = 0;
virtual bool WriteItem(uint8_t* buffer) = 0;
size_t current_item() const { return current_item_; }
protected:
size_t item_capacity_;
size_t item_size_;
size_t item_capacity_ = 0;
size_t item_size_ = 0;
size_t current_item_ = 0;
};
class XStaticEnumerator : public XEnumerator {
@ -58,6 +62,18 @@ class XStaticEnumerator : public XEnumerator {
std::memcpy(buffer, buffer_.data(), item_count_ * item_size_);
}
bool WriteItem(uint8_t* buffer) {
if (current_item_ >= item_count_) {
return false;
}
std::memcpy(buffer, buffer_.data() + current_item_ * item_size_,
item_size_);
current_item_++;
return true;
}
private:
uint32_t item_count_;
std::vector<uint8_t> buffer_;