#include <iostream>
#include <strstream>
#include <vector>
#include "dataio.h"
#include "stringutil.cpp"
#include "dataio.cpp"
#include <fstream>
int main()
{
dataio data1, data2;
vector <vector <string> > products;
vector <double> prices;
vector <string> activeproducts;
double moneyformonth;
ifstream f("samprec.txt");
fstream binf("samprec.bin", ios::in | ios::out);
if(!f || !binf) {
cout << "main:error: can't open input files"<< endl;
return 1;
}
data1.add(&products);
data1.add("prices", &prices);
data1.additemcomment(&products, "the list of products");
data1.addcomment("prices", "the price list corresponding to product list");
data2.add("products", &data1);
data2.add("money-for-month", &moneyformonth);
data2.additemcomment(&moneyformonth, "the cote for each month");
data2.add("responsible for", &activeproducts);
data2.addcomment("responsible for", "product controled by this section");
data2.ignorecase(false);
data2.commentline("");
#ifdef _DEBUG_
cout << "main: readding data" << endl;
#endif
f >> data2;
cout << "main: data loaded...\n";
cout << "prices.size() =" << prices.size() << endl;
cout << "products.size() =" << products.size() << endl;
cout << "the nemes refered by data file (does not includes field names) are:\n";
putline(cout, data2.referednames());
if(!data2.refered("money-for-month")) {
cout << endl << "The money-for-month is not on data base. ";
cout << "Setting as 80\n";
moneyformonth = 80;
}
else {
cout << "Money-for-month is refered in database\n";
}
if(!data1.setted("prices"))
cout << "prices correctly loaded\n";
else
cout << "prices value is incorrect data\n";
#ifdef _DEBUG_
cout << "main: writting data" << endl;
#endif
cout << "loaded data\n";
cout << data2 << endl;
cout << "now, products in columnoriented mode\n";
data1.columnoriented = true;
cout << data2;
data2.clearcomment(true);
cout << "writing to binary stream\n";
data2.write(binf);
cout << "readding from binary stream\n";
binf.seekg(0, ios::beg);
data2.read(binf);
cout << "data loaded\n";
cout << data2;
#ifdef _DEBUG_
cout << "products: \n";
for(int i=0; i < products.size(); i++)
putline(cout, products[i]);
#endif
}