Fundamental Types

From K-3D

Jump to: navigation, search

Overview

Until recently, K-3D resisted the tendency towards defining a lot of application-specific types, preferring to use C++ builtin types (bool, int, long, double) wherever possible and defining custom types (k3d::point3, k3d::matrix4, k3d::ustring) where required. Unfortunately, this led to some subtle problems on different platforms and looked likely to cause larger issues in the future.

Types

K-3D provides a collection of fundamental types that meet the following attributes:

  • The size of each type is consistent across all platforms. Rationale: Consistent behavior across all platforms.
    • Caveat: bool isn't the same size on all platforms, but it is a distinct type, so we can use it for overloaded functions / specializations.
    • Caveat: Our mesh based arrays make heavy use of array indices and counts. The underlying arrays are based on std::vector. std::vector::size_type is implementation dependent (32/64 bits depending on the platform), so we provide an integer type k3d::uint_t that is 32/64 bits respectively.
  • Every fundamental type is unique - i.e. no two fundamental types are aliases for the same underlying type. Rationale: This eliminates problems with function overloading and template specialization. It also ensures that every fundamental type can be mapped to a unique string representation and back for serialization.
    • Caveat: This is not true for k3d::uint_t. However, we can at least guarantee that k3d::uint_t will always be an alias for k3d::uint32_t or k3d::uint64_t depending on the platform, making overloading / specialization well-defined.

Following is a list of the fundamental K-3D types as defined in k3dsdk/types.h, along with their underlying properties on different platforms:

GNU/Linux/IA32

type                          actual type              size
----                          -----------              ----
k3d::bool_t                   bool                     1
k3d::half_t                   half                     2
k3d::float_t                  float                    4
k3d::double_t                 double                   8
----                          -----------              ----
k3d::int8_t                   signed char              1
k3d::int16_t                  short                    2
k3d::int32_t                  int                      4
k3d::int64_t                  long long                8
k3d::uint8_t                  unsigned char            1
k3d::uint16_t                 unsigned short           2
k3d::uint32_t                 unsigned int             4
k3d::uint64_t                 unsigned long long       8
----                          -----------              ----
k3d::uint_t                   unsigned int             4

MacOSX/PPC

Note: Unlike the other platforms, bool is four bytes instead of one. This is of only academic concern, since code that works with bool is required to ignore underlying storage size regardless. Although bool is larger than we'd like, the important thing is that it is still a unique type.

type                          actual type              size
----                          -----------              ----
k3d::bool_t                   bool                     4
k3d::half_t                   half                     2
k3d::float_t                  float                    4
k3d::double_t                 double                   8
----                          -----------              ----
k3d::int8_t                   signed char              1
k3d::int16_t                  short                    2
k3d::int32_t                  int                      4
k3d::int64_t                  long long                8
k3d::uint8_t                  unsigned char            1
k3d::uint16_t                 unsigned short           2
k3d::uint32_t                 unsigned int             4
k3d::uint64_t                 unsigned long long       8
----                          -----------              ----
k3d::uint_t                   unsigned int             4

Win32/IA32/MinGW

Note: internal type names are displayed mangled because runtime demangling is not supported on this platform. However, all of the types are still unique, which is the main requirement.

type                          actual type              size
----                          -----------              ----
k3d::bool_t                   b                        1
k3d::half_t                   half                     2
k3d::float_t                  f                        4
k3d::double_t                 d                        8
----                          -----------              ----
k3d::int8_t                   a                        1
k3d::int16_t                  s                        2
k3d::int32_t                  i                        4
k3d::int64_t                  x                        8
k3d::uint8_t                  h                        1
k3d::uint16_t                 t                        2
k3d::uint32_t                 j                        4
k3d::uint64_t                 y                        8
----                          -----------              ----
k3d::uint_t                   j                        4
Personal tools