Blender  V3.3
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
blender::CPPType Class Reference

#include <BLI_cpp_type.hh>

Inheritance diagram for blender::CPPType:
blender::NonCopyable blender::NonMovable blender::fn::FieldCPPType blender::fn::ValueOrFieldCPPType

Classes

struct  type_tag
 

Public Member Functions

template<typename T , CPPTypeFlags Flags>
 CPPType (CPPTypeParam< T, Flags >, StringRef debug_name)
 
virtual ~CPPType ()=default
 
StringRefNull name () const
 
int64_t size () const
 
int64_t alignment () const
 
bool is_trivially_destructible () const
 
bool is_trivial () const
 
bool is_default_constructible () const
 
bool is_copy_constructible () const
 
bool is_move_constructible () const
 
bool is_destructible () const
 
bool is_copy_assignable () const
 
bool is_move_assignable () const
 
bool is_printable () const
 
bool is_equality_comparable () const
 
bool is_hashable () const
 
bool has_special_member_functions () const
 
bool pointer_has_valid_alignment (const void *ptr) const
 
bool pointer_can_point_to_instance (const void *ptr) const
 
void default_construct (void *ptr) const
 
void default_construct_n (void *ptr, int64_t n) const
 
void default_construct_indices (void *ptr, IndexMask mask) const
 
void value_initialize (void *ptr) const
 
void value_initialize_n (void *ptr, int64_t n) const
 
void value_initialize_indices (void *ptr, IndexMask mask) const
 
void destruct (void *ptr) const
 
void destruct_n (void *ptr, int64_t n) const
 
void destruct_indices (void *ptr, IndexMask mask) const
 
void copy_assign (const void *src, void *dst) const
 
void copy_assign_n (const void *src, void *dst, int64_t n) const
 
void copy_assign_indices (const void *src, void *dst, IndexMask mask) const
 
void copy_assign_compressed (const void *src, void *dst, IndexMask mask) const
 
void copy_construct (const void *src, void *dst) const
 
void copy_construct_n (const void *src, void *dst, int64_t n) const
 
void copy_construct_indices (const void *src, void *dst, IndexMask mask) const
 
void copy_construct_compressed (const void *src, void *dst, IndexMask mask) const
 
void move_assign (void *src, void *dst) const
 
void move_assign_n (void *src, void *dst, int64_t n) const
 
void move_assign_indices (void *src, void *dst, IndexMask mask) const
 
void move_construct (void *src, void *dst) const
 
void move_construct_n (void *src, void *dst, int64_t n) const
 
void move_construct_indices (void *src, void *dst, IndexMask mask) const
 
void relocate_assign (void *src, void *dst) const
 
void relocate_assign_n (void *src, void *dst, int64_t n) const
 
void relocate_assign_indices (void *src, void *dst, IndexMask mask) const
 
void relocate_construct (void *src, void *dst) const
 
void relocate_construct_n (void *src, void *dst, int64_t n) const
 
void relocate_construct_indices (void *src, void *dst, IndexMask mask) const
 
void fill_assign_n (const void *value, void *dst, int64_t n) const
 
void fill_assign_indices (const void *value, void *dst, IndexMask mask) const
 
void fill_construct_n (const void *value, void *dst, int64_t n) const
 
void fill_construct_indices (const void *value, void *dst, IndexMask mask) const
 
bool can_exist_in_buffer (const int64_t buffer_size, const int64_t buffer_alignment) const
 
void print (const void *value, std::stringstream &ss) const
 
std::string to_string (const void *value) const
 
void print_or_default (const void *value, std::stringstream &ss, StringRef default_value) const
 
bool is_equal (const void *a, const void *b) const
 
bool is_equal_or_false (const void *a, const void *b) const
 
uint64_t hash (const void *value) const
 
uint64_t hash_or_fallback (const void *value, uint64_t fallback_hash) const
 
const voiddefault_value () const
 
uint64_t hash () const
 
template<typename T >
bool is () const
 
template<typename... Types, typename Fn >
void to_static_type (const Fn &fn) const
 
template<typename... Types, typename Fn >
void to_static_type_tag (const Fn &fn) const
 

Static Public Member Functions

template<typename T >
static const CPPTypeget ()
 
template<typename T >
static const CPPTypeget_impl ()
 

Public Attributes

void(*)(void *) destruct_fn () const
 

Friends

bool operator== (const CPPType &a, const CPPType &b)
 
bool operator!= (const CPPType &a, const CPPType &b)
 

Detailed Description

Definition at line 101 of file BLI_cpp_type.hh.

Constructor & Destructor Documentation

◆ CPPType()

template<typename T , CPPTypeFlags Flags>
blender::CPPType::CPPType ( CPPTypeParam< T, Flags >  ,
StringRef  debug_name 
)

Definition at line 209 of file BLI_cpp_type_make.hh.

References default_value(), EqualityComparable, Hashable, Printable, and T.

◆ ~CPPType()

virtual blender::CPPType::~CPPType ( )
virtualdefault

Member Function Documentation

◆ alignment()

int64_t blender::CPPType::alignment ( ) const
inline

◆ can_exist_in_buffer()

bool blender::CPPType::can_exist_in_buffer ( const int64_t  buffer_size,
const int64_t  buffer_alignment 
) const
inline

Definition at line 629 of file BLI_cpp_type.hh.

◆ copy_assign()

void blender::CPPType::copy_assign ( const void src,
void dst 
) const
inline

◆ copy_assign_compressed()

void blender::CPPType::copy_assign_compressed ( const void src,
void dst,
IndexMask  mask 
) const
inline

Similar to copy_assign_indices, but does not leave gaps in the #dst array.

Definition at line 418 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by blender::GVArrayImpl_For_GSpan::materialize_compressed().

◆ copy_assign_indices()

void blender::CPPType::copy_assign_indices ( const void src,
void dst,
IndexMask  mask 
) const
inline

◆ copy_assign_n()

void blender::CPPType::copy_assign_n ( const void src,
void dst,
int64_t  n 
) const
inline

◆ copy_construct()

void blender::CPPType::copy_construct ( const void src,
void dst 
) const
inline

◆ copy_construct_compressed()

void blender::CPPType::copy_construct_compressed ( const void src,
void dst,
IndexMask  mask 
) const
inline

Similar to copy_construct_indices, but does not leave gaps in the #dst array.

Definition at line 461 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by blender::GVArrayImpl_For_GSpan::materialize_compressed_to_uninitialized().

◆ copy_construct_indices()

void blender::CPPType::copy_construct_indices ( const void src,
void dst,
IndexMask  mask 
) const
inline

◆ copy_construct_n()

void blender::CPPType::copy_construct_n ( const void src,
void dst,
int64_t  n 
) const
inline

Definition at line 444 of file BLI_cpp_type.hh.

References copy_construct_indices().

Referenced by blender::tests::TEST().

◆ default_construct()

void blender::CPPType::default_construct ( void ptr) const
inline

Call the default constructor at the given memory location. The memory should be uninitialized before this method is called. For some trivial types (like int), this method does nothing.

C++ equivalent: new (ptr) T;

Definition at line 316 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and ptr.

Referenced by blender::modifiers::geometry_nodes::GeometryNodesEvaluator::convert_value(), blender::modifiers::geometry_nodes::GeometryNodesEvaluator::execute_multi_function_node__value(), blender::GVArrayCommon::get_internal_single_to_uninitialized(), blender::GVArray_For_GVVectorArrayIndex::get_to_uninitialized(), and blender::tests::TEST().

◆ default_construct_indices()

void blender::CPPType::default_construct_indices ( void ptr,
IndexMask  mask 
) const
inline

Definition at line 328 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and ptr.

Referenced by default_construct_n(), and blender::tests::TEST().

◆ default_construct_n()

void blender::CPPType::default_construct_n ( void ptr,
int64_t  n 
) const
inline

◆ default_value()

const void* blender::CPPType::default_value ( ) const
inline

Get a pointer to a constant value of this type. The specific value depends on the type. It is usually a zero-initialized or default constructed value.

Definition at line 690 of file BLI_cpp_type.hh.

Referenced by CPPType(), blender::GVArray::ForSingleDefault(), and print_or_default().

◆ destruct()

void blender::CPPType::destruct ( void ptr) const
inline

◆ destruct_indices()

void blender::CPPType::destruct_indices ( void ptr,
IndexMask  mask 
) const
inline

Definition at line 380 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and ptr.

Referenced by destruct_n(), and blender::tests::TEST().

◆ destruct_n()

void blender::CPPType::destruct_n ( void ptr,
int64_t  n 
) const
inline

◆ fill_assign_indices()

void blender::CPPType::fill_assign_indices ( const void value,
void dst,
IndexMask  mask 
) const
inline

◆ fill_assign_n()

void blender::CPPType::fill_assign_n ( const void value,
void dst,
int64_t  n 
) const
inline

Copy the given value to the first n elements in an array starting at dst.

Other instances of the same type should live in the array before this method is called.

Definition at line 598 of file BLI_cpp_type.hh.

References fill_assign_indices().

Referenced by blender::GVMutableArray::fill(), blender::GVArrayImpl_For_SingleValueRef::materialize_compressed(), and blender::tests::TEST().

◆ fill_construct_indices()

void blender::CPPType::fill_construct_indices ( const void value,
void dst,
IndexMask  mask 
) const
inline

◆ fill_construct_n()

void blender::CPPType::fill_construct_n ( const void value,
void dst,
int64_t  n 
) const
inline

Copy the given value to the first n elements in an array starting at dst.

The array should be uninitialized before this method is called.

Definition at line 616 of file BLI_cpp_type.hh.

References fill_construct_indices().

Referenced by blender::GVArrayImpl_For_SingleValueRef::materialize_compressed_to_uninitialized(), and blender::tests::TEST().

◆ get()

template<typename T >
static const CPPType& blender::CPPType::get ( )
inlinestatic

Get the CPPType that corresponds to a specific static type. This only works for types that actually implement the template specialization using BLI_CPP_TYPE_MAKE.

Definition at line 173 of file BLI_cpp_type.hh.

References type.

◆ get_impl()

template<typename T >
static const CPPType& blender::CPPType::get_impl ( )
static

◆ has_special_member_functions()

bool blender::CPPType::has_special_member_functions ( ) const
inline

Returns true, when the type has the following functions:

  • Default constructor.
  • Copy constructor.
  • Move constructor.
  • Copy assignment operator.
  • Move assignment operator.
  • Destructor.

Definition at line 290 of file BLI_cpp_type.hh.

◆ hash() [1/2]

uint64_t blender::CPPType::hash ( ) const
inline

Definition at line 695 of file BLI_cpp_type.hh.

References blender::get_default_hash().

Referenced by hash_or_fallback().

◆ hash() [2/2]

uint64_t blender::CPPType::hash ( const void value) const
inline

Definition at line 672 of file BLI_cpp_type.hh.

References BLI_assert, and pointer_can_point_to_instance().

◆ hash_or_fallback()

uint64_t blender::CPPType::hash_or_fallback ( const void value,
uint64_t  fallback_hash 
) const
inline

Definition at line 678 of file BLI_cpp_type.hh.

References hash(), and is_hashable().

Referenced by blender::fn::CustomMF_GenericConstant::hash().

◆ is()

template<typename T >
bool blender::CPPType::is ( ) const
inline

◆ is_copy_assignable()

bool blender::CPPType::is_copy_assignable ( ) const
inline

Definition at line 256 of file BLI_cpp_type.hh.

◆ is_copy_constructible()

bool blender::CPPType::is_copy_constructible ( ) const
inline

Definition at line 241 of file BLI_cpp_type.hh.

◆ is_default_constructible()

bool blender::CPPType::is_default_constructible ( ) const
inline

Definition at line 236 of file BLI_cpp_type.hh.

◆ is_destructible()

bool blender::CPPType::is_destructible ( ) const
inline

Definition at line 251 of file BLI_cpp_type.hh.

◆ is_equal()

bool blender::CPPType::is_equal ( const void a,
const void b 
) const
inline

◆ is_equal_or_false()

bool blender::CPPType::is_equal_or_false ( const void a,
const void b 
) const
inline

Definition at line 664 of file BLI_cpp_type.hh.

References usdtokens::b(), is_equal(), and is_equality_comparable().

◆ is_equality_comparable()

bool blender::CPPType::is_equality_comparable ( ) const
inline

Definition at line 271 of file BLI_cpp_type.hh.

Referenced by is_equal_or_false().

◆ is_hashable()

bool blender::CPPType::is_hashable ( ) const
inline

Definition at line 276 of file BLI_cpp_type.hh.

Referenced by hash_or_fallback().

◆ is_move_assignable()

bool blender::CPPType::is_move_assignable ( ) const
inline

Definition at line 261 of file BLI_cpp_type.hh.

◆ is_move_constructible()

bool blender::CPPType::is_move_constructible ( ) const
inline

Definition at line 246 of file BLI_cpp_type.hh.

◆ is_printable()

bool blender::CPPType::is_printable ( ) const
inline

Definition at line 266 of file BLI_cpp_type.hh.

Referenced by print_or_default().

◆ is_trivial()

bool blender::CPPType::is_trivial ( ) const
inline

When true, the value is like a normal C type, it can be copied around with #memcpy and does not have to be destructed.

C++ equivalent: std::is_trivial_v<T>;

Definition at line 231 of file BLI_cpp_type.hh.

Referenced by blender::GVArray::GVArray(), and blender::GVArrayImpl_For_SmallTrivialSingleValue< BufferSize >::GVArrayImpl_For_SmallTrivialSingleValue().

◆ is_trivially_destructible()

bool blender::CPPType::is_trivially_destructible ( ) const
inline

When true, the destructor does not have to be called on this type. This can sometimes be used for optimization purposes.

C++ equivalent: std::is_trivially_destructible_v<T>;

Definition at line 219 of file BLI_cpp_type.hh.

Referenced by blender::GVectorArray::~GVectorArray().

◆ move_assign()

void blender::CPPType::move_assign ( void src,
void dst 
) const
inline

Move an instance of this type from src to dst.

The memory pointed to by dst should be initialized.

C++ equivalent: dst = std::move(src);

Definition at line 478 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and src.

◆ move_assign_indices()

void blender::CPPType::move_assign_indices ( void src,
void dst,
IndexMask  mask 
) const
inline

Definition at line 491 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by move_assign_n().

◆ move_assign_n()

void blender::CPPType::move_assign_n ( void src,
void dst,
int64_t  n 
) const
inline

Definition at line 486 of file BLI_cpp_type.hh.

References move_assign_indices().

◆ move_construct()

void blender::CPPType::move_construct ( void src,
void dst 
) const
inline

Move an instance of this type from src to dst.

The memory pointed to by dst should be uninitialized.

C++ equivalent: new (dst) T(std::move(src));

Definition at line 508 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and src.

Referenced by blender::GVArrayImpl_For_GSpan::set_by_move().

◆ move_construct_indices()

void blender::CPPType::move_construct_indices ( void src,
void dst,
IndexMask  mask 
) const
inline

Definition at line 522 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by move_construct_n().

◆ move_construct_n()

void blender::CPPType::move_construct_n ( void src,
void dst,
int64_t  n 
) const
inline

Definition at line 517 of file BLI_cpp_type.hh.

References move_construct_indices().

◆ name()

StringRefNull blender::CPPType::name ( ) const
inline

Returns the name of the type for debugging purposes. This name should not be used as identifier.

Definition at line 185 of file BLI_cpp_type.hh.

Referenced by blender::bke::add_implicit_conversion(), and blender::fn::MFDataType::to_string().

◆ pointer_can_point_to_instance()

bool blender::CPPType::pointer_can_point_to_instance ( const void ptr) const
inline

◆ pointer_has_valid_alignment()

bool blender::CPPType::pointer_has_valid_alignment ( const void ptr) const
inline

Returns true, when the given pointer fulfills the alignment requirement of this type.

Definition at line 298 of file BLI_cpp_type.hh.

References ptr.

Referenced by blender::GMutableSpan::GMutableSpan(), blender::GSpan::GSpan(), and pointer_can_point_to_instance().

◆ print()

void blender::CPPType::print ( const void value,
std::stringstream &  ss 
) const
inline

Definition at line 634 of file BLI_cpp_type.hh.

References BLI_assert, and pointer_can_point_to_instance().

Referenced by print_or_default(), and to_string().

◆ print_or_default()

void blender::CPPType::print_or_default ( const void value,
std::stringstream &  ss,
StringRef  default_value 
) const
inline

Definition at line 647 of file BLI_cpp_type.hh.

References default_value(), is_printable(), and print().

◆ relocate_assign()

void blender::CPPType::relocate_assign ( void src,
void dst 
) const
inline

Relocates an instance of this type from src to dst. src will point to uninitialized memory afterwards.

C++ equivalent: dst = std::move(src); src->~T();

Definition at line 539 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and src.

Referenced by blender::GMutablePointer::relocate_out(), blender::GVArrayImpl_For_GSpan::set_by_relocate(), and blender::tests::TEST().

◆ relocate_assign_indices()

void blender::CPPType::relocate_assign_indices ( void src,
void dst,
IndexMask  mask 
) const
inline

Definition at line 553 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by relocate_assign_n(), and blender::tests::TEST().

◆ relocate_assign_n()

void blender::CPPType::relocate_assign_n ( void src,
void dst,
int64_t  n 
) const
inline

Definition at line 548 of file BLI_cpp_type.hh.

References relocate_assign_indices().

Referenced by blender::tests::TEST().

◆ relocate_construct()

void blender::CPPType::relocate_construct ( void src,
void dst 
) const
inline

Relocates an instance of this type from src to dst. src will point to uninitialized memory afterwards.

C++ equivalent: new (dst) T(std::move(src)) src->~T();

Definition at line 570 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and src.

Referenced by blender::tests::TEST().

◆ relocate_construct_indices()

void blender::CPPType::relocate_construct_indices ( void src,
void dst,
IndexMask  mask 
) const
inline

Definition at line 584 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and src.

Referenced by relocate_construct_n(), and blender::tests::TEST().

◆ relocate_construct_n()

void blender::CPPType::relocate_construct_n ( void src,
void dst,
int64_t  n 
) const
inline

Definition at line 579 of file BLI_cpp_type.hh.

References relocate_construct_indices().

Referenced by blender::tests::TEST().

◆ size()

int64_t blender::CPPType::size ( ) const
inline

Required memory in bytes for an instance of this type.

C++ equivalent: sizeof(T);

Definition at line 196 of file BLI_cpp_type.hh.

Referenced by blender::GVArrayImpl_For_SlicedGVArray::common_info(), compute_geometry(), ED_geometry_attribute_convert(), blender::modifiers::geometry_nodes::GeometryNodesEvaluator::execute_multi_function_node__field(), blender::modifiers::geometry_nodes::GeometryNodesEvaluator::execute_multi_function_node__value(), blender::fn::FieldConstant::FieldConstant(), blender::modifiers::geometry_nodes::GeometryNodesEvaluator::forward_output(), blender::ed::geometry::geometry_attribute_convert_exec(), blender::GVMutableArray::get_internal_span(), blender::modifiers::geometry_nodes::GeometryNodesEvaluator::get_value_from_socket(), blender::GMutableVArraySpan::GMutableVArraySpan(), blender::GVArray::GVArray(), blender::GVArrayImpl_For_SingleValue::GVArrayImpl_For_SingleValue(), blender::GVArrayImpl_For_SmallTrivialSingleValue< BufferSize >::GVArrayImpl_For_SmallTrivialSingleValue(), blender::GVArraySpan::GVArraySpan(), blender::nodes::geometry_nodes_eval_log::LocalGeoLogger::log_value_for_sockets(), blender::GVArrayImpl::materialize(), blender::GVArrayImpl::materialize_compressed(), blender::GVArrayImpl::materialize_compressed_to_uninitialized(), blender::GVArrayImpl::materialize_to_uninitialized(), blender::GArray< Allocator >::operator[](), blender::GSpan::operator[](), blender::GMutableSpan::operator[](), blender::GVMutableArrayImpl::set_all(), blender::GSpan::slice(), blender::GMutableSpan::slice(), and blender::tests::TEST().

◆ to_static_type()

template<typename... Types, typename Fn >
void blender::CPPType::to_static_type ( const Fn &  fn) const
inline

Convert a CPPType that is only known at run-time, to a static type that is known at compile-time. This allows the compiler to optimize a function for specific types, while all other types can still use a generic fallback function.

Parameters
TypesThe types that code should be generated for.
fnThe function object to call. This is expected to have a templated operator() and a non-templated operator(). The templated version will be called if the current CPPType matches any of the given types. Otherwise, the non-templated function is called.

Definition at line 720 of file BLI_cpp_type.hh.

References blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add_new(), callback, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_default(), and void.

Referenced by to_static_type_tag().

◆ to_static_type_tag()

template<typename... Types, typename Fn >
void blender::CPPType::to_static_type_tag ( const Fn &  fn) const
inline

Similar to to_static_type but is easier to use with a lambda function. The function is expected to take a single auto type_tag parameter. To extract the static type, use: using T = typename decltype(type_tag)type;

If the current CPPType is not in #Types, the type tag is void.

Definition at line 775 of file BLI_cpp_type.hh.

References to_static_type().

Referenced by blender::attribute_math::convert_to_static_type().

◆ to_string()

std::string blender::CPPType::to_string ( const void value) const
inline

Definition at line 640 of file BLI_cpp_type.hh.

References print().

◆ value_initialize()

void blender::CPPType::value_initialize ( void ptr) const
inline

Same as default_construct, but does zero initialization for trivial types.

C++ equivalent: new (ptr) T();

Definition at line 341 of file BLI_cpp_type.hh.

References BLI_assert, pointer_can_point_to_instance(), and ptr.

Referenced by blender::tests::TEST().

◆ value_initialize_indices()

void blender::CPPType::value_initialize_indices ( void ptr,
IndexMask  mask 
) const
inline

Definition at line 353 of file BLI_cpp_type.hh.

References BLI_assert, mask(), and ptr.

Referenced by blender::tests::TEST(), and value_initialize_n().

◆ value_initialize_n()

void blender::CPPType::value_initialize_n ( void ptr,
int64_t  n 
) const
inline

Definition at line 348 of file BLI_cpp_type.hh.

References value_initialize_indices().

Referenced by blender::tests::TEST().

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CPPType a,
const CPPType b 
)
friend

Definition at line 163 of file BLI_cpp_type.hh.

◆ operator==

bool operator== ( const CPPType a,
const CPPType b 
)
friend

Two types only compare equal when their pointer is equal. No two instances of CPPType for the same C++ type should be created.

Definition at line 158 of file BLI_cpp_type.hh.

Member Data Documentation

◆ destruct_fn

void(*)(void *) blender::CPPType::destruct_fn() const
inline

Definition at line 700 of file BLI_cpp_type.hh.


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