Jpp  17.1.0
the software that should make you happy
 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 #include "JROOT/JRootToolkit.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JROOT {}
21 namespace JPP { using namespace JROOT; }
22 
23 namespace JROOT {
24 
25  using JLANG::JType;
26  using JEEP::getClassname;
27 
28 
29  /**
30  * Auxiliary class to select ROOT class based on class name.
31  */
33  public std::string
34  {
35  /**
36  * Default contructor.
37  */
39  std::string()
40  {}
41 
42 
43  /**
44  * Contructor.
45  *
46  * \param type_name type_name
47  */
48  JROOTClassSelector(const char* type_name) :
49  std::string(type_name)
50  {}
51 
52 
53  /**
54  * Contructor.
55  *
56  * \param type_name type_name
57  */
58  JROOTClassSelector(const std::string& type_name) :
59  std::string(type_name)
60  {}
61 
62 
63  /**
64  * Contructor.
65  *
66  * \param type data type
67  */
68  template<class T>
69  JROOTClassSelector(const JType<T>& type) :
70  std::string(getClassname(getName(type)))
71  {}
72 
73 
74  /**
75  * Get status of given data type.
76  *
77  * \param type data type
78  * \return true if valid class name; else false
79  */
80  template<class T>
81  bool operator()(const JType<T>& type) const
82  {
83  return *this == getClassname(T::Class_Name());
84  }
85  };
86 
87 
88  /**
89  * Auxiliary class for ROOT class selection.
90  */
92  public std::set<JROOTClassSelector>
93  {
94  /**
95  * Default contructor.
96  */
98  {}
99 
100 
101  /**
102  * Copy contructor.
103  *
104  * \param selection selection
105  */
107  std::set<JROOTClassSelector>(selection)
108  {}
109 
110 
111  /**
112  * Contructor.
113  *
114  * \param typelist type list
115  */
116  template<class T>
117  JROOTClassSelection(const JType<T>& typelist)
118  {
119  JLANG::for_each(*this, typelist);
120  }
121 
122 
123  /**
124  * Add given data type.
125  */
126  template<class T>
127  void add()
128  {
129  this->insert(JROOTClassSelector(JType<T>()));
130  }
131 
132 
133  /**
134  * Remove data type.
135  */
136  template<class T>
137  void remove()
138  {
139  this->erase(JROOTClassSelector(JType<T>()));
140  }
141 
142 
143  /**
144  * Add data type.
145  *
146  * \param type data type
147  */
148  template<class T>
149  void operator()(const JType<T>& type)
150  {
151  add<T>();
152  }
153 
154 
155  /**
156  * Get status of given data type.
157  *
158  * \param type data type
159  * \return true if valid class name; else false
160  */
161  template<class T>
162  bool operator()(const JType<T>& type) const
163  {
164  return this->find(JROOTClassSelector(JType<T>())) != this->end();
165  }
166 
167 
168  /**
169  * Read ROOT class selection from input.
170  *
171  * Note that if the first character of the read class name is:
172  * - a '+', the remainder of the class name is added; or
173  * - a '-', the remainder of the class name is removed; otherwise
174  * - the complete class name is added.
175  *
176  * \param in input stream
177  * \param object ROOT class selection
178  * \return input stream
179  */
180  friend inline std::istream& operator>>(std::istream& in, JROOTClassSelection& object)
181  {
182  for (std::string buffer; in >> buffer; ) {
183 
184  const TRegexp regexp(buffer.substr(1).c_str());
185 
186  switch (buffer[0]) {
187 
188  case '-':
189 
190  for (JROOTClassSelection::iterator i = object.begin(); i != object.end(); ) {
191 
192  if (TString(i->c_str()).Index(regexp) != -1)
193  object.erase(i++);
194  else
195  ++i;
196  }
197 
198  break;
199 
200  case '+':
201 
202  object.insert(buffer.substr(1));
203  break;
204 
205  default:
206 
207  object.insert(buffer);
208  break;
209  }
210  }
211 
212  return in;
213  }
214 
215 
216  /**
217  * Write ROOT class selection to output.
218  *
219  * \param out output stream
220  * \param object ROOT class selection
221  * \return output stream
222  */
223  friend inline std::ostream& operator<<(std::ostream& out, const JROOTClassSelection& object)
224  {
225  for (const_iterator i = object.begin(); i != object.end(); ++i) {
226  out << *i << std::endl;
227  }
228 
229  return out;
230  }
231  };
232 
233 
234  /**
235  * Get ROOT class selection.
236  *
237  * \return ROOT class selection
238  */
239  template<class T>
241  {
242  return JROOTClassSelection(JType<T>());
243  }
244 }
245 
246 #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)
Add data type.
JROOTClassSelection(const std::set< JROOTClassSelector > &selection)
Copy contructor.
void add()
Add given data type.
std::string getClassname(const std::string &type_name)
Get type name, i.e. part after JEEP::TYPENAME_SEPARATOR.
Definition: JeepToolkit.hh:284
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:415
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.
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:57
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46