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 {
12  public:
13  template <class D>
14  class iterator
15  {
16  public:
18  using value_type = D;
19 
20  explicit iterator( const typename DDI::Store<N,C>::iterator it ) : it_( it ) {}
21 
23 
24  value_type& operator*() const {
25  d_.prep_ = it_->second;
26  return d_;
27  }
28 
30  d_.prep_ = it_->second;
31  return &d_;
32  }
33 
34  bool operator==( const iterator & i ) const {
35  return i.it_ == it_;
36  }
37 
38  bool operator!=( const iterator & i ) const {
39  return i.it_ != it_;
40  }
41 
42  bool operator<( const iterator & i ) const {
43  return it_ < i.it_;
44  }
45 
46  bool operator>( const iterator & i ) const {
47  return it_ > i.it_;
48  }
49 
50  void operator++() {
51  ++it_;
52  }
53 
54  void end() const {
55  it_ = StoreT::instance().end();
56  }
57 
58  private:
59  mutable typename DDI::Store<N,C>::iterator it_;
60  mutable D d_;
61  };
62 
63  public:
64 
66  using def_type = std::pair< const N*, bool >;
67  static auto end() { return StoreT::instance().end(); }
68  static auto begin() { return StoreT::instance().begin(); }
69 
71  : prep_( nullptr ) { }
72  virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/ }
73 
74  const N & name() const { return prep_->name(); }
75 
76  const N & ddname() const { return prep_->name(); }
77 
78  std::string toString() const { return prep_->name().fullname(); }
79 
80  const typename DDI::rep_traits< N, C >::reference rep() const {
81  return *( prep_->second );
82  }
83 
85  return *( prep_->second );
86  }
87 
88  const typename DDI::rep_traits< N, C >::reference val() const {
89  if( !isValid()) throw cms::Exception( "DDException" ) << "undefined: " << name();
90  return rep();
91  }
92 
94  if( !isValid()) throw cms::Exception( "DDException" ) << "undefined: " << name();
95  return rep();
96  }
97 
98  bool operator==( const DDBase & b ) const { return prep_ == b.prep_; }
99  // true, if registered or defined
100  operator bool() const { return isValid(); }
101  bool operator<( const DDBase & b ) const { return prep_ < b.prep_; }
102  bool operator>( const DDBase & b ) const { return prep_ > b.prep_; }
103 
104  // ( name*, true ) if defined
105  // ( name*, false ) if registered but not defined
106  // ( 0, false ) if not there at all
108  {
109  return prep_ ?
110  std::make_pair( &( prep_->name()), bool( prep_->second ))
111  :
112  std::make_pair(( const N* )nullptr, false );
113  }
114 
116  bool isValid() const
117  {
118  return prep_ ? bool( prep_->second )
119  : false;
120  }
121  void create( const N& name, C vals ) {
122  prep_ = StoreT::instance().create( name, std::move( vals ) );
123  }
124  void create( const N& name ) {
125  prep_ = StoreT::instance().create( name );
126  }
127 
128  private:
129 
131 };
132 
133 #endif
Definition: DDBase.h:10
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:84
def_type isDefined() const
Definition: DDBase.h:107
value_type * operator->() const
Definition: DDBase.h:29
bool operator<(const iterator &i) const
Definition: DDBase.h:42
const N & name() const
Definition: DDBase.h:74
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:93
bool operator==(const DDBase &b) const
Definition: DDBase.h:98
static PFTauRenderPlugin instance
bool operator>(const DDBase &b) const
Definition: DDBase.h:102
#define nullptr
bool operator>(const iterator &i) const
Definition: DDBase.h:46
virtual ~DDBase()
Definition: DDBase.h:72
bool operator!=(const iterator &i) const
Definition: DDBase.h:38
static auto end()
Definition: DDBase.h:67
typename registry_type::iterator iterator
Definition: Store.h:46
value_type & operator*() const
Definition: DDBase.h:24
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:80
static value_type & instance()
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:116
iterator(const typename DDI::Store< N, C >::iterator it)
Definition: DDBase.h:20
static auto begin()
Definition: DDBase.h:68
DDBase()
Definition: DDBase.h:70
void create(const N &name)
Definition: DDBase.h:124
DDI::rep_type< N, C > * prep_
Definition: DDBase.h:130
std::string toString() const
Definition: DDBase.h:78
#define N
Definition: blowfish.cc:9
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:152
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ...
Definition: DDBase.h:18
double b
Definition: hdecay.h:120
void operator++()
Definition: DDBase.h:50
typename I::reference reference
Definition: rep_type.h:13
std::pair< const DDName *, bool > def_type
Definition: DDBase.h:66
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:88
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:59
bool operator==(const iterator &i) const
Definition: DDBase.h:34
void end() const
Definition: DDBase.h:54
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:41
def move(src, dest)
Definition: eostools.py:511
bool operator<(const DDBase &b) const
Definition: DDBase.h:101
const N & ddname() const
Definition: DDBase.h:76
void create(const N &name, C vals)
Definition: DDBase.h:121