Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JROOTClassSelector.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JROOTCLASSSELECTOR__
2 #define __JROOT__JROOTCLASSSELECTOR__
3 
4 #include <string>
5 #include <set>
6 
7 #include "TString.h"
8 #include "TRegexp.h"
9 
10 #include "JLang/JTypeList.hh"
11 #include "JLang/JType.hh"
12 #include "Jeep/JeepToolkit.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JROOT {}
20 namespace JPP { using namespace JROOT; }
21 
22 namespace JROOT {
23 
24  using JLANG::JType;
25  using JEEP::getClassname;
26 
27 
28  /**
29  * Auxiliary class to select ROOT class based on class name.
30  */
32  public std::string
33  {
34  /**
35  * Default contructor.
36  */
38  std::string()
39  {}
40 
41 
42  /**
43  * Contructor.
44  *
45  * \param type_name type_name
46  */
47  JROOTClassSelector(const char* type_name) :
48  std::string(type_name)
49  {}
50 
51 
52  /**
53  * Contructor.
54  *
55  * \param type_name type_name
56  */
57  JROOTClassSelector(const std::string& type_name) :
58  std::string(type_name)
59  {}
60 
61 
62  /**
63  * Contructor.
64  *
65  * \param type data type
66  */
67  template<class T>
68  JROOTClassSelector(const JType<T>& type) :
69  std::string(getClassname(T::Class_Name()))
70  {}
71 
72 
73  /**
74  * Get status of given data type.
75  *
76  * \param type data type
77  * \return true if valid class name; else false
78  */
79  template<class T>
80  bool operator()(const JType<T>& type) const
81  {
82  return *this == getClassname(T::Class_Name());
83  }
84  };
85 
86 
87  /**
88  * Auxiliary class for ROOT class selection.
89  */
91  public std::set<JROOTClassSelector>
92  {
93  /**
94  * Default contructor.
95  */
97  {}
98 
99 
100  /**
101  * Copy contructor.
102  *
103  * \param selection selection
104  */
106  std::set<JROOTClassSelector>(selection)
107  {}
108 
109 
110  /**
111  * Contructor.
112  *
113  * \param typelist type list
114  */
115  template<class T>
116  JROOTClassSelection(const JType<T>& typelist)
117  {
118  JLANG::for_each(*this, typelist);
119  }
120 
121 
122  /**
123  * Virtual destructor.
124  */
125  /*
126  virtual ~JROOTClassSelection()
127  {}
128  */
129 
130  /**
131  * Add data type.
132  *
133  * \param type data type
134  */
135  template<class T>
136  void operator()(const JType<T>& type)
137  {
138  this->insert(JROOTClassSelector(type));
139  }
140 
141 
142  /**
143  * Get status of given data type.
144  *
145  * \param type data type
146  * \return true if valid class name; else false
147  */
148  template<class T>
149  bool operator()(const JType<T>& type) const
150  {
151  return this->find(getClassname(T::Class_Name())) != this->end();
152  }
153 
154 
155  /**
156  * Read ROOT class selection from input.
157  *
158  * Note that if the first character of the read class name is:
159  * - '+' the remainder of the class name is added; or
160  * - '-' the remainder of the class name is removed; otherwise
161  * - the complete class name is added.
162  *
163  * \param in input stream
164  * \param object ROOT class selection
165  * \return input stream
166  */
167  friend inline std::istream& operator>>(std::istream& in, JROOTClassSelection& object)
168  {
169  for (std::string buffer; in >> buffer; ) {
170 
171  const TRegexp regexp(buffer.substr(1).c_str());
172 
173  switch (buffer[0]) {
174 
175  case '-':
176 
177  for (JROOTClassSelection::iterator i = object.begin(); i != object.end(); ) {
178 
179  if (TString(i->c_str()).Index(regexp) != -1)
180  object.erase(i++);
181  else
182  ++i;
183  }
184 
185  break;
186 
187  case '+':
188 
189  object.insert(buffer.substr(1));
190  break;
191 
192  default:
193 
194  object.insert(buffer);
195  break;
196  }
197  }
198 
199  return in;
200  }
201 
202 
203  /**
204  * Write ROOT class selection to output.
205  *
206  * \param out output stream
207  * \param object ROOT class selection
208  * \return output stream
209  */
210  friend inline std::ostream& operator<<(std::ostream& out, const JROOTClassSelection& object)
211  {
212  for (const_iterator i = object.begin(); i != object.end(); ++i) {
213  out << *i << std::endl;
214  }
215 
216  return out;
217  }
218  };
219 
220 
221  /**
222  * Get ROOT class selection.
223  *
224  * \return ROOT class selection
225  */
226  template<class T>
228  {
229  return JROOTClassSelection(JType<T>());
230  }
231 }
232 
233 #endif
JROOTClassSelector(const JType< T > &type)
Contructor.
JROOTClassSelector()
Default contructor.
JROOTClassSelection(const JType< T > &typelist)
Contructor.
Auxiliary class to select ROOT class based on class name.
Auxiliary class for ROOT class selection.
JROOTClassSelector(const std::string &type_name)
Contructor.
Auxiliary class for a type holder.
Definition: JType.hh:19
std::set< JROOTClassSelector > getROOTClassSelection()
Get ROOT class selection.
friend std::istream & operator>>(std::istream &in, JROOTClassSelection &object)
Read ROOT class selection from input.
JROOTClassSelector(const char *type_name)
Contructor.
void operator()(const JType< T > &type)
Virtual destructor.
JROOTClassSelection(const std::set< JROOTClassSelector > &selection)
Copy contructor.
std::string getClassname(const std::string &type_name)
Get type name, i.e.
Definition: JeepToolkit.hh:226
bool operator()(const JType< T > &type) const
Get status of given data type.
Auxiliary methods for handling file names, type names and environment.
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition: JTypeList.hh:572
bool operator()(const JType< T > &type) const
Get status of given data type.
friend std::ostream & operator<<(std::ostream &out, const JROOTClassSelection &object)
Write ROOT class selection to output.
JROOTClassSelection()
Default contructor.