CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDBase.h
Go to the documentation of this file.
1 #ifndef DDCore_DDBase_h
2 #define DDCore_DDBase_h
3 
4 #include <utility>
5 #include <string>
9 
13 template <class N, class C>
14 class DDBase
15 {
16 public:
17  template <class D>
18  class iterator
19  {
20  public:
22  typedef D value_type;
23 
24  explicit iterator( const typename DDI::Store<N,C>::iterator & it) : it_(it) { }
25 
27 
28  value_type& operator*() const {
29  d_.prep_ = it_->second;
30  return d_;
31  }
32 
34  d_.prep_ = it_->second;
35  return &d_;
36  }
37 
38  bool operator==(const iterator & i) {
39  return i.it_ == it_;
40  }
41 
42  bool operator!=(const iterator & i) {
43  return i.it_ != it_;
44  }
45 
46  bool operator<(const iterator & i) {
47  return it_ < i.it_;
48  }
49 
50  bool operator>(const iterator & i) {
51  return it_ > i.it_;
52  }
53 
54  void operator++() {
55  ++it_;
56  }
57 
58  void end() const {
59  it_ = StoreT::instance().end();
60  }
61 
62 
63  private:
64  mutable typename DDI::Store<N,C>::iterator it_;
65  mutable D d_;
66  };
67 
68 public:
69  static typename DDI::Store<N,C>::iterator end() { return StoreT::instance().end(); }
70  static typename DDI::Store<N,C>::iterator begin() { return StoreT::instance().begin(); }
71  // dangerous stuff!!
72  static void clear() { StoreT::instance().clear(); }
73  static size_t size() { return StoreT::instance().size(); }
75  typedef C pimpl_type;
77  typedef std::pair<const N*,bool> def_type;
78 
79  DDBase() : prep_(0) { }
80  virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/ }
81 
82  const N & name() const { return prep_->name(); }
83 
84  const N & ddname() const { return prep_->name(); }
85 
86  std::string toString() const { return prep_->name().fullname(); }
87 
88 
89  const typename DDI::rep_traits<N,C>::reference rep() const
90  { return *(prep_->second); }
91 
93  { return *(prep_->second); }
94 
95  const typename DDI::rep_traits<N,C>::reference val() const
96  { if (!isValid()) throw cms::Exception("DDException") << "undefined: " << name();
97  return rep();
98  };
99 
101  { if (!isValid()) throw cms::Exception("DDException") << "undefined: " << name();
102  return rep();
103  };
104 
105  bool operator==(const DDBase & b) const { return prep_ == b.prep_; }
106  // true, if registered or defined
107  operator bool() const { return isValid(); }
108 
109  bool operator<(const DDBase & b) const { return prep_ < b.prep_; }
110  bool operator>(const DDBase & b) const { return prep_ > b.prep_; }
111 
112  // (name*,true) if defined
113  // (name*,false) if registered but not defined
114  // (0,false) if not there at all
116  {
117  return prep_ ?
118  std::make_pair(&(prep_->name()), bool(prep_->second))
119  :
120  std::make_pair((const N *)0,false);
121  }
122 
124  bool isValid() const
125  {
126  return prep_ ? bool(prep_->second)
127  : false;
128  }
129 
130 protected:
132 private:
133  //bool operator==(const DDBase &);
134  //bool operator<(const DDBase &) const ;
135 };
136 
137 #endif
I::reference reference
Definition: rep_type.h:12
Definition: DDBase.h:14
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:95
int i
Definition: DBlmapReader.cc:9
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:89
def_type isDefined() const
Definition: DDBase.h:115
value_type * operator->() const
Definition: DDBase.h:33
const N & name() const
Definition: DDBase.h:82
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:100
iterator(const typename DDI::Store< N, C >::iterator &it)
Definition: DDBase.h:24
DDI::rep_type< N, pimpl_type > * prep_type
Definition: DDBase.h:76
bool operator==(const DDBase &b) const
Definition: DDBase.h:105
std::pair< const N *, bool > def_type
Definition: DDBase.h:77
static PFTauRenderPlugin instance
bool operator>(const DDBase &b) const
Definition: DDBase.h:110
virtual ~DDBase()
Definition: DDBase.h:80
registry_type::iterator iterator
Definition: Store.h:59
value_type & operator*() const
Definition: DDBase.h:28
static value_type & instance()
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:124
static size_t size()
Definition: DDBase.h:73
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ....
Definition: DDBase.h:22
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:34
DDBase()
Definition: DDBase.h:79
bool operator>(const iterator &i)
Definition: DDBase.h:50
static void clear()
Definition: DDBase.h:72
std::string toString() const
Definition: DDBase.h:86
bool operator<(const iterator &i)
Definition: DDBase.h:46
#define N
Definition: blowfish.cc:9
double b
Definition: hdecay.h:120
void operator++()
Definition: DDBase.h:54
bool operator!=(const iterator &i)
Definition: DDBase.h:42
static DDI::Store< N, C >::iterator begin()
Definition: DDBase.h:70
bool operator==(const iterator &i)
Definition: DDBase.h:38
DDI::Singleton< DDI::Store< N, C > > StoreT
Definition: DDBase.h:74
static DDI::Store< N, C >::iterator end()
Definition: DDBase.h:69
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:64
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:92
prep_type prep_
Definition: DDBase.h:131
C pimpl_type
Definition: DDBase.h:75
void end() const
Definition: DDBase.h:58
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
bool operator<(const DDBase &b) const
Definition: DDBase.h:109
const N & ddname() const
Definition: DDBase.h:84