home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 34.ddi / CSTRM.ZIP / CBDRDEM2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  2.6 KB  |  129 lines

  1.     // cbdrdem2.cpp
  2.     // Demo CopyBinder defaulting to C strings!
  3.     
  4.     #include <fstream.h>
  5.     #include <iomanip.h>
  6.     #include <cbinder.hpp>
  7.  
  8.     #define ID_CBDR_STRCMP  1
  9.  
  10.     #pragma argsused
  11.     void display1(char * D, voiD M, int * A)
  12.     {
  13.         int i = strlen((char *)D);
  14.  
  15.  
  16.         *A += i;
  17.         cout << "length: " << setw(3) << i
  18.             << "   accumulated length: "
  19.             << setw(3)
  20.             << *A << "   string: "
  21.             << D << "\n";
  22.  
  23.     }
  24.  
  25.     void display2(char * D, unsigned * M)
  26.     {
  27.         cout << "node: " << setw(3)
  28.             << ++*M
  29.             << "   contents: "
  30.             << D << "\n";
  31.     }
  32.  
  33.     main()
  34.     {
  35.         CopyBinder B;
  36.  
  37.         CopyBinder::registerClass();
  38.  
  39.         B.pushC("Now is the time");
  40.         B.insQC("for all programmers");
  41.         B.insQC("");  // empty string should Q and stream!        
  42.         B.atInsC(B.Nodes(),"to stop reinventing");
  43.         B.insQC("the linked list!");
  44.         B.insQC("");  // empty string should Q and stream!
  45.  
  46.         cout << "\n\nOverloaded ++ and typecast: "
  47.             << "operators \n\n";
  48.  
  49.         while (B++)
  50.             cout << (char *)(voiD)B << "\n";
  51.  
  52.         cout << "\n\nOverloaded [] subscript"
  53.             << " operator \n\n";
  54.  
  55.         for (unsigned i = 0; i < B.Nodes(); i++)
  56.             cout << (char *)B[i] << "\n";
  57.  
  58.         cout << "\n\npress enter to continue ...";
  59.         cin.get();
  60.  
  61.         i = 0;
  62.  
  63.         cout << "\n\nForEach iterator \n\n";
  64.  
  65.         B.forEach((BDRforEachBlocK)display1,0,&i);
  66.  
  67.         cout << "\n\npress enter to continue ...";
  68.         cin.get();
  69.  
  70.         B.setComparE((BDRcomparE)strcmp);
  71.  
  72.         RegisterFunction(ID_CBDR_STRCMP,
  73.             (GenericFnC)B.ComparE());
  74.  
  75.         ofstream oS("cbdrdem1.txt");
  76.         if (oS)  {
  77.             oS << (StreamablE) B;
  78.             B.restream();
  79.             oS.close();
  80.             ifstream iS("cbdrdem1.txt");
  81.             if (iS)  {
  82.                 StreamablE C;
  83.                 iS >> C;
  84.                 RestreamRegistry();
  85.                 if (C)
  86.                 {
  87.                   cout << "\n\nStreamed and"
  88.                     << " reloaded CopyBinder \n\n";
  89.                   i = 0;
  90.                   ((CBindeR)C)->forEach(
  91.                       (BDRforEachBlocK)
  92.                         display2,&i,0);
  93.                   ((CBindeR)C)->sort();
  94.                   cout << "\n\nStreamed and"
  95.                     << " reloaded CopyBinder"
  96.                     << " sorted on reloaded"
  97.                     << " compare fnc! \n\n";
  98.                   i = 0;
  99.                   ((CBindeR)C)->forEach(
  100.                       (BDRforEachBlocK)
  101.                         display2,&i,0);
  102.                   delete C;
  103.                 }
  104.                 else
  105.                   cout << "\n\nUnable to reload"
  106.                     << " CopyBinder \n\n";
  107.             }
  108.             else
  109.                 cout << "\n\nUnable to reopen"
  110.                   << " stream for input of"
  111.                   << " of CopyBinder \n\n";
  112.         }
  113.  
  114.         cout << "\n\npress enter to continue ...";
  115.         cin.get();
  116.  
  117.         cout << "\n\nCopyBinder streamed directly to"
  118.             << " cout \n\n";
  119.  
  120.         cout << (StreamablE) B;
  121.         B.restream();
  122.  
  123.  
  124.         cout << "\n\npress enter to quit ...";
  125.         cin.get();
  126.  
  127.         return 0;
  128.     }
  129.