BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSTwoVector.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSTWOVECTOR_H
19#define BDSTWOVECTOR_H
20#include "BDSException.hh"
21
22#include "globals.hh" // geant4 types / globals
23
24#include <ostream>
25
35template <typename T>
37{
38public:
41 {values[0] = 0; values[1] = 0;}
42
45 {values[0] = x; values[1] = y;}
46
49 {
50 for (G4int i : {0, 1})
51 {values[i] = other.values[i];}
52 }
53
56 {
57 if (this == &rhs)
58 {return *this;}
59 values[0] = rhs.values[0];
60 values[1] = rhs.values[1];
61 return *this;
62 }
63
65 T& operator[](const G4int index)
66 {
67 if (index > 1)
68 {throw BDSException("BDSTwoVector::operator[]> index outside array");}
69 return values[index];
70 }
71
72 // Access a single element.
73 const T& operator[](const G4int index) const
74 {
75 if (index > 1)
76 {throw BDSException("BDSTwoVector::operator[]> index outside array");}
77 return values[index];
78 }
79
81 inline const T& x() const {return values[0];}
82 inline const T& y() const {return values[1];}
84
86 friend std::ostream& operator<< (std::ostream& out, BDSTwoVector const &v)
87 {out << "(" << v.values[0] << ", " << v.values[1] << ")"; return out;}
88
89private:
91 T values[2];
92};
93
94
95#endif
General exception with possible name of object and message.
Simple two vector that's templated so the right type can be used.
BDSTwoVector(const BDSTwoVector &other)
Copy constructor.
BDSTwoVector(T x, T y)
Alternate constructor.
friend std::ostream & operator<<(std::ostream &out, BDSTwoVector const &v)
Output stream.
T & operator[](const G4int index)
Access / set a single element.
BDSTwoVector()
Default constructor.
BDSTwoVector & operator=(const BDSTwoVector &rhs)
Assignment operator.
const T & y() const
Accessor by name.
const T & x() const
Accessor by name.
T values[2]
Member data - x,y.