LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 &src)
 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 60 of file SortedObjects.h.

Constructor & Destructor Documentation

pma::SortedBranchBase::SortedBranchBase ( void  )
inline

Definition at line 63 of file SortedObjects.h.

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

Definition at line 64 of file SortedObjects.h.

References pma::SortedObjectBase::next.

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

Note: copy constructor does not preserve connections.

Definition at line 70 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 71 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().

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

Reimplemented from pma::SortedObjectBase.

Definition at line 65 of file SortedObjects.cxx.

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

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

Definition at line 41 of file SortedObjects.h.

References pma::SortedObjectBase::prev.

41 { 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 107 of file SortedObjects.cxx.

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

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

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