test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NamedRef.h
Go to the documentation of this file.
1 #ifndef INCLUDE_ORA_NAMEDREF_H
2 #define INCLUDE_ORA_NAMEDREF_H
3 
4 #include "Exception.h"
5 //
6 #include <assert.h>
7 #include <boost/shared_ptr.hpp>
8 
9 namespace ora {
10 
12  public:
14  explicit NamedReference( const std::string& name );
15  NamedReference( const std::string& name, boost::shared_ptr<void> ptr );
16  NamedReference( const NamedReference& rhs );
17  virtual ~NamedReference();
19  void set( const std::string& name );
20  const std::string& name() const;
21  bool isPersistent() const;
22  boost::shared_ptr<void>& ptr() const;
23  void reset();
24  private:
27  mutable boost::shared_ptr<void> m_ptr;
28  };
29 
30  template <typename T> class NamedRef : public NamedReference {
31  public:
32  NamedRef();
33  NamedRef( const std::string& name );
34  NamedRef( const std::string& name, boost::shared_ptr<T>& data );
35  template <typename C> NamedRef( const std::string& name, boost::shared_ptr<C>& data );
36  NamedRef( const NamedRef<T>& rhs );
37  template <typename C> NamedRef( const NamedRef<C>& rhs );
38  virtual ~NamedRef();
39  NamedRef<T>& operator=( const NamedRef<T>& rhs );
40  template <typename C> NamedRef<T>& operator=( const NamedRef<C>& rhs );
41  T* operator->() const;
42  T& operator*() const;
43  operator bool () const;
44  T* get() const;
45  boost::shared_ptr<T> share() const;
46  bool operator!() const;
47  bool operator==(const NamedRef<T>& rhs) const;
48  bool operator!=(const NamedRef<T>& rhs) const;
49  template <class C>
50  bool operator==(const NamedRef<C>& rhs) const;
51  template <class C>
52  bool operator!=(const NamedRef<C>& rhs) const;
53  private:
54  T* safePtr( bool throw_flag ) const;
55 
56  };
57 
58 }
59 
60 template <class T>
62  NamedReference(){}
63 
64 template <class T>
66  NamedReference( name ){}
67 
68 template <class T>
69 inline ora::NamedRef<T>::NamedRef( const std::string& name, boost::shared_ptr<T>& data ) :
70  NamedReference( name, boost::shared_ptr<void>( data ) ){}
71 
72 template <class T>
73 template <class C>
74 inline ora::NamedRef<T>::NamedRef( const std::string& name, boost::shared_ptr<C>& data ) :
75  NamedReference( name, boost::shared_ptr<void>( data )){
76 }
77 
78 template <class T>
80  NamedReference( rhs.name() ){
81 }
82 
83 template <class T>
84 template <class C>
86  NamedReference( rhs.name() ){
87 }
88 
89 template <class T>
91 }
92 
93 template <class T>
96  return *this;
97 }
98 
99 template <class T>
100 template <class C>
103  return *this;
104 }
105 
106 template <class T>
107 T* ora::NamedRef<T>::safePtr( bool throw_flag ) const {
108  T* p = share().get();
109  if( !p && throw_flag) throwException( "Underlying pointer is null.","NamedRef::safePtr");
110  return p;
111 }
112 
113 template <class T>
115  return safePtr( true );
116 }
117 
118 template <class T>
120  return *safePtr( true );
121 }
122 
123 template <class T>
124 inline ora::NamedRef<T>::operator bool() const {
125  return safePtr(false);
126 }
127 
128 template <class T>
129 inline T* ora::NamedRef<T>::get() const {
130  return safePtr(false);
131 }
132 
133 template <class T>
134 inline boost::shared_ptr<T> ora::NamedRef<T>::share() const {
135  return boost::static_pointer_cast<T>(ptr());
136 }
137 
138 template <class T>
139 inline bool ora::NamedRef<T>::operator!() const {
140  return safePtr(false)==0;
141 }
142 
143 template <class T>
145  return share() == rhs.share();
146 }
147 
148 template <class T>
149 bool ora::NamedRef<T>::operator!=(const NamedRef<T>& rhs ) const {
150  return !(this->operator==(rhs));
151 }
152 
153 template <class T>
154 template <class C>
156  return share() == rhs.share();
157 }
158 
159 template <class T>
160 template <class C>
161 bool ora::NamedRef<T>::operator!=(const NamedRef<C>& rhs ) const {
162  return !(this->operator==(rhs));
163 }
164 
165 #endif
166 
167 
168 
boost::shared_ptr< void > & ptr() const
Definition: NamedRef.cc:44
NamedReference & operator=(const NamedReference &rhs)
Definition: NamedRef.cc:22
T * operator->() const
Definition: NamedRef.h:114
T & operator*() const
Definition: NamedRef.h:119
bool operator!() const
Definition: NamedRef.h:139
const std::string & name() const
Definition: NamedRef.cc:36
virtual ~NamedReference()
Definition: NamedRef.cc:19
virtual ~NamedRef()
Definition: NamedRef.h:90
bool operator==(const NamedRef< T > &rhs) const
Definition: NamedRef.h:144
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
T * get() const
Definition: NamedRef.h:129
bool isPersistent() const
Definition: NamedRef.cc:40
T * safePtr(bool throw_flag) const
Definition: NamedRef.h:107
bool operator!=(const NamedRef< T > &rhs) const
Definition: NamedRef.h:149
std::string m_name
Definition: NamedRef.h:25
NamedRef< T > & operator=(const NamedRef< T > &rhs)
Definition: NamedRef.h:94
boost::shared_ptr< T > share() const
Definition: NamedRef.h:134
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void set(const std::string &name)
Definition: NamedRef.cc:31
boost::shared_ptr< void > m_ptr
Definition: NamedRef.h:27
long double T