Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

sampbinrec.cpp

Testing... Example file for simple record data read/write as binary mode.

// dataio 0.5 (beta) - Copyright (C) 2001, by Sadao Massago              //
// file: sampbinrec.cpp (record data examples)                           //
// requires: dataio.h, dataio.cpp, stringutil.h, stringutil.cpp          //
// ----------------------------------------------------------------------//
// The dataio library and related files is licenced under the term of    //
// GNU Lesser General Public License version 2.1 or latter               //
// (see lesser.txt for detail).                                          //
// For information over GNU or GNU compatible license, visit the site    //
// http://www.gnu.org.                                                   //

//#include <string>
#include <iostream>
#include <strstream>
#include <vector>

//  #define _DATAIODEBUG_

// #define _DEBUG_

#include "dataio.h"
// it want to copile for single linkable file (without using makefile)
// comment above include and active follow two includes:
 #include "stringutil.cpp"
 #include "dataio.cpp"

// for main()
#include <fstream>

//    void main(int argc, char **argv)
//    {
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;
  }
      
  // file open succeeds

  data1.add(&products);  // products withou field names 

  // data1.add(&list3);  
  data1.add("prices", &prices); // prices with name fields
  data1.additemcomment(&products, "the list of products");
  data1.addcomment("prices", "the price list corresponding to product list");

  data2.add("products", &data1); // data1 is sub data block for data2
  data2.add("money-for-month", &moneyformonth); // one double item
  // add item comment using variable reference for item
  data2.additemcomment(&moneyformonth, "the cote for each month");
  data2.add("responsible for", &activeproducts); // productlist with field names
  // add comment using item names
  data2.addcomment("responsible for", "product controled by this section"); 
  data2.ignorecase(false); // ignore case
  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 << "products.size(): " << products.size() << endl;
  // cout << "main: list1[0][0] = "<<list1[0][0]<<endl;
  // cout << "main: x = " << x << endl;
  // cout << "main: list2[0] = "<<list2[0]<<endl;
  // x = strtod("2.0",NULL);
  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

}       

Generated at Thu Sep 6 13:45:40 2001 for dataio by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001