ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ObjPtr< T_Obj > Class Template Reference

Pointer to objects managed by ObjContainer. More...

#include <ObjContainer.h>

Collaboration diagram for ObjPtr< T_Obj >:

Public Member Functions

 ObjPtr ()=default
 
 ObjPtr (ObjPtr &&obj_ptr)=default
 
 ObjPtr (const ObjPtr &obj_ptr)
 
 ObjPtr (ObjContainer< T_Obj > &container, const T_Obj &obj)
 Store an external object in the container. More...
 
 ObjPtr (ObjContainer< T_Obj > &container, std::unique_ptr< T_Obj > obj)
 Pass a unique_ptr to the container The Unique_ptr becomes an Owned object i.e has count 1. More...
 
 ObjPtr (ObjContainer< T_Obj > &container, ObjRef ref=ObjRef())
 Share the referred object managed by the given container. More...
 
 ~ObjPtr () noexcept(false)
 
 operator bool () const
 Test whether this pointer points to a valid object. More...
 
ObjPtroperator= (const ObjPtr &obj)
 
ObjPtroperator= (ObjPtr &&obj)
 
ObjPtroperator= (ObjRef ref)
 
bool operator== (const ObjPtr &obj) const
 Test whether two pointer point to the same object. More...
 
bool operator!= (const ObjPtr &obj) const
 Test whether two pointer point to different objects. More...
 
T_Obj & operator* ()
 
T_Obj * operator-> ()
 
T_Obj * get ()
 Get a pointer to a valid manged object. More...
 
const T_Obj * get () const
 Get a const pointer to a valid manged object. More...
 
T_Obj * release ()
 Release the object this pointer points to from the container. More...
 
std::unique_ptr< T_Obj > to_unique ()
 Release the object this pointer points to from the container. More...
 
ObjRef index () const
 Get a light-weight reference to the object pointed to by this pointer The returned light-weight reference does not provide any lifetime guarantees of the object. More...
 
bool isOwned () const
 Return true if the object is managed and owned by the container. More...
 
bool isShared () const
 Return true if the object is managed by the container and if there are more than one instances of ObjPtr which point to this object. More...
 
bool isExtern () const
 Return true if the object is an external object i.e. More...
 

Protected Member Functions

void shareAndSet (ObjRef ref)
 Helper method to increase the share count of the referenced object and point to that object. More...
 

Private Attributes

ObjContainer< T_Obj > * m_container = nullptr
 pointer to the conainer More...
 
ObjRef m_ref {}
 a valid reference to an object stored in the container or an invalid reference. More...
 

Detailed Description

template<class T_Obj>
class ObjPtr< T_Obj >

Pointer to objects managed by ObjContainer.

Definition at line 33 of file ObjContainer.h.

Constructor & Destructor Documentation

◆ ObjPtr() [1/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( )
default

◆ ObjPtr() [2/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( ObjPtr< T_Obj > &&  obj_ptr)
default

◆ ObjPtr() [3/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( const ObjPtr< T_Obj > &  obj_ptr)
inline

Definition at line 477 of file ObjContainer.h.

478  : m_container(obj_ptr.m_container)
479  {
480  shareAndSet(obj_ptr.index());
481  }

◆ ObjPtr() [4/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( ObjContainer< T_Obj > &  container,
const T_Obj &  obj 
)
inline

Store an external object in the container.

Parameters
containerthe container to store the given object
objthe external object to be stored in the container. The container will not claim ownership.

Definition at line 488 of file ObjContainer.h.

489  : m_container(&container)
490  , m_ref(m_container->registerObj(obj))
491  {}

◆ ObjPtr() [5/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( ObjContainer< T_Obj > &  container,
std::unique_ptr< T_Obj >  obj 
)
inline

Pass a unique_ptr to the container The Unique_ptr becomes an Owned object i.e has count 1.

Parameters
containerthe container to store the given object
objthe object to be managed.

Definition at line 501 of file ObjContainer.h.

502  : ObjPtr(container, container.registerObj(obj.release()))
503  {}

◆ ObjPtr() [6/6]

template<class T_Obj >
ObjPtr< T_Obj >::ObjPtr ( ObjContainer< T_Obj > &  container,
ObjRef  ref = ObjRef() 
)
inline

Share the referred object managed by the given container.

Parameters
containerthe container which manages the referenced object.
refa reference to an object in the container (or an invalid reference) to create on invalid ObjPtr.

Definition at line 509 of file ObjContainer.h.

510  : m_container(&container)
511  , m_ref(ref ? container.share(ref) : ref)
512  {}

◆ ~ObjPtr()

template<class T_Obj >
ObjPtr< T_Obj >::~ObjPtr ( )
inlinenoexcept

Definition at line 514 of file ObjContainer.h.

514  {
515  if (m_ref) {
516  m_container->drop(m_ref);
517  }
518  }

Member Function Documentation

◆ get() [1/2]

template<class T_Obj >
T_Obj* ObjPtr< T_Obj >::get ( )
inline

Get a pointer to a valid manged object.

Exceptions
willthrow an exception if this pointer does not point to a valid object.

Definition at line 588 of file ObjContainer.h.

588  {
589  if (!m_ref) return nullptr;
590  else return m_container->get(m_ref);
591  }

◆ get() [2/2]

template<class T_Obj >
const T_Obj* ObjPtr< T_Obj >::get ( ) const
inline

Get a const pointer to a valid manged object.

Exceptions
willthrow an exception if this pointer does not point to a valid object.

Definition at line 598 of file ObjContainer.h.

598  {
599  if (!m_ref) return nullptr;
600  else return std::as_const(*m_container).get(m_ref);
601  }

◆ index()

template<class T_Obj >
ObjRef ObjPtr< T_Obj >::index ( ) const
inline

Get a light-weight reference to the object pointed to by this pointer The returned light-weight reference does not provide any lifetime guarantees of the object.

Definition at line 629 of file ObjContainer.h.

629 { return m_ref; }

◆ isExtern()

template<class T_Obj >
bool ObjPtr< T_Obj >::isExtern ( ) const
inline

Return true if the object is an external object i.e.

if the container does not have ownership over this object.

Definition at line 660 of file ObjContainer.h.

660  {
661  return m_container->isExtern(m_ref);
662  }

◆ isOwned()

template<class T_Obj >
bool ObjPtr< T_Obj >::isOwned ( ) const
inline

Return true if the object is managed and owned by the container.

Definition at line 648 of file ObjContainer.h.

648  {
649  return m_container->isOwned(m_ref);
650  }

◆ isShared()

template<class T_Obj >
bool ObjPtr< T_Obj >::isShared ( ) const
inline

Return true if the object is managed by the container and if there are more than one instances of ObjPtr which point to this object.

Definition at line 654 of file ObjContainer.h.

654  {
655  return m_container->isShared(m_ref);
656  }

◆ operator bool()

template<class T_Obj >
ObjPtr< T_Obj >::operator bool ( ) const
inline

Test whether this pointer points to a valid object.

Definition at line 522 of file ObjContainer.h.

522 { return m_container && m_container->isValid(m_ref); }

◆ operator!=()

template<class T_Obj >
bool ObjPtr< T_Obj >::operator!= ( const ObjPtr< T_Obj > &  obj) const
inline

Test whether two pointer point to different objects.

Definition at line 573 of file ObjContainer.h.

573  {
574  return obj.m_ref != m_ref;
575  }

◆ operator*()

template<class T_Obj >
T_Obj& ObjPtr< T_Obj >::operator* ( )
inline

Definition at line 577 of file ObjContainer.h.

577  {
578  return *m_container->get(m_ref);
579  }

◆ operator->()

template<class T_Obj >
T_Obj* ObjPtr< T_Obj >::operator-> ( )
inline

Definition at line 581 of file ObjContainer.h.

581  {
582  return get();
583  }

◆ operator=() [1/3]

template<class T_Obj >
ObjPtr& ObjPtr< T_Obj >::operator= ( const ObjPtr< T_Obj > &  obj)
inline

Definition at line 524 of file ObjContainer.h.

524  {
525  if (obj.m_ref != m_ref) {
526  if (*this) {
527  m_container->drop(m_ref);
528  }
529  if (obj.m_container) {
530  assert( !m_container || m_container == obj.m_container);
531  m_container = obj.m_container;
532  }
533  shareAndSet(obj.index());
534  }
535  return *this;
536  }

◆ operator=() [2/3]

template<class T_Obj >
ObjPtr& ObjPtr< T_Obj >::operator= ( ObjPtr< T_Obj > &&  obj)
inline

Definition at line 538 of file ObjContainer.h.

538  {
539  if (&obj != this) {
540  if (*this) {
541  m_container->drop(m_ref);
542  }
543  m_ref = std::move(obj.m_ref);
544  if (obj.m_container) {
545  assert( !m_container || m_container == obj.m_container);
546  m_container = obj.m_container;
547  }
548  }
549  return *this;
550  }

◆ operator=() [3/3]

template<class T_Obj >
ObjPtr& ObjPtr< T_Obj >::operator= ( ObjRef  ref)
inline

Definition at line 552 of file ObjContainer.h.

552  {
553  if (ref != m_ref) {
554  if (*this) {
555  m_container->drop(m_ref);
556  }
557  if (!m_container) {
559  }
560  shareAndSet(ref);
561  }
562  return *this;
563  }

◆ operator==()

template<class T_Obj >
bool ObjPtr< T_Obj >::operator== ( const ObjPtr< T_Obj > &  obj) const
inline

Test whether two pointer point to the same object.

Definition at line 567 of file ObjContainer.h.

567  {
568  return obj.m_ref == m_ref;
569  }

◆ release()

template<class T_Obj >
T_Obj* ObjPtr< T_Obj >::release ( )
inline

Release the object this pointer points to from the container.

Returns
a pointer to the object This will remove the ownership over this object from the container. If there are still other ObjPtr instances alive which point to this object, then the object will remain in the container. This it is up to the user to ensure that the object stays alive at least as long as the container.

Definition at line 610 of file ObjContainer.h.

610  {
611  if (!m_ref) return nullptr;
612  else return m_container->release(m_ref);
613  }

◆ shareAndSet()

template<class T_Obj >
void ObjPtr< T_Obj >::shareAndSet ( ObjRef  ref)
inlineprotected

Helper method to increase the share count of the referenced object and point to that object.

Definition at line 635 of file ObjContainer.h.

635  {
636  if (ref) {
637  assert(m_container);
638  m_ref=m_container->share(ref);
639  }
640  else {
641  m_ref=ref;
642  }
643  }

◆ to_unique()

template<class T_Obj >
std::unique_ptr<T_Obj> ObjPtr< T_Obj >::to_unique ( )
inline

Release the object this pointer points to from the container.

Returns
a unique_ptr to the object This will remove the ownership over this object from the container. If there are still other ObjPtr instances alive which point to this object, then the object will remain in the container. Then it is up to the user to ensure that the unique_ptr stays alive at least as long as the container.

Definition at line 622 of file ObjContainer.h.

622  {
623  return std::unique_ptr<T_Obj>(release());
624  }

Member Data Documentation

◆ m_container

template<class T_Obj >
ObjContainer<T_Obj>* ObjPtr< T_Obj >::m_container = nullptr
private

pointer to the conainer

Definition at line 666 of file ObjContainer.h.

◆ m_ref

template<class T_Obj >
ObjRef ObjPtr< T_Obj >::m_ref {}
private

a valid reference to an object stored in the container or an invalid reference.

Definition at line 667 of file ObjContainer.h.


The documentation for this class was generated from the following file:
ObjPtr::release
T_Obj * release()
Release the object this pointer points to from the container.
Definition: ObjContainer.h:610
ObjContainerBase::throwNoContainer
static void throwNoContainer()
Definition: ObjContainer.h:118
ObjPtr::ObjPtr
ObjPtr()=default
ObjContainer::registerObj
ObjRef registerObj(T_Obj &obj)
Manage an external object.
Definition: ObjContainer.h:247
ObjPtr::m_container
ObjContainer< T_Obj > * m_container
pointer to the conainer
Definition: ObjContainer.h:666
ObjPtr::shareAndSet
void shareAndSet(ObjRef ref)
Helper method to increase the share count of the referenced object and point to that object.
Definition: ObjContainer.h:635
ObjPtr::get
T_Obj * get()
Get a pointer to a valid manged object.
Definition: ObjContainer.h:588
ref
const boost::regex ref(r_ef)
python.PyAthena.obj
obj
Definition: PyAthena.py:132
ObjContainer::share
ObjRef share(ObjRef ref)
Increase the share count of a given object.
Definition: ObjContainer.h:262
ObjPtr::m_ref
ObjRef m_ref
a valid reference to an object stored in the container or an invalid reference.
Definition: ObjContainer.h:667
ObjPtr::index
ObjRef index() const
Get a light-weight reference to the object pointed to by this pointer The returned light-weight refer...
Definition: ObjContainer.h:629