KADATH
list_comp.cpp
1 /*
2  Copyright 2018 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #include "array.hpp"
22 #include "array.hpp"
23 #include "list_comp.hpp"
24 
25 namespace Kadath {
26 
27 // Standard onsructor
28 List_comp::List_comp(int nc, int val) : ncomp(nc), valence(val) {
29  pcomp = new Array<int>* [ncomp] ;
30  for (int i=0 ; i<ncomp ; i++)
31  pcomp[i] = new Array<int>(valence) ;
32 }
33 
34 // Constructor by copy
35 List_comp::List_comp(const List_comp& so) : ncomp(so.ncomp), valence(so.valence) {
36  pcomp = new Array<int>* [ncomp] ;
37  for (int i=0 ; i<ncomp ; i++)
38  pcomp[i] = new Array<int>(*so.pcomp[i]) ;
39 }
40 
41 // Destructor
43  for (int i=0 ; i<ncomp ; i++)
44  delete pcomp[i] ;
45  delete [] pcomp ;
46 }
47 
48 // Read/write
50  assert(i>=0) ;
51  assert(i<ncomp) ;
52  return pcomp[i] ;
53 }
54 
55 
56 // Read only
58  assert(i>=0) ;
59  assert(i<ncomp) ;
60  return pcomp[i] ;
61 }
62 }
63 
Class for storing a list of tensorial components.
Definition: list_comp.hpp:33
~List_comp()
Destructor.
Definition: list_comp.cpp:42
Array< int > ** pcomp
Array of pointers on each componenent.
Definition: list_comp.hpp:37
int valence
Number of indices for each component.
Definition: list_comp.hpp:36
List_comp(int nc, int val)
Standard constructor.
Definition: list_comp.cpp:28
int ncomp
Number of stored components.
Definition: list_comp.hpp:35
Array< int > * set(int i)
Read/write of one particular component.
Definition: list_comp.cpp:49
Array< int > * operator()(int i) const
Read/write of one particular component.
Definition: list_comp.cpp:57