Class Reference for E1039 Core & Analysis Software
PHTypedNodeIterator.h
Go to the documentation of this file.
1 #ifndef __PHTYPEDNODEITERATOR_H__
2 #define __PHTYPEDNODEITERATOR_H__
3 
4 #include "PHNodeIterator.h"
5 
6 #include <cstddef>
7 
8 class TObject;
9 template<typename T> class PHIODataNode;
10 class PHCompositeNode;
11 
12 // A special PHOOL node iterator that simplifies finding and adding
13 // data nodes. This version is a templated class, to allow its use
14 // interactively in CINT. (CINT only allows function templates in
15 // very recent versions, which we aren't using yet.)
16 // @author Kyle Pope
17 
18 template <class T>
20 {
21 public:
22 
25  myIODataNode = 0;
26  }
27 
29  myIODataNode = 0;
30  }
31 
32  T& operator*();
33 
35  // virtual ~PHTypedNodeIterator(); // Need a virtual ~PHNodeIterator() !
37 
43  PHIODataNode<T>* FindIODataNode(const char* name);
44 
45  PHIODataNode<T>* find(const char* name);
46 
47 
54  PHBoolean AddIODataNode(T* data, const char* name);
55 
56  PHBoolean insert(T* data, const char* name);
57 
58 protected:
60 
61 };
62 
63 template <class T>
64 T&
66 {
67  return *(myIODataNode->getData());
68 }
69 
70 template <class T>
73 {
74  return find(name);
75 }
76 
77 template <class T>
80 {
81  // TODO: also check that "name" is not a null string!
82  if (!name)
83  {
84  return 0;
85  }
86 
87  // Can't do dynamic_cast here; it fails if node was created as
88  // PHIODataNode<X> instead of PHIODataNode<T>, even if T is a
89  // derived class of X! In general, T -> X does not imply A<T> ->
90  // A<X>. ("->" denotes "derives from", and "A" is any template
91  // class)
92  myIODataNode =
93  static_cast<PHIODataNode<T>*>(findFirst("PHIODataNode", name));
94 
95  return myIODataNode;
96 }
97 
98 template <class T>
100 PHTypedNodeIterator<T>::AddIODataNode(T* data, const char* name)
101 {
102  return insert(data, name);
103 }
104 
105 template <class T>
106 PHBoolean
107 PHTypedNodeIterator<T>::insert(T* data, const char* name)
108 {
109  // TODO: also check that "name" is not a null string!
110  if (!name)
111  {
112  return False;
113  }
114 
115  // For IODataNode, ought to check (if possible) that T derives from
116  // TObject. Will typeid() give us this info?
117  PHIODataNode<T>* n = new PHIODataNode<T>(data, name);
118  if (!n)
119  {
120  // problem creating node?
121  return False;
122  }
123 
124  return addNode(n);
125 }
126 
127 // Typedef to simplify notation.
129 
130 #endif /* __PHTYPEDNODEITERATOR_H__ */
PHTypedNodeIterator< TObject > PHRootNodeIterator
PHIODataNode< T > * find(const char *name)
PHBoolean AddIODataNode(T *data, const char *name)
PHTypedNodeIterator(PHCompositeNode *n)
Constructor.
PHIODataNode< T > * FindIODataNode(const char *name)
~PHTypedNodeIterator()
Destructor.
PHIODataNode< T > * myIODataNode
PHBoolean insert(T *data, const char *name)
int PHBoolean
Definition: phool.h:13
static const int False
Definition: phool.h:9