DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Operators.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DD4HEP_DD4HEP_OPERATORS_H
15 #define DD4HEP_DD4HEP_OPERATORS_H
16 
17 // C/C++ include files
18 #include <string>
19 
21 namespace DD4hep {
22 
24  template <typename T> class ByName {
25  private:
27  template <typename Q> ByName<T>& operator=(const ByName<Q>& /* copy */) { return *this; }
28  public:
30  const std::string& name;
32  ByName(const std::string& nam) : name(nam) {}
34  ByName(const ByName& copy) : name(copy.name) {}
36  bool operator()(const T& entry) const { return entry.name() == name; }
38  bool operator()(const T* entry) const { return entry->name() == name; }
39  };
40  template <typename T> ByName<T> byName(const std::string& n) { return ByName<T>(n); }
41  template <typename T> ByName<T> byName(const T* o) { return ByName<T>(o->name()); }
42  template <typename T> ByName<T> byName(const T& o) { return ByName<T>(o.name()); }
43 
45  template <typename T> class ByNameAttr {
46  private:
48  template <typename Q> ByNameAttr<T>& operator=(const ByNameAttr<Q>& /* copy */) { return *this; }
49  public:
51  const std::string& name;
53  ByNameAttr(const std::string& nam) : name(nam) {}
55  ByNameAttr(const ByNameAttr& copy) : name(copy.name) {}
57  bool operator()(const T& entry) const { return entry.name == name; }
59  bool operator()(const T* entry) const { return entry->name == name; }
60  };
61 
62  template <typename T> ByNameAttr<T> byNameAttr(const std::string& nam) { return ByNameAttr<T>(nam); }
63  template <typename T> ByNameAttr<T> byNameAttr(const T* o) { return ByNameAttr<T>(o->name); }
64  template <typename T> ByNameAttr<T> byNameAttr(const T& o) { return ByNameAttr<T>(o.name); }
65 
66 } // End namespace DD4hep
67 #endif // DD4HEP_DD4HEP_OPERATORS_H
bool operator()(const T *entry) const
Operator to select from pointer containers.
Definition: Operators.h:59
bool operator()(const T &entry) const
Operator to select from object containers.
Definition: Operators.h:36
ByName< T > & operator=(const ByName< Q > &)
Assignment operator.
Definition: Operators.h:27
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
ByName< T > byName(const std::string &n)
Definition: Operators.h:40
Helper functor to select elements by name (using name() member method)
Definition: Operators.h:24
ByNameAttr(const ByNameAttr &copy)
Copy constructor.
Definition: Operators.h:55
ByNameAttr(const std::string &nam)
Standard constructor.
Definition: Operators.h:53
bool operator()(const T &entry) const
Operator to select from object containers.
Definition: Operators.h:57
Helper functor to select elements by name (using name member variable)
Definition: Operators.h:45
ByName(const std::string &nam)
Standard constructor.
Definition: Operators.h:32
ByName(const ByName &copy)
Copy constructor.
Definition: Operators.h:34
bool operator()(const T *entry) const
Operator to select from pointer containers.
Definition: Operators.h:38
const std::string & name
Reference name.
Definition: Operators.h:30
const std::string & name
Reference name.
Definition: Operators.h:51
ByNameAttr< T > & operator=(const ByNameAttr< Q > &)
Assignment operator.
Definition: Operators.h:48
ByNameAttr< T > byNameAttr(const std::string &nam)
Definition: Operators.h:62