"Yu Han" <hanjunyu@163.com> ha scritto nel messaggio
news:hjo7uh$2rje$1@adenine.netfront.net...
What you give is an object, not a type. only circular_buffer<buffer>
Again, you *must* use a pointer(i.e, circular_buffer<buffer>*), or
your application will not work!
I read up a little better on boost::circular_buffer so I can now do like
this:
const int numbuff = 3;
struct buffer
{
unsigned char data[1024];
int bytesRecorded;
int user;
buffer(const unsigned char * data_, const int bytesRecorded_, const int
user_) :
bytesRecorded(bytesRecorded_), user(user_)
{
copy(data_, data_ + bytesRecorded_, data);
}
};
struct circular
{
circular_buffer<buffer> cb;
};
int main()
{
map<int, circular> users;
int regkey = 1000;
circular k;
k.cb.set_capacity(numbuff); // Finally!
// Prepare buffer
for(int i = 0; i<numbuff; i++)
{
k.cb.push_back(buffer(NULL,0,0));
}
// Add buffer
k.cb.push_back(buffer((unsigned char*)"hellow world!", 15,1));
k.cb.push_back(buffer((unsigned char*)"hellow world!", 15,2));
k.cb.push_back(buffer((unsigned char*)"hellow world!", 15,3));
// Push in the map
users.insert(make_pair(regkey, k));
// Show map: element regkey
// First element
cout << users[regkey].cb.at(0).user << endl; // 1
// Last element
cout << users[regkey].cb.at(numbuff-1).user << endl; // 3
// Remove from map
users.erase(regkey);
}
I cannot use std::string since I need to deal with binary data