v0.9.1
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
Examples
basic_plastic.cpp.

Definition at line 128 of file AuxPETSc.hpp.

Constructor & Destructor Documentation

◆ SmartPetscObj() [1/2]

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

◆ SmartPetscObj() [2/2]

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

Definition at line 133 of file AuxPETSc.hpp.

Member Function Documentation

◆ operator OBJ()

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

Definition at line 137 of file AuxPETSc.hpp.

137 { return this->get(); }

◆ operator PetscObject()

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

Definition at line 138 of file AuxPETSc.hpp.

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

◆ use_count()

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

Definition at line 142 of file AuxPETSc.hpp.

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

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