reprtest.cc 2.19 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*! \file reprtest.cc
 * \brief test representation classes (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id: reprtest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
 * \author Thomas Forbriger
 * \date 10/05/2002
 * 
 * test representation classes (implementation)
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 10/05/2002   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_REPRTEST_CC_VERSION \
  "TF_REPRTEST_CC   V1.0   "
#define TF_REPRTEST_CC_CVSID \
  "$Id: reprtest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"

#include <contxx/repr/sharedheap.h>
#include <iostream>

using std::cout;
using std::endl;

// output function for representation objects
template<class T>
void print(const T& cont, const char* name)
{
  using namespace contxx::util;
  const int blocksize=15;
  cout << name << ":" << endl;
  Tsize size=cont.size();
  int blocks=size / blocksize + 1;
  for (int i=0; i<blocks; i++)
  {
    Tsize first=i*blocksize;
    Tsize last=first+blocksize;
    last = ( last > size ? size : last);
    cout << "  ";
    for (Tsize j=first; j<last; j++)
    { cout.width(5); cout << j; }
    cout << endl << "  ";
    for (Tsize j=first; j<last; j++)
    { cout.width(5); cout << cont[j]; }
    cout << endl << endl;
  }
}

#define PRINT( x ) print(x, #x );

int main()
{
  cout << TF_REPRTEST_CC_VERSION << endl;
  cout << TF_REPRTEST_CC_CVSID << endl;

  using contxx::representation::SharedHeap;

  const int N=10;
  const int N2=23;
  SharedHeap<int> A(N);
  SharedHeap<int> B(N2);
  SharedHeap<const int> C(N2);
  SharedHeap<float> D(N2);

  for (int i=0; i<N; i++) { A[i]=(i+1)*10; }
  for (int i=0; i<N2; i++) { B[i]=(i+4)*3; }
  for (int i=0; i<N2; i++) { D[i]=(i+2.45)*2; }

  PRINT(A)
  PRINT(B)
  C=B;
  PRINT(C)
  // modify C through B
  B[8]=632;
  PRINT(C)
  // modify C directly - is illegal
#ifdef ILLEGAL1
  C[9]=354;
  PRINT(C)
#endif
  // make B a reference to A
  B=A;
  // modification should be visible through B
  A[5]=453;
  PRINT(B)
  // test another type
  PRINT(D)

  cout << endl;
}

/* ----- END OF reprtest.cc ----- */