GeoModel - GeoModelCore
Path.h
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef GEOMODELKERNEL_PATH_H
6 #define GEOMODELKERNEL_PATH_H
7 
14 #include <vector>
15 #include <cstdlib>
16 
17 template <class T>
18 class Path
19 {
20  public:
21  Path();
22  Path(const Path< T > &right);
23  ~Path();
24 
25  Path< T > & operator=(const Path< T > &right);
26 
27  // Pops the last node from the stack.
28  const T * pop ();
29 
30  // Pushes another node on to the tail of the path.
31  void push (const T *node);
32 
33  // Returns the length of the path.
34  unsigned int getLength () const;
35 
36  // Returns the ith Item.
37  const T * getItem (unsigned int i) const;
38 
39  // Gets the head of the path.
40  const T * getHead () const;
41 
42  // Gets the tail of the path.
43  const T * getTail () const;
44 
45  private:
46  // A list of physical volumes betwee the head of the path
47  // and the tail of the path.
48  std::vector<const T *> m_nodeList;
49 
50 };
51 
52 template <class T>
53 inline Path<T>::Path()
54 {
55  m_nodeList.reserve(2);
56 }
57 
58 template <class T>
59 inline Path<T>::Path(const Path<T> &right)
60  : m_nodeList(right.m_nodeList)
61 {
62 }
63 
64 template <class T>
65 inline Path<T>::~Path()
66 {
67 }
68 
69 template <class T>
70 inline Path<T> & Path<T>::operator=(const Path<T> &right)
71 {
72  if (this != &right)
73  {
74  m_nodeList = right.m_nodeList;
75  }
76  return *this;
77 }
78 
79 template <class T>
80 inline const T * Path<T>::pop ()
81 {
82  if (m_nodeList.size () == 0)
83  {
84  return nullptr;
85  }
86  else
87  {
88  const T *gvp = m_nodeList.back ();
89  m_nodeList.pop_back ();
90  return gvp;
91  }
92 }
93 
94 template <class T>
95 inline void Path<T>::push (const T *node)
96 {
97  m_nodeList.push_back (node);
98 }
99 
100 template <class T>
101 inline unsigned int Path<T>::getLength () const
102 {
103  return m_nodeList.size ();
104 }
105 
106 template <class T>
107 inline const T * Path<T>::getItem (unsigned int i) const
108 {
109  if (m_nodeList.size () == 0)
110  {
111  return nullptr;
112  }
113  else
114  {
115  return m_nodeList[i];
116  }
117 }
118 
119 template <class T>
120 inline const T * Path<T>::getHead () const
121 {
122  if (m_nodeList.size () == 0)
123  {
124  return nullptr;
125  }
126  else
127  {
128  return m_nodeList.front ();
129  }
130 }
131 
132 template <class T>
133 inline const T * Path<T>::getTail () const
134 {
135  if (m_nodeList.size () == 0)
136  {
137  return nullptr;
138  }
139  else
140  {
141  return m_nodeList.back ();
142  }
143 }
144 
145 #endif
Represents a path from one point in the general tree, to the present point.
Definition: Path.h:18