SortedObjects.cxx
Go to the documentation of this file.
1 /**
2  * @file SortedObjects.cxx
3  *
4  * @author D.Stefan and R.Sulej
5  *
6  * @brief Implementation of the Projection Matching Algorithm
7  *
8  * Base classes for chains and branched chains of nodes and segments.
9  * See PmaTrack3D.h file for details.
10  */
11 
13 
15 
16 
17 //*********************** SortedObjectBase ***********************
19  next(0), prev(0)
20 {
21  if (prevElement) prevElement->AddNext(this);
22  if (nextElement) AddNext(nextElement);
23 }
24 
26 {
27  if (prev) prev->RemoveNext(this);
28  if (next) RemoveNext(next);
29 }
30 
32 {
33  if (!nextElement || (nextElement == this)) return false;
34 
35  if (next && (next->prev == this))
36  next->prev = 0;
37 
38  if (nextElement->prev && (nextElement->prev != this))
39  nextElement->prev->RemoveNext(nextElement);
40 
41  next = nextElement;
42  next->prev = this;
43  return true;
44 }
45 
47 {
48  if (nextElement && (next == nextElement))
49  {
50  if (next->prev == this) next->prev = 0;
51  else
52  {
53  mf::LogError("pma::SortedObjectBase") << "Object structure is broken.";
54  }
55 
56  next = 0;
57  return 0;
58  }
59  else return -1;
60 }
61 //******************************************************************
62 
63 //*********************** SortedBranchBase ***********************
65 {
66  while (next_vector.size()) RemoveNext(next_vector.front());
67  if (prev) prev->RemoveNext(this);
68 }
69 
71 {
72  if (!nextElement)
73  {
74  mf::LogError("pma::SortedBranchBase") << "Next == 0.";
75  return false;
76  }
77 
78  if (nextElement == this)
79  {
80  mf::LogWarning("pma::SortedBranchBase") << "Next == This.";
81  return false;
82  }
83 
84  bool present = false;
85  for (size_t i = 0; i < next_vector.size(); i++)
86  {
87  if (next_vector[i] == nextElement)
88  {
89  mf::LogWarning("pma::SortedBranchBase") << "Contained.";
90  present = true; break;
91  }
92  }
93  if (!present)
94  {
95  if (nextElement->prev) // && (nextElement->prev != this)
96  nextElement->prev->RemoveNext(nextElement);
97 
98  next = nextElement;
99  next->prev = this;
100  next_vector.push_back(next);
101  return true;
102  }
103  else return false;
104 }
105 
107 {
108  if (!nextElement || (nextElement == this)) return -1;
109 
110  int index = -1;
111  for (unsigned int i = 0; i < next_vector.size(); i++)
112  {
113  if (next_vector[i] == nextElement) { index = i; break; }
114  }
115  if (index >= 0)
116  {
117  if (next_vector[index]->prev != this)
118  {
119  mf::LogError("pma::SortedBranchBase") << "Object structure is broken.";
120  return -1;
121  }
122  next_vector[index]->prev = 0;
123  next_vector.erase(next_vector.begin() + index);
124 
125  if (next_vector.size() > 0) next = next_vector.back();
126  else next = 0;
127  }
128  return index;
129 }
130 //******************************************************************
131 
virtual bool AddNext(pma::SortedObjectBase *nextElement)
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Implementation of the Projection Matching Algorithm.
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
virtual void Disconnect(void)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual void Disconnect(void)
virtual bool AddNext(pma::SortedObjectBase *nextElement)
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10