advance(o);
}
+ template<bool is_const>
+ buffer::list::iterator_impl<is_const>::iterator_impl(const buffer::list::iterator& i)
+ : iterator_impl<is_const>(i.bl, i.off, i.p, i.p_off) {}
+
template<bool is_const>
void buffer::list::iterator_impl<is_const>::advance(int o)
{
advance(o);
}
- template<bool is_const>
- bool buffer::list::iterator_impl<is_const>::operator!=(const buffer::list::iterator_impl<is_const>& rhs) const
- {
- return bl != rhs.bl || off != rhs.off;
- }
-
template<bool is_const>
char buffer::list::iterator_impl<is_const>::operator*() const
{
}
}
-
// -- buffer::list --
buffer::list::list(list&& other)
unsigned _memcopy_count; //the total of memcopy using rebuild().
ptr append_buffer; // where i put small appends.
+ public:
+ class iterator;
+
+ private:
template <bool is_const>
class CEPH_BUFFER_DETAILS iterator_impl
: public std::iterator<std::forward_iterator_tag, char> {
unsigned off; // in bl
list_iter_t p;
unsigned p_off; // in *p
+ friend class iterator_impl<true>;
public:
// constructor. position.
iterator_impl(bl_t *l, unsigned o=0);
iterator_impl(bl_t *l, unsigned o, list_iter_t ip, unsigned po)
: bl(l), ls(&bl->_buffers), off(o), p(ip), p_off(po) {}
+ iterator_impl(const list::iterator& i);
/// get current iterator offset in buffer::list
unsigned get_off() const { return off; }
void advance(int o);
void seek(unsigned o);
- bool operator!=(const iterator_impl& rhs) const;
char operator*() const;
iterator_impl& operator++();
ptr get_current_ptr() const;
- bl_t& get_bl() { return *bl; }
+ bl_t& get_bl() const { return *bl; }
// copy data out.
// note that these all _append_ to dest!
void copy(unsigned len, list &dest);
void copy(unsigned len, std::string &dest);
void copy_all(list &dest);
+
+ friend bool operator==(const iterator_impl& lhs,
+ const iterator_impl& rhs) {
+ return &lhs.get_bl() == &rhs.get_bl() && lhs.get_off() == rhs.get_off();
+ }
+ friend bool operator!=(const iterator_impl& lhs,
+ const iterator_impl& rhs) {
+ return &lhs.get_bl() != &rhs.get_bl() || lhs.get_off() != rhs.get_off();
+ }
};
public:
void copy_in(unsigned len, const char *src);
void copy_in(unsigned len, const char *src, bool crc_reset);
void copy_in(unsigned len, const list& otherl);
+
+ bool operator==(const iterator& rhs) const {
+ return bl == rhs.bl && off == rhs.off;
+ }
+ bool operator!=(const iterator& rhs) const {
+ return bl != rhs.bl || off != rhs.off;
+ }
};
private:
l.update(r);
return l;
}
+
}
#if defined(HAVE_XIO)
j.advance(-1);
EXPECT_EQ('X', *j);
}
+
+ //
+ // const_iterator(const iterator& other)
+ //
+ {
+ bufferlist bl;
+ bl.append("ABC", 3);
+ bufferlist::iterator i(&bl);
+ bufferlist::const_iterator ci(i);
+ EXPECT_EQ(0u, ci.get_off());
+ EXPECT_EQ('A', *ci);
+ }
}
TEST(BufferListIterator, empty_create_append_copy) {
ASSERT_TRUE(out.contents_equal(bl));
}
-TEST(BufferListIterator, operator_equal) {
+TEST(BufferListIterator, operator_assign) {
bufferlist bl;
bl.append("ABC", 3);
bufferlist::iterator i(&bl, 1);
}
}
+TEST(BufferListIterator, operator_equal) {
+ bufferlist bl;
+ bl.append("ABC", 3);
+ {
+ bufferlist::iterator i(&bl);
+ bufferlist::iterator j(&bl);
+ EXPECT_EQ(i, j);
+ }
+ {
+ bufferlist::const_iterator ci = bl.begin();
+ bufferlist::iterator i = bl.begin();
+ EXPECT_EQ(i, ci);
+ EXPECT_EQ(ci, i);
+ }
+}
+
+TEST(BufferListIterator, operator_nequal) {
+ bufferlist bl;
+ bl.append("ABC", 3);
+ {
+ bufferlist::iterator i(&bl);
+ bufferlist::iterator j(&bl);
+ EXPECT_NE(++i, j);
+ }
+ {
+ bufferlist::const_iterator ci = bl.begin();
+ bufferlist::const_iterator cj = bl.begin();
+ ++ci;
+ EXPECT_NE(ci, cj);
+ bufferlist::iterator i = bl.begin();
+ EXPECT_NE(i, ci);
+ EXPECT_NE(ci, i);
+ }
+ {
+ // tests begin(), end(), operator++() also
+ string s("ABC");
+ int i = 0;
+ for (auto c : bl) {
+ EXPECT_EQ(s[i++], c);
+ }
+ }
+}
+
TEST(BufferListIterator, operator_plus_plus) {
bufferlist bl;
{
bufferlist::iterator i(&bl);
++i;
EXPECT_EQ('B', *i);
- }
+ }
}
TEST(BufferListIterator, get_current_ptr) {