v0.9.0
Public Member Functions | List of all members
MoFEM::SmartPetscObj< OBJ > Struct Template Reference

intrusive_ptr for managing petsc objects More...

#include <src/petsc/AuxPETSc.hpp>

Inherits intrusive_ptr< std::remove_pointer< OBJ >::type >.

Public Member Functions

 SmartPetscObj ()
 
 SmartPetscObj (OBJ o, bool add_ref=false)
 
 operator OBJ ()
 
 operator PetscObject ()
 
int use_count () const
 

Detailed Description

template<typename OBJ>
struct MoFEM::SmartPetscObj< OBJ >

intrusive_ptr for managing petsc objects

It manages destruction, referencing and dereferencing petsc objects. It is similar how smart_ptr pointers works, but applied for petsc objects like Vec, DM, Mat, etc.

SmartPetscObj<Vec> smart_vec = createSmartGhostVector(...);
Template Parameters
OBJ

Definition at line 128 of file AuxPETSc.hpp.

Constructor & Destructor Documentation

◆ SmartPetscObj() [1/2]

template<typename OBJ>
MoFEM::SmartPetscObj< OBJ >::SmartPetscObj ( )

Definition at line 131 of file AuxPETSc.hpp.

132  : boost::intrusive_ptr<typename std::remove_pointer<OBJ>::type>() {}

◆ SmartPetscObj() [2/2]

template<typename OBJ>
MoFEM::SmartPetscObj< OBJ >::SmartPetscObj ( OBJ  o,
bool  add_ref = false 
)

Definition at line 133 of file AuxPETSc.hpp.

134  : boost::intrusive_ptr<typename std::remove_pointer<OBJ>::type>(o,
135  add_ref) {}

Member Function Documentation

◆ operator OBJ()

template<typename OBJ>
MoFEM::SmartPetscObj< OBJ >::operator OBJ ( )

Definition at line 136 of file AuxPETSc.hpp.

136 { return this->get(); }

◆ operator PetscObject()

template<typename OBJ>
MoFEM::SmartPetscObj< OBJ >::operator PetscObject ( )
explicit

Definition at line 137 of file AuxPETSc.hpp.

137  {
138  return reinterpret_cast<PetscObject>(this->get());
139  }

◆ use_count()

template<typename OBJ>
int MoFEM::SmartPetscObj< OBJ >::use_count ( ) const

Definition at line 141 of file AuxPETSc.hpp.

141  {
142  if (this->get()) {
143  int cnt;
144  ierr = PetscObjectGetReference(getPetscObject(this->get()), &cnt);
145  CHKERRABORT(PetscObjectComm(getPetscObject(this->get())), ierr);
146  return cnt;
147  } else
148  return 0;
149  }
PetscObject getPetscObject(T obj)
Definition: AuxPETSc.hpp:23

The documentation for this struct was generated from the following file: