File: Array2D.h

package info (click to toggle)
clustalx 2.1%2Blgpl-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,324 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 16
file content (141 lines) | stat: -rw-r--r-- 2,786 bytes parent folder | download | duplicates (11)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
#ifndef ARRAY2D_H
#define ARRAY2D_H

#include<iostream>
#include <vector>
namespace clustalw
{

using namespace std;

template <class T>
class Array2D
{
public:
   Array2D():m_dimRow(0), m_dimCol(0){;}
   Array2D(int nRow, int nCol) 
   {
       m_dimRow = nRow;
       m_dimCol = nCol;
       for (int i=0; i < nRow; i++)
       {
           vector<T> x(nCol);
           int y = x.size();
           m_2DVector.push_back(x);
       }
   }
   
   int getRowSize()
   {
       return m_dimRow;
   }
   
   int getColSize()
   {
       return m_dimCol;
   }
   
   void SetAt(int nRow, int nCol, const T& value)
   {
       m_2DVector[nRow][nCol] = value;
   }
   T GetAt(int nRow, int nCol) 
   {
       return m_2DVector[nRow][nCol];
   }
   void GrowRow(int newSize) 
   {
       if (newSize <= (int)m_dimRow)
           return;
       m_dimRow = newSize;
       for(int i = 0 ; i < newSize - (int)m_dimCol; i++)   
       {
           vector<T> x(m_dimRow);
           m_2DVector.push_back(x);
       }
   }
   void GrowCol(int newSize) 
   {
       if(newSize <= (int)m_dimCol)
           return;
       m_dimCol = newSize;
       for (int i=0; i < (int)m_dimRow; i++)
           m_2DVector[i].resize(newSize);
   }
   
   void ResizeRect(int row, int col)
   {
       GrowRow(row);
       GrowCol(col);
   }

   /* This is to get everything initialised to a value */
   void GrowRow(int newSize, const T& value) 
   {
       if (newSize <= m_dimRow)
           return;
       m_dimRow = newSize;
       for(int i = 0 ; i < newSize - m_dimCol; i++)   
       {
           vector<T> x(m_dimRow, value);
           m_2DVector.push_back(x);
       }
   }
   void GrowCol(int newSize, const T& value) 
   {
       if(newSize <= m_dimCol)
           return;
       m_dimCol = newSize;
       for (int i=0; i <m_dimRow; i++)
           m_2DVector[i].resize(newSize, value);
   }
   
   void ResizeRect(int row, int col, const T& value)
   {
       GrowRow(row, value);
       GrowCol(col, value);
   }   
      
   void printArray()
   {
       for(int row=0; row < m_dimRow; row++)
       {
           for(int col=0; col < m_dimCol; col++)
           {
               cout <<" "<< m_2DVector[row][col];  
           }
           cout<<"\n";
       }
   }
   
   void clearArray()
   {
       int size = m_2DVector.size();
       for(int i = 0; i < size; i++)
       {
           m_2DVector[i].clear();
       }
       m_2DVector.clear();
       m_dimRow = 0;
       m_dimCol = 0;
       
   }
   
   vector<T>& operator[](int x)    
   {
       return m_2DVector[x];
   }
private:
   vector< vector <T> > m_2DVector;
   unsigned int m_dimRow;
   unsigned int m_dimCol;
};

}
#endif