home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file19 / tstvec2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  1.8 KB  |  70 lines

  1. ////////////////////////////////////////////////////////////////
  2. // tstvec2.cpp: Vector test program using struct elements.
  3. // Copyright(c) 1993 Azarona Software. All rights reserved.
  4. ////////////////////////////////////////////////////////////////
  5. #include <iostream.h>
  6. #include "vector.h"
  7. #include "shape.h"
  8.  
  9. template<class TYPE>
  10. void PrtVec(const Vector<TYPE> &v)
  11. // Print out the elements of a vector
  12. {
  13.   VecPtr<const TYPE> cursor(v.PtrToAll());
  14.   unsigned i, len = v.Length();
  15.   for (i = 0; i<len; i++) {
  16.       cout << *cursor << ' ';
  17.       cursor++;
  18.   }
  19.   cout << '\n';
  20. }
  21.  
  22. // You need one of these statements for each type of vector:
  23.  
  24. INITNULLVEC(Shape);
  25.  
  26. // A low-level C array we'll copy
  27.  
  28. const int arr_size = 7;
  29. Shape arr[arr_size] = {
  30.   Shape(0,0), Shape(1,1), Shape(2,2), Shape(3,3),
  31.   Shape(4,4), Shape(5,5), Shape(6,6)
  32. };
  33.  
  34. void test()
  35. {
  36.   cout << "Creating a vector\n";
  37.  
  38.   Vector<Shape> myvec(arr_size, arr);
  39.   cout << "myvec: "; PrtVec(myvec);
  40.  
  41.   cout << "Creating a shared slice of every other element\n";
  42.  
  43.   Vector<Shape> everyother(myvec, SHARED, 4, 2);
  44.   cout << "everyother: "; PrtVec(everyother);
  45.  
  46.   cout << "Setting each element in slice to Shape(99,99)\n";
  47.  
  48.   everyother = Shape(99, 99);
  49.   cout << "myvec: ";   PrtVec(myvec);
  50.   cout << "everyother: "; PrtVec(everyother);
  51.  
  52.   cout << "Testing consistency checks for stride, length, and offset\n";
  53.  
  54.   everyother[0] = Shape(101, 101);
  55.   everyother[1] = Shape(202, 202);
  56.   everyother[2] = Shape(303, 303);
  57.   everyother[3] = Shape(404, 404);
  58.  
  59.   Vector<Shape> tstslice(everyother, SHARED, 4, 2, 1);
  60.  
  61.   tstslice[0] = Shape(111, 111);
  62.   tstslice[1] = Shape(222, 222);
  63.  
  64.   cout << "everyother:  "; PrtVec(everyother);
  65.   cout << "tstslice: "; PrtVec(tstslice);
  66.  
  67. }
  68.  
  69. #include "tstmain.cpp"
  70.