CMS 3D CMS Logo

DDBase.h
Go to the documentation of this file.
1 #ifndef DDCore_DDBase_h
2 #define DDCore_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  typedef D value_type;
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 
29  value_type* operator->() const {
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 
59  private:
60  mutable typename DDI::Store<N,C>::iterator it_;
61  mutable D d_;
62  };
63 
64 public:
65  static auto end() { return StoreT::instance().end(); }
66  static auto begin() { return StoreT::instance().begin(); }
67  // dangerous stuff!!
68  static void clear() { StoreT::instance().clear(); }
69  static size_t size() { return StoreT::instance().size(); }
71  typedef C pimpl_type;
73  typedef std::pair<const N*,bool> def_type;
74 
75  DDBase() : prep_(0) { }
76  virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/ }
77 
78  const N & name() const { return prep_->name(); }
79 
80  const N & ddname() const { return prep_->name(); }
81 
82  std::string toString() const { return prep_->name().fullname(); }
83 
84  const typename DDI::rep_traits<N,C>::reference rep() const
85  { return *(prep_->second); }
86 
88  { return *(prep_->second); }
89 
90  const typename DDI::rep_traits<N,C>::reference val() const
91  { if (!isValid()) throw cms::Exception("DDException") << "undefined: " << name();
92  return rep();
93  };
94 
96  { if (!isValid()) throw cms::Exception("DDException") << "undefined: " << name();
97  return rep();
98  };
99 
100  bool operator==(const DDBase & b) const { return prep_ == b.prep_; }
101  // true, if registered or defined
102  operator bool() const { return isValid(); }
103 
104  bool operator<(const DDBase & b) const { return prep_ < b.prep_; }
105  bool operator>(const DDBase & b) const { return prep_ > b.prep_; }
106 
107  // (name*,true) if defined
108  // (name*,false) if registered but not defined
109  // (0,false) if not there at all
110  def_type isDefined() const
111  {
112  return prep_ ?
113  std::make_pair(&(prep_->name()), bool(prep_->second))
114  :
115  std::make_pair((const N *)0,false);
116  }
117 
119  bool isValid() const
120  {
121  return prep_ ? bool(prep_->second)
122  : false;
123  }
124 
125 protected:
126  prep_type prep_;
127 };
128 
129 #endif
I::reference reference
Definition: rep_type.h:12
Definition: DDBase.h:10
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:90
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:84
def_type isDefined() const
Definition: DDBase.h:110
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:78
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:95
DDI::rep_type< N, pimpl_type > * prep_type
Definition: DDBase.h:72
bool operator==(const DDBase &b) const
Definition: DDBase.h:100
std::pair< const N *, bool > def_type
Definition: DDBase.h:73
static PFTauRenderPlugin instance
bool operator>(const DDBase &b) const
Definition: DDBase.h:105
bool operator>(const iterator &i) const
Definition: DDBase.h:46
virtual ~DDBase()
Definition: DDBase.h:76
bool operator!=(const iterator &i) const
Definition: DDBase.h:38
static auto end()
Definition: DDBase.h:65
registry_type::iterator iterator
Definition: Store.h:46
value_type & operator*() const
Definition: DDBase.h:24
static value_type & instance()
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:119
static size_t size()
Definition: DDBase.h:69
iterator(const typename DDI::Store< N, C >::iterator it)
Definition: DDBase.h:20
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ....
Definition: DDBase.h:18
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:34
static auto begin()
Definition: DDBase.h:66
DDBase()
Definition: DDBase.h:75
static void clear()
Definition: DDBase.h:68
std::string toString() const
Definition: DDBase.h:82
#define N
Definition: blowfish.cc:9
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
double b
Definition: hdecay.h:120
void operator++()
Definition: DDBase.h:50
DDI::Singleton< DDI::Store< N, C > > StoreT
Definition: DDBase.h:70
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:60
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:87
prep_type prep_
Definition: DDBase.h:126
C pimpl_type
Definition: DDBase.h:71
bool operator==(const iterator &i) const
Definition: DDBase.h:34
void end() const
Definition: DDBase.h:54
bool operator<(const DDBase &b) const
Definition: DDBase.h:104
const N & ddname() const
Definition: DDBase.h:80