LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
pma::SortedBranchBase Class Reference

#include "SortedObjects.h"

Inheritance diagram for pma::SortedBranchBase:
pma::SortedObjectBase pma::Node3D

Public Member Functions

 SortedBranchBase (void)
 
 SortedBranchBase (pma::SortedObjectBase *prevElement, pma::SortedObjectBase *nextElement=0)
 
 SortedBranchBase (const pma::SortedBranchBase &)
 Note: copy constructor does not preserve connections. More...
 
virtual ~SortedBranchBase (void)
 
virtual void Disconnect (void)
 
virtual bool AddNext (pma::SortedObjectBase *nextElement)
 
virtual int RemoveNext (pma::SortedObjectBase *nextElement)
 
virtual pma::SortedObjectBaseNext (unsigned int index=0) const
 
virtual unsigned int NextCount (void) const
 
virtual bool IsLast (void) const
 
virtual bool IsFirst (void) const
 
virtual pma::SortedObjectBasePrev (void) const
 

Protected Attributes

std::vector< pma::SortedObjectBase * > next_vector
 
pma::SortedObjectBasenext
 
pma::SortedObjectBaseprev
 

Detailed Description

Base for classes, where a single object is assigned to Prev() and many objects may be assigned to Next().

Definition at line 59 of file SortedObjects.h.

Constructor & Destructor Documentation

pma::SortedBranchBase::SortedBranchBase ( void  )
inline

Definition at line 61 of file SortedObjects.h.

pma::SortedBranchBase::SortedBranchBase ( pma::SortedObjectBase prevElement,
pma::SortedObjectBase nextElement = 0 
)
inline

Definition at line 62 of file SortedObjects.h.

References pma::SortedObjectBase::next.

63  : pma::SortedObjectBase(prevElement, nextElement)
64  {
65  if (nextElement) next_vector.push_back(next);
66  }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
pma::SortedBranchBase::SortedBranchBase ( const pma::SortedBranchBase )
inline

Note: copy constructor does not preserve connections.

Definition at line 68 of file SortedObjects.h.

virtual pma::SortedBranchBase::~SortedBranchBase ( void  )
inlinevirtual

Member Function Documentation

bool pma::SortedBranchBase::AddNext ( pma::SortedObjectBase nextElement)
virtual

Reimplemented from pma::SortedObjectBase.

Definition at line 69 of file SortedObjects.cxx.

References pma::SortedObjectBase::next, art::productstatus::present(), pma::SortedObjectBase::prev, and pma::SortedObjectBase::RemoveNext().

Referenced by pma::Track3D::AttachBackToSameTPC(), and pma::Track3D::AttachToSameTPC().

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 }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10
void pma::SortedBranchBase::Disconnect ( void  )
virtual

Reimplemented from pma::SortedObjectBase.

Definition at line 62 of file SortedObjects.cxx.

References pma::SortedObjectBase::prev, and pma::SortedObjectBase::RemoveNext().

63 {
64  while (next_vector.size())
65  RemoveNext(next_vector.front());
66  if (prev) prev->RemoveNext(this);
67 }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
virtual bool pma::SortedObjectBase::IsFirst ( void  ) const
inlinevirtualinherited

Definition at line 39 of file SortedObjects.h.

References pma::SortedObjectBase::prev.

39 { return !prev; }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual bool pma::SortedBranchBase::IsLast ( void  ) const
inlinevirtual

Reimplemented from pma::SortedObjectBase.

Definition at line 85 of file SortedObjects.h.

85 { return !(next_vector.size()); }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
int pma::SortedBranchBase::RemoveNext ( pma::SortedObjectBase nextElement)
virtual

Reimplemented from pma::SortedObjectBase.

Definition at line 102 of file SortedObjects.cxx.

References pma::SortedObjectBase::next, and pma::SortedObjectBase::prev.

Referenced by pma::Track3D::AttachBackToSameTPC(), pma::Track3D::AttachToSameTPC(), and pma::Track3D::Split().

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 }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
pma::SortedObjectBase * next
Definition: SortedObjects.h:53

Member Data Documentation

std::vector<pma::SortedObjectBase*> pma::SortedBranchBase::next_vector
protected

Definition at line 88 of file SortedObjects.h.


The documentation for this class was generated from the following files: