CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
59  const N& name() const { return prep_->name(); }
60 
61  const N& ddname() const { return prep_->name(); }
62 
63  std::string toString() const { return prep_->name().fullname(); }
64 
65  const typename DDI::rep_traits<N, C>::reference rep() const { return *(prep_->second); }
66 
67  typename DDI::rep_traits<N, C>::reference rep() { return *(prep_->second); }
68 
69  const typename DDI::rep_traits<N, C>::reference val() const {
70  if (!isValid())
71  throw cms::Exception("DDException") << "undefined: " << name();
72  return rep();
73  }
74 
76  if (!isValid())
77  throw cms::Exception("DDException") << "undefined: " << name();
78  return rep();
79  }
80 
81  bool operator==(const DDBase& b) const { return prep_ == b.prep_; }
82  // true, if registered or defined
83  operator bool() const { return isValid(); }
84  bool operator<(const DDBase& b) const { return prep_ < b.prep_; }
85  bool operator>(const DDBase& b) const { return prep_ > b.prep_; }
86 
87  // ( name*, true ) if defined
88  // ( name*, false ) if registered but not defined
89  // ( 0, false ) if not there at all
90  def_type isDefined() const {
91  return prep_ ? std::make_pair(&(prep_->name()), bool(prep_->second)) : std::make_pair((const N*)nullptr, false);
92  }
93 
95  bool isValid() const { return prep_ ? bool(prep_->second) : false; }
96  void create(const N& name, C vals) { prep_ = StoreT::instance().create(name, std::move(vals)); }
97  void create(const N& name) { prep_ = StoreT::instance().create(name); }
98 
99 private:
101 };
102 
103 #endif
Definition: DDBase.h:10
def_type isDefined() const
Definition: DDBase.h:90
value_type * operator->() const
Definition: DDBase.h:27
bool operator<(const iterator &i) const
Definition: DDBase.h:36
const N & name() const
Definition: DDBase.h:59
bool operator==(const DDBase &b) const
Definition: DDBase.h:81
static PFTauRenderPlugin instance
bool operator>(const DDBase &b) const
Definition: DDBase.h:85
bool operator>(const iterator &i) const
Definition: DDBase.h:38
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:65
virtual ~DDBase()
Definition: DDBase.h:56
bool operator!=(const iterator &i) const
Definition: DDBase.h:34
static auto end()
Definition: DDBase.h:52
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:67
typename registry_type::iterator iterator
Definition: Store.h:45
value_type & operator*() const
Definition: DDBase.h:22
static value_type & instance()
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:39
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:95
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:45
iterator(const typename DDI::Store< N, C >::iterator it)
Definition: DDBase.h:18
static auto begin()
Definition: DDBase.h:53
def move
Definition: eostools.py:511
DDBase()
Definition: DDBase.h:55
void create(const N &name)
Definition: DDBase.h:97
DDI::rep_type< N, C > * prep_
Definition: DDBase.h:100
std::string toString() const
Definition: DDBase.h:63
#define N
Definition: blowfish.cc:9
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ...
Definition: DDBase.h:16
double b
Definition: hdecay.h:118
void operator++()
Definition: DDBase.h:40
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:75
typename I::reference reference
Definition: rep_type.h:12
std::pair< const DDName *, bool > def_type
Definition: DDBase.h:51
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:69
bool operator==(const iterator &i) const
Definition: DDBase.h:32
void end() const
Definition: DDBase.h:42
bool operator<(const DDBase &b) const
Definition: DDBase.h:84
const N & ddname() const
Definition: DDBase.h:61
void create(const N &name, C vals)
Definition: DDBase.h:96