CMS 3D CMS Logo

DDBase.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_CORE_DDBASE_H
2 #define DETECTOR_DESCRIPTION_CORE_DDBASE_H
3 
4 #include <utility>
8 
9 template <class N, class C>
10 class DDBase {
11 public:
12  template <class D>
13  class iterator {
14  public:
16  using value_type = D;
17 
18  explicit iterator(const typename DDI::Store<N, C>::iterator it) : it_(it) {}
19 
21 
22  value_type& operator*() const {
23  d_.prep_ = it_->second;
24  return d_;
25  }
26 
28  d_.prep_ = it_->second;
29  return &d_;
30  }
31 
32  bool operator==(const iterator& i) const { return i.it_ == it_; }
33 
34  bool operator!=(const iterator& i) const { return i.it_ != it_; }
35 
36  bool operator<(const iterator& i) const { return it_ < i.it_; }
37 
38  bool operator>(const iterator& i) const { return it_ > i.it_; }
39 
40  void operator++() { ++it_; }
41 
42  void end() const { it_ = StoreT::instance().end(); }
43 
44  private:
45  mutable typename DDI::Store<N, C>::iterator it_;
46  mutable D d_;
47  };
48 
49 public:
51  using def_type = std::pair<const N*, bool>;
52  static auto end() { return StoreT::instance().end(); }
53  static auto begin() { return StoreT::instance().begin(); }
54 
55  DDBase() : prep_(nullptr) {}
56  virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/ }
57 
58  const N& name() const { return prep_->name(); }
59 
60  const N& ddname() const { return prep_->name(); }
61 
62  std::string toString() const { return prep_->name().fullname(); }
63 
64  const typename DDI::rep_traits<N, C>::reference rep() const { return *(prep_->second); }
65 
66  typename DDI::rep_traits<N, C>::reference rep() { return *(prep_->second); }
67 
68  const typename DDI::rep_traits<N, C>::reference val() const {
69  if (!isValid())
70  throw cms::Exception("DDException") << "undefined: " << name();
71  return rep();
72  }
73 
75  if (!isValid())
76  throw cms::Exception("DDException") << "undefined: " << name();
77  return rep();
78  }
79 
80  bool operator==(const DDBase& b) const { return prep_ == b.prep_; }
81  // true, if registered or defined
82  operator bool() const { return isValid(); }
83  bool operator<(const DDBase& b) const { return prep_ < b.prep_; }
84  bool operator>(const DDBase& b) const { return prep_ > b.prep_; }
85 
86  // ( name*, true ) if defined
87  // ( name*, false ) if registered but not defined
88  // ( 0, false ) if not there at all
89  def_type isDefined() const {
90  return prep_ ? std::make_pair(&(prep_->name()), bool(prep_->second)) : std::make_pair((const N*)nullptr, false);
91  }
92 
94  bool isValid() const { return prep_ ? bool(prep_->second) : false; }
95  void create(const N& name, C vals) { prep_ = StoreT::instance().create(name, std::move(vals)); }
96  void create(const N& name) { prep_ = StoreT::instance().create(name); }
97 
98 private:
100 };
101 
102 #endif
Definition: DDBase.h:10
static PFTauRenderPlugin instance
bool operator==(const iterator &i) const
Definition: DDBase.h:32
virtual ~DDBase()
Definition: DDBase.h:56
static auto end()
Definition: DDBase.h:52
bool operator==(const DDBase &b) const
Definition: DDBase.h:80
bool operator>(const DDBase &b) const
Definition: DDBase.h:84
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:64
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:39
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:66
typename registry_type::iterator iterator
Definition: Store.h:45
void end() const
Definition: DDBase.h:42
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:94
static value_type & instance()
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:45
iterator(const typename DDI::Store< N, C >::iterator it)
Definition: DDBase.h:18
bool operator>(const iterator &i) const
Definition: DDBase.h:38
bool operator<(const iterator &i) const
Definition: DDBase.h:36
static auto begin()
Definition: DDBase.h:53
DDBase()
Definition: DDBase.h:55
void create(const N &name)
Definition: DDBase.h:96
bool operator<(const DDBase &b) const
Definition: DDBase.h:83
DDI::rep_type< N, C > * prep_
Definition: DDBase.h:99
std::string toString() const
Definition: DDBase.h:62
const N & name() const
Definition: DDBase.h:58
#define N
Definition: blowfish.cc:9
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
const N & ddname() const
Definition: DDBase.h:60
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ...
Definition: DDBase.h:16
double b
Definition: hdecay.h:120
void operator++()
Definition: DDBase.h:40
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:74
bool operator!=(const iterator &i) const
Definition: DDBase.h:34
typename I::reference reference
Definition: rep_type.h:12
std::pair< const DDName *, bool > def_type
Definition: DDBase.h:51
value_type * operator->() const
Definition: DDBase.h:27
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:68
def_type isDefined() const
Definition: DDBase.h:89
value_type & operator*() const
Definition: DDBase.h:22
def move(src, dest)
Definition: eostools.py:511
void create(const N &name, C vals)
Definition: DDBase.h:95