Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
caffe2::Blob Class Referencefinal

Blob is a general container that hosts a typed pointer. More...

#include <blob.h>

Inheritance diagram for caffe2::Blob:
c10::intrusive_ptr_target

Public Member Functions

 Blob () noexcept
 Initializes an empty Blob.
 
 Blob (Blob &&other) noexcept
 
Bloboperator= (Blob &&other) noexcept
 
template<class T >
bool IsType () const noexcept
 Checks if the content stored in the blob is of type T.
 
const TypeMetameta () const noexcept
 Returns the meta info of the blob.
 
const char * TypeName () const noexcept
 Returns a printable typename of the blob.
 
template<class T >
const TGet () const
 Gets the const reference of the stored object. More...
 
const void * GetRaw () const noexcept
 
void * GetRaw () noexcept
 
template<class T >
TGetMutable ()
 Gets a mutable pointer to the stored object. More...
 
template<class T >
TGetMutableOrNull ()
 
template<class T >
TReset (T *allocated)
 Sets the underlying object to the allocated one. More...
 
template<class T >
std::remove_const< T >::type * ShareExternal (typename std::remove_const< T >::type *allocated)
 Sets the underlying object to the allocated one, but does not take over the ownership of the passed in pointer. More...
 
void * ShareExternal (void *allocated, const TypeMeta &meta)
 
void Reset ()
 Resets the Blob to an empty one.
 
void swap (Blob &rhs)
 Swaps the underlying storage of two blobs.
 

Additional Inherited Members

- Protected Member Functions inherited from c10::intrusive_ptr_target
 intrusive_ptr_target (intrusive_ptr_target &&other) noexcept
 
intrusive_ptr_targetoperator= (intrusive_ptr_target &&other) noexcept
 
 intrusive_ptr_target (const intrusive_ptr_target &other) noexcept
 
intrusive_ptr_targetoperator= (const intrusive_ptr_target &other) noexcept
 

Detailed Description

Blob is a general container that hosts a typed pointer.

A Blob hosts a pointer as well as its type, and takes charge of deleting it properly when the blob is deallocated or re-allocated with a new type. A blob could contain anything, although the most common case is to contain a Tensor.

Definition at line 24 of file blob.h.

Member Function Documentation

template<class T >
const T& caffe2::Blob::Get ( ) const
inline

Gets the const reference of the stored object.

The code checks if the stored object is of the desired type.

Definition at line 71 of file blob.h.

template<class T >
T* caffe2::Blob::GetMutable ( )
inline

Gets a mutable pointer to the stored object.

If the current object is not of the right type, a new object is created and the old object is freed. Note that type T should have a default constructor. Otherwise, create the object yourself first, and use Reset().

Definition at line 100 of file blob.h.

template<class T >
T* caffe2::Blob::Reset ( T allocated)
inline

Sets the underlying object to the allocated one.

The Blob then takes over the ownership of the passed in pointer. If there is already an object in the Blob, the old object is freed.

This is used when the underlying class T does not have a default ctor, or complex initializations needs to be done outside the blob.

Definition at line 132 of file blob.h.

template<class T >
std::remove_const<T>::type* caffe2::Blob::ShareExternal ( typename std::remove_const< T >::type *  allocated)
inline

Sets the underlying object to the allocated one, but does not take over the ownership of the passed in pointer.

If there is already an object in the Blob, the old object is freed.

Unlike Reset, this does not take over the ownership of the pointer and the caller is responsible for making sure that the lifetime of the allocated blob outlasts the lifetime of any access to this blob, until another Reset call is made or the blob is destructed.

Definition at line 151 of file blob.h.


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