Page MenuHome

BLI: Move CPPType to blenlib.
ClosedPublic

Authored by Jacques Lucke (JacquesLucke) on Mar 17 2022, 10:45 AM.

Details

Summary

The CPPType class allows writing generic algorithms and data structures. In that way they are similar to c++ templates. The difference is that the type used by templated algorithms and data structures has to be known at compile time. Using CPPType allows writing code that only knows that exact underlying data type at run-time. For more details see the comment in BLI_cpp_type.hh.

CPPType is already the basis for various algorithms and data structures in the functions module. Those are used extensively by geometry nodes but can be useful in more contexts.

We already have other run-time type systems in Blender. Most notably, there is CustomDataType. In its current state, CustomDataType state is not suitable as a generic run-time type system (it was never designed to be one), because it mixes data type and other semantic information about the data. It also does not support arbitrary C++ types (which have life-time semantics) and is centralized (there is a centralized list with all the types).

Given that CPPType is very foundational for generic data structures, I'd like to move it to blenlib. It only depends on blenlib anyway. As a follow up commit, I want to move the generic data structures that exist already to blenlib as well. In most cases, those are the generic version of types that exist in blenlib already. The types to move are GArray, GPointer, GSpan and GVArray (as well as their mutable variants).

Diff Detail

Repository
rB Blender

Event Timeline

Jacques Lucke (JacquesLucke) requested review of this revision.Mar 17 2022, 10:45 AM
Jacques Lucke (JacquesLucke) created this revision.

Mostly want to know if there are any concerns with moving this to blenlib. The actual code changes are quite small.

I don't see why not.

This revision is now accepted and ready to land.Mar 17 2022, 1:34 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/blenlib/BLI_cpp_type.hh
40

as example -> as an example

source/blender/functions/intern/cpp_types.cc
10โ€“17

What's the reason to move this chunk out of the blender namespace too?

Campbell Barton (campbellbarton) added inline comments.
source/blender/blenlib/BLI_cpp_type_make.hh
244โ€“245

Since these aren't in a namespace, I'd prefer a more unique prefix CPP_TYPE_MAKE or BLI_CPP_TYPE_MAKEidentifiers (complete more usefully if others are added).

This revision was automatically updated to reflect the committed changes.