Ginkgo: gko::PolymorphicObject Class Reference

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
gko::PolymorphicObject Class Referenceabstract

A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphically. More...

`#include <ginkgo/core/base/polymorphic_object.hpp>`

Inheritance diagram for gko::PolymorphicObject:
[legend]
Collaboration diagram for gko::PolymorphicObject:
[legend]

## Public Member Functions
PolymorphicObject & | operator= (const PolymorphicObject &)
std::unique_ptr< PolymorphicObject > | create_default (std::shared_ptr< const Executor > exec) const
| Creates a new "default" object of the same dynamic type as this object.
std::unique_ptr< PolymorphicObject > | create_default () const
| Creates a new "default" object of the same dynamic type as this object.
std::unique_ptr< PolymorphicObject > | clone (std::shared_ptr< const Executor > exec) const
| Creates a clone of the object.
std::unique_ptr< PolymorphicObject > | clone () const
| Creates a clone of the object.
PolymorphicObject * | copy_from (const PolymorphicObject *other)
| Copies another object into this object.
template<typename Derived, typename Deleter>
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * | copy_from (std::unique_ptr< Derived, Deleter > &&other)
| Moves another object into this object.
template<typename Derived, typename Deleter>
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * | copy_from (const std::unique_ptr< Derived, Deleter > &other)
| Copies another object into this object.
PolymorphicObject * | copy_from (const std::shared_ptr< const PolymorphicObject > &other)
| Copies another object into this object.
PolymorphicObject * | move_from (ptr_param< PolymorphicObject > other)
| Moves another object into this object.
PolymorphicObject * | clear ()
| Transforms the object into its default state.
std::shared_ptr< const Executor > | get_executor () const noexcept
| Returns the Executor of the object.
Public Member Functions inherited from gko::log::EnableLogging< PolymorphicObject >
void | add_logger (std::shared_ptr< const Logger > logger) override
| Adds a new logger to the list of subscribed loggers.
void | remove_logger (const Logger *logger) override
| Removes a logger from the list of subscribed loggers.
const std::vector< std::shared_ptr< const Logger > > & | get_loggers () const override
| Returns the vector containing all loggers registered at this object.
void | clear_loggers () override
| Remove all loggers registered at this object.
Public Member Functions inherited from gko::log::Loggable
void | remove_logger (ptr_param< const Logger > logger)

## Detailed Description

A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphically.

It defines the basic utilities (copying moving, cloning, clearing the objects) for all such objects. It takes into account that these objects are dynamically allocated, managed by smart pointers, and used polymorphically. Additionally, it assumes their data can be allocated on different executors, and that they can be copied between those executors.

Note
  Most of the public methods of this class should not be overridden directly, and are thus not virtual. Instead, there are equivalent protected methods (ending in <method_name>_impl) that should be overridden instead. This allows polymorphic objects to implement default behavior around virtual methods (parameter checking, type casting).

See also
  EnablePolymorphicObject if you wish to implement a concrete polymorphic object and have sensible defaults generated automatically. EnableAbstractPolymorphicObject if you wish to implement a new abstract polymorphic object, and have the return types of the methods updated to your type (instead of having them return PolymorphicObject).

## Member Function Documentation

## ◆ clear()

PolymorphicObject * gko::PolymorphicObject::clear | ( |  | ) |
| inline

Transforms the object into its default state.

Equivalent to this->copy_from(this->create_default()).

See also
  clear_impl() when implementing this method

Returns
  this

## ◆ clone() [1/2]

std::unique_ptr< PolymorphicObject > gko::PolymorphicObject::clone | ( |  | ) | const
| inline

Creates a clone of the object.

This is a shorthand for clone(std::shared_ptr<const Executor>) that uses the executor of this object to construct the new object.

Returns
  A clone of the LinOp.

References clone().

Referenced by clone().

## ◆ clone() [2/2]

std::unique_ptr< PolymorphicObject > gko::PolymorphicObject::clone | ( | std::shared_ptr< const Executor > | exec | ) | const
| inline

Creates a clone of the object.

This is the polymorphic equivalent of the executor copy constructor decltype(*this)(exec, this).

Parameters

  exec | the executor where the clone will be created

Returns
  A clone of the LinOp.

References create_default().

## ◆ copy_from() [1/4]

PolymorphicObject * gko::PolymorphicObject::copy_from | ( | const PolymorphicObject * | other | ) |
| inline

Copies another object into this object.

This is the polymorphic equivalent of the copy assignment operator.

See also
  copy_from_impl(const PolymorphicObject *)

Parameters

  other | the object to copy

Returns
  this

Referenced by copy_from(), copy_from(), and copy_from().

## ◆ copy_from() [2/4]

PolymorphicObject * gko::PolymorphicObject::copy_from | ( | const std::shared_ptr< const PolymorphicObject > & | other | ) |
| inline

Copies another object into this object.

This is the polymorphic equivalent of the copy assignment operator.

See also
  copy_from_impl(const PolymorphicObject *)

Parameters

  other | the object to copy

Returns
  this

References copy_from().

## ◆ copy_from() [3/4]

template<typename Derived, typename Deleter>

std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * gko::PolymorphicObject::copy_from | ( | const std::unique_ptr< Derived, Deleter > & | other | ) |
| inline

Copies another object into this object.

This is the polymorphic equivalent of the copy assignment operator.

See also
  copy_from_impl(const PolymorphicObject *)

Parameters

  other | the object to copy

Returns
  this

Template Parameters

  Derived | the actual pointee type of the parameter, it needs to be derived from PolymorphicObject.
  Deleter | the deleter of the unique_ptr parameter

References copy_from().

## ◆ copy_from() [4/4]

template<typename Derived, typename Deleter>

std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * gko::PolymorphicObject::copy_from | ( | std::unique_ptr< Derived, Deleter > && | other | ) |
| inline

Moves another object into this object.

This is the polymorphic equivalent of the move assignment operator.

See also
  copy_from_impl(std::unique_ptr<PolymorphicObject>)

Parameters

  other | the object to move from

Returns
  this

Template Parameters

  Derived | the actual pointee type of the parameter, it needs to be derived from PolymorphicObject.
  Deleter | the deleter of the unique_ptr parameter

References copy_from().

## ◆ create_default() [1/2]

std::unique_ptr< PolymorphicObject > gko::PolymorphicObject::create_default | ( |  | ) | const
| inline

Creates a new "default" object of the same dynamic type as this object.

This is a shorthand for create_default(std::shared_ptr<const Executor>) that uses the executor of this object to construct the new object.

Returns
  a polymorphic object of the same type as this

References create_default().

Referenced by clone(), and create_default().

## ◆ create_default() [2/2]

std::unique_ptr< PolymorphicObject > gko::PolymorphicObject::create_default | ( | std::shared_ptr< const Executor > | exec | ) | const
| inline

Creates a new "default" object of the same dynamic type as this object.

This is the polymorphic equivalent of the executor default constructor decltype(*this)(exec);.

Parameters

  exec | the executor where the object will be created

Returns
  a polymorphic object of the same type as this

## ◆ get_executor()

std::shared_ptr< const Executor > gko::PolymorphicObject::get_executor | ( |  | ) | const
| inlinenoexcept

Returns the Executor of the object.

Returns
  Executor of the object

## ◆ move_from()

PolymorphicObject * gko::PolymorphicObject::move_from | ( | ptr_param< PolymorphicObject > | other | ) |
| inline

Moves another object into this object.

This is the polymorphic equivalent of the move assignment operator.

See also
  move_from_impl(PolymorphicObject *)

Parameters

  other | the object to move from

Returns
  this

References gko::ptr_param< T >::get().

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

- ginkgo/core/base/polymorphic_object.hpp