UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cust_lifetime.H
1 /* cust_lifetime.H */
2 /* $Id: cust_lifetime.H,v 1.5 2007/10/10 11:52:45 vlad Exp $ */
3 #ifdef __CubeStorage_H
4 
5 
6 /***********************************************************************
7  * Create 2D cube - matrix.
8  */
9 template<class T>
10 CubeStorage<T>::CubeStorage (int nR, int nC, item_order_t itor)
11  : pDim(NULL), /*iCur(NULL),*/ pStorage(NULL),
12  fpLog(NULL), szFormat(NULL), szStreamDir(NULL)
13 {
14  int dims[2];
15  dims[0] = nR;
16  dims[1] = nC;
17 
18  new_size(2, dims, itor);
19 
20  fpLog = stdout;
21  szFormat = NULL;
22 }
23 
24 
25 /***********************************************************************
26  * Create any dimension supercube.
27  */
28 template<class T>
29 CubeStorage<T>::CubeStorage (int dim_n, int* dims, item_order_t itor)
30  : pDim(NULL), /*iCur(NULL),*/ pStorage(NULL),
31  fpLog(NULL), szFormat(NULL), szStreamDir(NULL)
32 {
33  new_size(dim_n, dims, itor);
34 
35  fpLog = stdout;
36  szFormat = NULL;
37 }
38 
39 
40 /***********************************************************************
41  * Create cube as a copy of another one.
42  */
43 template<class T>
44 CubeStorage<T>::CubeStorage (const CubeStorage<T>& cs, item_order_t itor)
45  : pDim(NULL), /*iCur(NULL),*/ pStorage(NULL),
46  fpLog(NULL), szFormat(NULL), szStreamDir(NULL)
47 {
48  operator=(cs);
49 
50  fpLog = stdout;
51  szFormat = NULL;
52 }
53 
54 
55 /***********************************************************************
56  * Destroy object.
57  */
58 template<class T>
60 {
61  /*delete[] iCur;*/
62  delete[] pDim;
63  delete[] pStorage;
64  delete[] szFormat;
65  delete[] szStreamDir;
66 }
67 
68 
69 /***********************************************************************
70  * Copy cs to this supercube erasing previous contents.
71  */
72 template<class T>
75 {
76  new_size(cs.nDim, cs.pDim, eItemOrder);
77 
78  if(cs.eItemOrder == eItemOrder)
79  memcpy(pDim, cs.pDim, sizeof(T));
80  else /* copy item by item */
81  {
82  int dim_i, *i = new int[nDim];
83  bool good = true;
84 
85  for(dim_i = 0; dim_i < nDim; ++dim_i)
86  i[dim_i] = 0;
87 
88  while(good)
89  {
90  /* copy itself */
91  pStorage[lin_index(i)] = cs.pStorage[lin_index(i)];
92 
93  /* flush flag of allowed index */
94  good = FALSE;
95 
96  /* increment index */
97  for(dim_i = 0; dim_i < nDim; ++dim_i)
98  if(i[dim_i] < pDim[dim_i] - 1)
99  {
100  ++i[dim_i];
101  good = TRUE;
102  break;
103  }
104  else
105  i[dim_i] = 0;
106  }
107  }
108 }
109 
110 
111 #endif /* cust_lifetime.H */
Definition: CubeStorage.H:48