Edit: Solved. Posted, saw the "const" in the error, and then it hit me: const. Peek() is const (as peeking a buffer shouldn't change it). Change the iterator to a const_iterator, and everything works. Good day, thank you CBoard for sparking my mind.. (That's what I get for trying to be const-correct...)
Edit II: Sorry for the ... width ... of the original post.
Can't seem to get iterators for deques working. This is probably a simple error somewhere. Sorry about the length - tried to make a smaller example but it worked. (And I've no clue how it differs...)
The sole error perplexing me:
Code:
BufferImpl.cpp: In member function `unsigned int Net::BufferImpl::Peek(void*, unsigned int, unsigned int) const':
BufferImpl.cpp:90: error: no match for 'operator=' in
'i = (((const std::deque<Net::DataChunk, std::allocator<Net::DataChunk> >*)
((const Net::BufferImpl*)this)) + 4u)->std::deque<_Tp, _Alloc>::begin
[with _Tp = Net::DataChunk, _Alloc = std::allocator<Net::DataChunk>]()'
N:/MINGW/include/c++/3.4.2/bits/stl_deque.h:101: note:
candidates are:
std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>&
std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>::operator=
(const std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>&)
Header file:
Code:
#ifndef _INET_PIMPL_H
#define _INET_PIMPL_H
#include <stdint.h>
#include <deque>
#include <boost/shared_array.hpp>
namespace Net
{
struct DataChunk
{
// Snipped
};
class BufferImpl
{
std::deque<DataChunk> m_datalist;
public:
BufferImpl();
BufferImpl(const BufferImpl &b);
virtual ~BufferImpl();
BufferImpl &operator = (const BufferImpl &b);
unsigned int Read(void *buffer, unsigned int length);
unsigned int Write(const void *buffer, unsigned int length);
unsigned int Peek(void *buffer, unsigned int length, unsigned int pos = 0) const;
unsigned int Pop(unsigned int length);
unsigned int GetSize() const;
};
}
#endif
Code file:
Code:
#include <stdint.h>
#include <string.h> // For memcpy()
#include <deque>
#include <boost/shared_array.hpp>
#include "inet_pimpl.h"
using namespace Net;
// Snip
unsigned int BufferImpl::Peek(void *buffer, unsigned int length, unsigned int pos) const
{
uint8_t *ubuf = (uint8_t *) buffer;
unsigned int read = 0, seeked = 0;
std::deque<DataChunk>::iterator i;
for(i = m_datalist.begin(); i != m_datalist.end(); ++i)
{
if(seeked < pos)
{
// Are we at our chunk yet?
seeked += (*i).GetDataSize();
if(seeked <= pos) continue;
// We're done seeking, but _some_ data in this chunk must be copied.
// (We've "ought seeked")
read = (*i).Peek(ubuf, length, pos - (seeked - (*i).GetDataSize()));
}
else
{
// Continue reading
read += (*i).Peek(ubuf + read, length - read);
}
}
return read;
}
// Snip