LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SortedObjects.h
Go to the documentation of this file.
1 
12 #ifndef SortedObjects_h
13 #define SortedObjects_h
14 
15 #include <vector>
16 
17 namespace pma {
18  class SortedObjectBase;
19  class SortedBranchBase;
20 }
21 
23  friend class pma::SortedBranchBase;
24 
25 public:
26  SortedObjectBase(void) : next(0), prev(0) {}
28 
31 
32  virtual ~SortedObjectBase(void) { Disconnect(); }
33 
34  virtual void Disconnect(void);
35 
36  virtual bool AddNext(pma::SortedObjectBase* nextElement);
37  virtual int RemoveNext(pma::SortedObjectBase* nextElement);
38 
39  virtual bool IsFirst(void) const { return !prev; }
40  virtual bool IsLast(void) const { return !next; }
41 
42  virtual pma::SortedObjectBase* Prev(void) const { return prev; }
43  virtual pma::SortedObjectBase* Next(unsigned int /* index */ = 0) const { return next; }
44  virtual unsigned int NextCount(void) const
45  {
46  if (next)
47  return 1;
48  else
49  return 0;
50  }
51 
52 protected:
55 };
56 
60 public:
63  : pma::SortedObjectBase(prevElement, nextElement)
64  {
65  if (nextElement) next_vector.push_back(next);
66  }
69 
70  virtual ~SortedBranchBase(void) { Disconnect(); }
71 
72  virtual void Disconnect(void);
73 
74  virtual bool AddNext(pma::SortedObjectBase* nextElement);
75  virtual int RemoveNext(pma::SortedObjectBase* nextElement);
76 
77  virtual pma::SortedObjectBase* Next(unsigned int index = 0) const
78  {
79  if (next_vector.size())
80  return next_vector[index];
81  else
82  return 0;
83  }
84  virtual unsigned int NextCount(void) const { return next_vector.size(); }
85  virtual bool IsLast(void) const { return !(next_vector.size()); }
86 
87 protected:
88  std::vector<pma::SortedObjectBase*> next_vector;
89 };
90 
91 #endif
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual bool IsFirst(void) const
Definition: SortedObjects.h:39
SortedBranchBase(const pma::SortedBranchBase &)
Note: copy constructor does not preserve connections.
Definition: SortedObjects.h:68
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
virtual bool IsLast(void) const
Definition: SortedObjects.h:40
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:44
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
SortedObjectBase(const pma::SortedObjectBase &)
Note: copy constructor does not preserve connections.
Definition: SortedObjects.h:30
SortedBranchBase(pma::SortedObjectBase *prevElement, pma::SortedObjectBase *nextElement=0)
Definition: SortedObjects.h:62
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
virtual bool IsLast(void) const
Definition: SortedObjects.h:85
virtual ~SortedObjectBase(void)
Definition: SortedObjects.h:32
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual void Disconnect(void)
virtual bool AddNext(pma::SortedObjectBase *nextElement)
virtual ~SortedBranchBase(void)
Definition: SortedObjects.h:70
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42