ATLAS Offline Software
Loading...
Searching...
No Matches
IntVec.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7#include <cstdint>
8#include <exception>
9#include <iostream>
10
11namespace Trk {
12
14 : m_Nele(0), m_ptr_data(nullptr)
15{}
16
18 : m_Nele(N)
19 , m_ptr_data(new int[m_Nele])
20{
21
22 for(int i=0;i<m_Nele;i++)
23 *(m_ptr_data+i)=0;
24}
25
26IntVec::IntVec(int N, int init)
27 : m_Nele(N)
28 , m_ptr_data(new int[m_Nele])
29{
30
31 for(int i=0;i<m_Nele;i++)
32 *(m_ptr_data+i)=init;
33}
34
36 : m_Nele(v.m_Nele)
37 , m_ptr_data(new int[m_Nele])
38{
39
40 for(int i=0;i<m_Nele;i++)
41 *(m_ptr_data+i)=v[i];
42}
43
45 delete [] m_ptr_data;
46}
47
49 if(m_Nele!=0 && m_Nele!=v.m_Nele) {
50 throw std::range_error( "IntVec Assignment: size does not match!" );
51 }
52
53 if ( m_ptr_data != v.m_ptr_data ) {
54 reSize(v.m_Nele);
55 for(int i=0;i<m_Nele;i++)
56 *(m_ptr_data+i)=v[i];
57 }
58
59 return *this;
60}
61
62int& IntVec::operator[](int i) {
63 if(i<0) {
64 throw std::out_of_range( "IntVec: Index < zero! " );
65 }
66 else if(i>=m_Nele) {
67 throw std::out_of_range( "IntVec: Index too large! " );
68 }
69
70 return *(m_ptr_data+i);
71}
72
73const int& IntVec::operator[](int i) const {
74 if(i<0) {
75 throw std::out_of_range( "IntVec: Index < zero! " );
76 }
77 else if(i>=m_Nele) {
78 throw std::out_of_range( "IntVec: Index too large! " );
79 }
80
81 return *(m_ptr_data+i);
82}
83
85 if( m_Nele != v.m_Nele ) {
86 throw std::range_error( "operator+: vectors size does not match!" );
87 }
88
89 IntVec b(m_Nele);
90 for (int i=0;i<m_Nele;i++)
91 b[i] = *(m_ptr_data+i) + v[i];
92
93 return b;
94}
95
97 if( m_Nele != v.m_Nele ) {
98 throw std::range_error( "operator+=: vectors size does not match!" );
99 }
100
101 for (int i=0;i<m_Nele;i++)
102 *(m_ptr_data+i)+=v[i];
103
104 return *this;
105}
106
108 if( m_Nele != v.m_Nele ) {
109 throw std::range_error( "operator+: vectors size does not match!" );
110 }
111
112 IntVec b(m_Nele);
113 for (int i=0;i<m_Nele;i++)
114 b[i] = *(m_ptr_data+i) - v[i];
115
116 return b;
117}
118
120 if( m_Nele != v.m_Nele ) {
121 throw std::range_error( "operator+=: vectors size does not match!" );
122 }
123
124 for (int i=0;i<m_Nele;i++)
125 *(m_ptr_data+i)-=v[i];
126
127 return *this;
128}
129
130
131void IntVec::reSize(int Nnew) {
132 if ( Nnew>=0 && Nnew != m_Nele ) {
133 int* p = m_ptr_data;
134 int Nele_old = m_Nele;
135 m_ptr_data = new int[Nnew];
136 m_Nele = Nnew;
137 int k = m_Nele <= Nele_old ? m_Nele : Nele_old;
138
139 p += k;
140 int* q = m_ptr_data + k;
141 while (q > m_ptr_data)
142 *(--q) = *(--p);
143
144 delete [] p;
145 }
146}
147
148} // end namespace Trk
int * m_ptr_data
Definition IntVec.h:31
IntVec operator-(const IntVec &)
Definition IntVec.cxx:107
IntVec & operator+=(const IntVec &)
Definition IntVec.cxx:96
IntVec & operator-=(const IntVec &)
Definition IntVec.cxx:119
int & operator[](int)
Definition IntVec.cxx:62
IntVec operator+(const IntVec &)
Definition IntVec.cxx:84
void reSize(int)
Definition IntVec.cxx:131
int m_Nele
Definition IntVec.h:30
IntVec & operator=(const IntVec &)
Definition IntVec.cxx:48
Ensure that the ATLAS eigen extensions are properly loaded.
@ v
Definition ParamDefs.h:78