1 #ifndef INCLUDE_ORA_PTR_H
2 #define INCLUDE_ORA_PTR_H
8 #include <boost/shared_ptr.hpp>
26 virtual void*
load()
const=0;
47 template <
typename T>
class Ptr {
55 explicit Ptr(
T* anObject);
85 operator bool ()
const;
91 boost::shared_ptr<T>&
share()
const;
115 boost::shared_ptr<IPtrLoader>&
loader()
const {
130 T*
ptr(
bool throw_flag)
const;
149 m_ptr(),m_loader(),m_isLoaded(
false) {}
153 m_ptr(anObject),m_loader(),m_isLoaded(
true) {}
157 m_ptr(aPtr.m_ptr),m_loader(aPtr.m_loader),m_isLoaded(
false){
163 m_ptr(aPtr.share()),m_loader(aPtr.loader()),m_isLoaded(aPtr.isLoaded()) {
165 C*
c = 0;
T*
t(c); assert(t==0);
190 C*
c = 0;
T*
t(c); assert(t==0);
193 m_ptr = aPtr.
share();
201 m_ptr = boost::dynamic_pointer_cast( aPtr.
share());
238 return ptr(
false)==0;
257 if(throwFlag)
throwException(
"Loader is not installed.",
"Ptr::ptr()");
259 if(!m_isLoaded && m_loader.get()){
260 m_ptr.reset( static_cast<T*>(m_loader->load()));
265 if(throwFlag)
throwException(
"Underlying pointer is null.",
"Ptr::ptr()");
boost::shared_ptr< IPtrLoader > m_loader
bool operator!=(const Ptr< C > &aPtr) const
boost::shared_ptr< T > & share() const
Ptr< T > & operator=(T *)
T * ptr(bool throw_flag) const
virtual void invalidate()=0
virtual void * load() const =0
boost::shared_ptr< IPtrLoader > & loader() const
Ptr< T > & cast(const Ptr< C > &)
virtual bool isValid() const =0
void throwException(const std::string &message, const std::string &methodName)
boost::shared_ptr< T > m_ptr
bool operator==(const Ptr< C > &aPtr) const