/*
* Read a bucket of objects
*
* Uses supported classes in Gbiostream
*
*/
#include
#include
#include
#include // reverse, transform vector; copy to output
#include // multiplies; negate; contains functors
#include "POBroker.h"
#include "bucket.h"
#include
using std::cout;
using std::endl;
int main()
{
const int MAX = 9;
cout << "Creating a database of objects" << endl;
POBroker pob("collect.dat");
pob.register_create_function(typeid(Bucket).name(), Bucket::create);
POBObj* pobj;
Bucket buck;
//OR: vector& v = buck.get_items();
for (double num=0; num < MAX; ++num) {
buck.push_back(num);
//OR: v.push_back(num);
//ALSO: buck.get_items().push_back(num);
}
cout << buck << endl;
//OR: vector& V = pnums->get_items();
//OR: copy(V.begin(), V.end(), ostream_iterator(cout," ") );
cout << "Writing a vector of doubles" << endl;
unsigned long oi = pob.writeObj(buck);
cout << "oi=" << oi << endl;
cout << "Searching for inserted object in file" << endl;
if (pob.findObj(oi)) {
Bucket* pnums = (Bucket*)pob.readObj(oi);
cout << "Inserted Object:" << endl;
cout << *pnums << endl;
cout << "\nReversing this vector of doubles:" << endl;
vector& V = pnums->get_items();
reverse(V.begin(), V.end());
cout << *pnums << endl;
cout << "\nDoubling this vector of doubles:" << endl;
transform(V.begin(),V.end(),V.begin(),V.begin(),multiplies());
//OR: transform(V.begin(),V.end(),V.begin(),negate());
cout << *pnums << endl;
pob.modifyObj(pnums);
pob.deleteRef(pnums);
}
else cout << "Not found" << endl;
cout << "\nSearching for modified object in file" << endl;
if (pob.findObj(oi)) {
Bucket* pnums = (Bucket*)pob.readObj(oi);
cout << "Modified Object:" << endl;
cout << *pnums << endl;
pob.deleteRef(pnums);
}
else cout << "Not found" << endl;
cout << "\nExiting from this program" << endl;
return 0;
}