e così anche il discorso della mappa!!!
codice:
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <boost/circular_buffer.hpp>
using namespace std;
using namespace boost;
void getDateTime(char * szTime);
const int numbuff = 3;
const int buflen = 30;
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()
{
circular c;
c.cb.set_capacity(numbuff);
// Prepare buffer
for(int i = 0; i<numbuff; i++)
{
c.cb.push_back(buffer(NULL,0,0));
}
c.cb.push_back(buffer((unsigned char*)"hellow world!", 15,1));
c.cb.push_back(buffer((unsigned char*)"hellow world!", 15,2));
c.cb.push_back(buffer((unsigned char*)"hellow world!", 15,3));
c.cb.push_back(buffer((unsigned char*)"hellow world!", 15,4));
// Get last element
cout << c.cb.at(numbuff-1).user << endl;
// get first element
cout << c.cb.at(0).user << endl;
/*
*
* Prova std::map<int, circular> users;
*
*/
map<int, circular> users;
circular k;
k.cb.set_capacity(numbuff);
// 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));
k.cb.push_back(buffer((unsigned char*)"hellow world!", 15,4));
// Push in the map
users.insert(make_pair(1000, k));
// Show map: element 1000
cout << users[1000].cb.at(0).user << endl;
cout << users[1000].cb.at(numbuff-1).user << endl;
system("pause");
return EXIT_SUCCESS;
}
void getDateTime(char * szTime)
{
time_t rawtime = time(NULL);
struct tm timeinfo;
gmtime_s(&timeinfo, &rawtime);
strftime(szTime, 30, "%a, %d %b %Y %X GMT", &timeinfo);
}
e mi ci sono volute solo 15 oreeeeeeeeeeee