LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SortedObjects.cxx
Go to the documentation of this file.
1 
13 
15 
16 //*********************** SortedObjectBase ***********************
18  pma::SortedObjectBase* nextElement)
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)) next->prev = 0;
36 
37  if (nextElement->prev && (nextElement->prev != this)) nextElement->prev->RemoveNext(nextElement);
38 
39  next = nextElement;
40  next->prev = this;
41  return true;
42 }
43 
45 {
46  if (nextElement && (next == nextElement)) {
47  if (next->prev == this)
48  next->prev = 0;
49  else {
50  mf::LogError("pma::SortedObjectBase") << "Object structure is broken.";
51  }
52 
53  next = 0;
54  return 0;
55  }
56  else
57  return -1;
58 }
59 //******************************************************************
60 
61 //*********************** SortedBranchBase ***********************
63 {
64  while (next_vector.size())
65  RemoveNext(next_vector.front());
66  if (prev) prev->RemoveNext(this);
67 }
68 
70 {
71  if (!nextElement) {
72  mf::LogError("pma::SortedBranchBase") << "Next == 0.";
73  return false;
74  }
75 
76  if (nextElement == this) {
77  mf::LogWarning("pma::SortedBranchBase") << "Next == This.";
78  return false;
79  }
80 
81  bool present = false;
82  for (size_t i = 0; i < next_vector.size(); i++) {
83  if (next_vector[i] == nextElement) {
84  mf::LogWarning("pma::SortedBranchBase") << "Contained.";
85  present = true;
86  break;
87  }
88  }
89  if (!present) {
90  if (nextElement->prev) // && (nextElement->prev != this)
91  nextElement->prev->RemoveNext(nextElement);
92 
93  next = nextElement;
94  next->prev = this;
95  next_vector.push_back(next);
96  return true;
97  }
98  else
99  return false;
100 }
101 
103 {
104  if (!nextElement || (nextElement == this)) return -1;
105 
106  int index = -1;
107  for (unsigned int i = 0; i < next_vector.size(); i++) {
108  if (next_vector[i] == nextElement) {
109  index = i;
110  break;
111  }
112  }
113  if (index >= 0) {
114  if (next_vector[index]->prev != this) {
115  mf::LogError("pma::SortedBranchBase") << "Object structure is broken.";
116  return -1;
117  }
118  next_vector[index]->prev = 0;
119  next_vector.erase(next_vector.begin() + index);
120 
121  if (next_vector.size() > 0)
122  next = next_vector.back();
123  else
124  next = 0;
125  }
126  return index;
127 }
128 //******************************************************************
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