ATLAS Offline Software
ExpandedIdentifier.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //-----------------------------------------------
6 inline ExpandedIdentifier::ExpandedIdentifier(const ExpandedIdentifier& other,
7  size_type start)
8 {
9  if (start < other.fields()) {
10  element_vector::const_iterator it = other.m_fields.begin();
11  it += start;
12 
13  m_fields.insert(m_fields.end(), it, other.m_fields.end());
14  }
15 }
16 
17 // Modifications
18 //-----------------------------------------------
19 inline void
20 ExpandedIdentifier::add(element_type value)
21 {
22  // Max size of id levels should be < 12
23  m_fields.push_back(value);
24 }
25 
26 //-----------------------------------------------
27 inline ExpandedIdentifier&
28 ExpandedIdentifier::operator<<(element_type value)
29 {
30  // Max size of id levels should be < 12
31  m_fields.push_back(value);
32  return (*this);
33 }
34 
35 //-----------------------------------------------
36 inline ExpandedIdentifier::element_type& ExpandedIdentifier::operator[](
37  size_type index)
38 {
39  // Raises an exception if index is out-of-bounds.
40  return m_fields.at(index);
41 }
42 
43 //-----------------------------------------------
44 inline void
45 ExpandedIdentifier::clear()
46 {
47  m_fields.clear();
48 }
49 
50 // Accessors
51 //-----------------------------------------------
52 inline ExpandedIdentifier::element_type ExpandedIdentifier::operator[](
53  size_type index) const
54 {
55  // Raises an exception if index is out-of-bounds.
56  return m_fields.at(index);
57 }
58 
59 //-----------------------------------------------
60 inline ExpandedIdentifier::size_type
61 ExpandedIdentifier::fields() const
62 {
63  return (m_fields.size());
64 }
65 
66 // Comparison operators
67 
68 //----------------------------------------------------------------
69 inline int
70 ExpandedIdentifier::operator==(const ExpandedIdentifier& other) const
71 {
72  const ExpandedIdentifier& me = *this;
73  const size_type my_fields = fields();
74  const size_type other_fields = other.fields();
75 
76  if (my_fields != other_fields)
77  return (0);
78 
79  size_type field = 0;
80  for (; field < my_fields; ++field) {
81  if (me[field] != other[field])
82  return (0);
83  }
84 
85  return (1);
86 }
87 
88 //----------------------------------------------------------------
89 inline int
90 ExpandedIdentifier::operator!=(const ExpandedIdentifier& other) const
91 {
92  const ExpandedIdentifier& me = *this;
93 
94  return (!(me == other));
95 }
96 
97 //-----------------------------------------------
98 inline int
99 ExpandedIdentifier::operator<(const ExpandedIdentifier& other) const
100 {
101  const ExpandedIdentifier& me = *this;
102  const size_type my_fields = fields();
103  const size_type other_fields = other.fields();
104 
105  size_type field = 0;
106  for (;;) {
107  if ((field == my_fields) || (field == other_fields)) {
108  // Someone has run out of fields. And up to now my_id ==
109  // other_id. If the lengths are different, the following
110  // then defines the "shorter" one to be "less than". If
111  // the lengths are the same, then the two are NOT "less
112  // than".
113  return (my_fields < other_fields);
114  }
115 
116  element_type my_field = me[field];
117  element_type other_field = other[field];
118 
119  if (my_field < other_field)
120  return (1);
121  if (my_field > other_field)
122  return (0);
123 
124  field++;
125  }
126 
127  return (0);
128 }
129 
130 //-----------------------------------------------
131 inline int
132 ExpandedIdentifier::operator>(const ExpandedIdentifier& other) const
133 {
134  const ExpandedIdentifier& me = *this;
135 
136  return (other < me);
137 }
138 
139 //----------------------------------------------------------------
140 inline int
141 ExpandedIdentifier::match(const ExpandedIdentifier& other) const
142 {
143  const ExpandedIdentifier& me = *this;
144  const size_type my_fields = fields();
145  const size_type other_fields = other.fields();
146 
147  const size_type fs = (my_fields < other_fields) ? my_fields : other_fields;
148 
149  for (size_type field = 0; field < fs; ++field) {
150  if (me[field] != other[field])
151  return (0);
152  }
153 
154  return (1);
155 }
156