Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/popratiomatrix.cc
[mareframe] / trunk / gadget / popratiomatrix.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/popratiomatrix.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "popratiomatrix.h"
2 :     #include "gadget.h"
3 :    
4 :     PopRatioMatrix::PopRatioMatrix(int nr, int nc, PopRatio value) {
5 :     nrow = nr;
6 :     v = new PopRatioVector*[nr];
7 :     int i, j;
8 :     for (i = 0; i < nr; i++)
9 :     v[i] = new PopRatioVector(nc, value);
10 :     }
11 :    
12 :     PopRatioMatrix::PopRatioMatrix(const PopRatioMatrix& initial) : nrow(initial.nrow) {
13 :     int i;
14 :     if (nrow >= 0) {
15 :     v = new PopRatioVector*[nrow];
16 :     for (i = 0; i < nrow; i++)
17 :     v[i] = new PopRatioVector(initial[i]);
18 :     } else {
19 :     v = 0;
20 :     nrow = 0;
21 :     }
22 :     }
23 :    
24 :     PopRatioMatrix::~PopRatioMatrix() {
25 :     int i;
26 :     if (v != 0) {
27 :     for (i = 0; i < nrow; i++)
28 :     delete v[i];
29 :     delete[] v;
30 :     v = 0;
31 :     }
32 :     }
33 :    
34 :     void PopRatioMatrix::AddRows(int add, int length, PopRatio value) {
35 :     if (add <= 0)
36 :     return;
37 :    
38 :     int i;
39 :     if (v == 0) {
40 :     nrow = add;
41 :     v = new PopRatioVector*[nrow];
42 :     for (i = 0; i < nrow; i++)
43 :     v[i] = new PopRatioVector(length, value);
44 :    
45 :     } else {
46 :     PopRatioVector** vnew = new PopRatioVector*[nrow + add];
47 :     for (i = 0; i < nrow; i++)
48 :     vnew[i] = v[i];
49 :     for (i = nrow; i < nrow + add; i++)
50 :     vnew[i] = new PopRatioVector(length, value);
51 :     delete[] v;
52 :     v = vnew;
53 :     nrow += add;
54 :     }
55 :     }
56 :    
57 :     void PopRatioMatrix::Delete(int pos) {
58 :     delete v[pos];
59 :     int i;
60 :     if (nrow > 1) {
61 :     PopRatioVector** vnew = new PopRatioVector*[nrow - 1];
62 :     for (i = 0; i < pos; i++)
63 :     vnew[i] = v[i];
64 :     for (i = pos; i < nrow - 1; i++)
65 :     vnew[i] = v[i + 1];
66 :     delete[] v;
67 :     v = vnew;
68 :     nrow--;
69 :     } else {
70 :     delete[] v;
71 :     v = 0;
72 :     nrow = 0;
73 :     }
74 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge