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