1// Copyright (c) Lawrence Livermore National Security, LLC and other Conduit 2// Project developers. See top-level LICENSE AND COPYRIGHT files for dates and 3// other details. No copyright assignment is required to contribute to Conduit. 4 5//----------------------------------------------------------------------------- 6/// 7/// file: conduit_bitwidth_style_types.h 8/// 9//----------------------------------------------------------------------------- 10 11#ifndef CONDUIT_BITWIDTH_STYLE_TYPES_H 12#define CONDUIT_BITWIDTH_STYLE_TYPES_H 13 14#include "conduit_config.h" 15#include <limits.h> 16 17//----------------------------------------------------------------------------- 18// byte len of native types 19//----------------------------------------------------------------------------- 20 21#define CONDUIT_SIZEOF_BYTE 1 22 23#cmakedefine CONDUIT_SIZEOF_CHAR @CONDUIT_SIZEOF_CHAR@ 24#cmakedefine CONDUIT_SIZEOF_SHORT @CONDUIT_SIZEOF_SHORT@ 25#cmakedefine CONDUIT_SIZEOF_INT @CONDUIT_SIZEOF_INT@ 26#cmakedefine CONDUIT_SIZEOF_LONG @CONDUIT_SIZEOF_LONG@ 27#cmakedefine CONDUIT_SIZEOF_LONG_LONG @CONDUIT_SIZEOF_LONG_LONG@ 28 29#cmakedefine CONDUIT_SIZEOF_FLOAT @CONDUIT_SIZEOF_FLOAT@ 30#cmakedefine CONDUIT_SIZEOF_DOUBLE @CONDUIT_SIZEOF_DOUBLE@ 31#cmakedefine CONDUIT_SIZEOF_LONG_DOUBLE @CONDUIT_SIZEOF_LONG_DOUBLE@ 32 33#cmakedefine CONDUIT_SIZEOF_VOID_P @CONDUIT_SIZEOF_VOID_P@ 34 35// defines that let us know if the compiler supports long long and long double 36#cmakedefine CONDUIT_HAS_LONG_LONG @CONDUIT_HAS_LONG_LONG@ 37#cmakedefine CONDUIT_HAS_LONG_DOUBLE @CONDUIT_HAS_LONG_DOUBLE@ 38 39 40// defines that let us know which types are used to support for our menu of 41// bit-width style types 42#cmakedefine CONDUIT_USE_CHAR @CONDUIT_USE_CHAR@ 43#cmakedefine CONDUIT_USE_SHORT @CONDUIT_USE_SHORT@ 44#cmakedefine CONDUIT_USE_INT @CONDUIT_USE_INT@ 45#cmakedefine CONDUIT_USE_LONG @CONDUIT_USE_LONG@ 46 47#cmakedefine CONDUIT_USE_FLOAT @CONDUIT_USE_FLOAT@ 48#cmakedefine CONDUIT_USE_DOUBLE @CONDUIT_USE_DOUBLE@ 49 50#cmakedefine CONDUIT_USE_LONG_LONG @CONDUIT_USE_LONG_LONG@ 51#cmakedefine CONDUIT_USE_LONG_DOUBLE @CONDUIT_USE_LONG_DOUBLE@ 52 53//----------------------------------------------------------------------------- 54// unsigned native types 55//----------------------------------------------------------------------------- 56 57typedef unsigned char conduit_unsigned_char; 58typedef unsigned short conduit_unsigned_short; 59typedef unsigned int conduit_unsigned_int; 60typedef unsigned long conduit_unsigned_long; 61 62#ifdef CONDUIT_HAS_LONG_LONG 63typedef unsigned long long conduit_unsigned_long_long; 64#endif 65 66//----------------------------------------------------------------------------- 67// signed native types 68//----------------------------------------------------------------------------- 69 70typedef signed char conduit_signed_char; 71typedef signed short conduit_signed_short; 72typedef signed int conduit_signed_int; 73typedef signed long conduit_signed_long; 74 75#ifdef CONDUIT_HAS_LONG_LONG 76typedef signed long long conduit_signed_long_long; 77#endif 78 79//----------------------------------------------------------------------------- 80// floating point native types 81//----------------------------------------------------------------------------- 82 83typedef float conduit_float; 84typedef double conduit_double; 85 86#if CONDUIT_SIZEOF_LONG_DOUBLE == CONDUIT_SIZEOF_DOUBLE 87 typedef double conduit_long_double; 88#else 89#ifdef CONDUIT_HAS_LONG_DOUBLE 90 typedef long double conduit_long_double; 91#endif 92#endif 93 94 95//----------------------------------------------------------------------------- 96// signed vs unsigned determination 97//----------------------------------------------------------------------------- 98 99// --- char -- // 100// char can be signed or unsigned 101#ifndef CHAR_MIN 102#error Bitwidth Style Types: native mapping requires CHAR_MIN def 103#endif 104 105 106#if (CHAR_MIN==0) 107#define CONDUIT_CHAR_IS_UNSIGNED 108#else 109#define CONDUIT_CHAR_IS_SIGNED 110#endif 111 112// per standard, the rest of types w/o 113// signed-ness should never be unsigned 114 115// --- short -- // 116#ifndef SHRT_MIN 117#error Bitwidth Style Types: native mapping requires SHRT_MIN def 118#endif 119 120#if (SHRT_MIN==0) 121#define CONDUIT_SHORT_IS_UNSIGNED 122#else 123#define CONDUIT_SHORT_IS_SIGNED 124#endif 125 126// --- int -- // 127#ifndef INT_MIN 128#error Bitwidth Style Types: native mapping requires INT_MIN def 129#endif 130 131#if (INT_MIN==0) 132#define CONDUIT_INT_IS_UNSIGNED 133#else 134#define CONDUIT_INT_IS_SIGNED 135#endif 136 137// --- long -- // 138#ifndef LONG_MIN 139#error Bitwidth Style Types: native mapping requires LONG_MIN def 140#endif 141 142#if (LONG_MIN==0) 143#define CONDUIT_LONG_IS_UNSIGNED 144#else 145#define CONDUIT_LONG_IS_SIGNED 146#endif 147 148// --- long long -- // 149#ifdef CONDUIT_HAS_LONG_LONG 150 151#ifndef LLONG_MIN 152#error Bitwidth Style Types: native mapping requires LLONG_MIN def 153#endif 154 155#if (LLONG_MIN==0) 156#define CONDUIT_LONG_LONG_IS_UNSIGNED 157#else 158#define CONDUIT_LONG_LONG_IS_SIGNED 159#endif 160 161#endif 162 163 164#if defined(CONDUIT_CHAR_IS_UNSIGNED) 165typedef conduit_unsigned_char conduit_char; 166#else 167typedef conduit_signed_char conduit_char; 168#endif 169 170typedef conduit_signed_short conduit_short; 171typedef conduit_signed_int conduit_int; 172typedef conduit_signed_long conduit_long; 173 174#ifdef CONDUIT_HAS_LONG_LONG 175typedef conduit_signed_long_long conduit_long_long; 176#endif 177 178/*----------------------------------------------------------------------------- 179/ conduit_datatype_type_id is an Enumeration used to describe the type 180/ roles supported by conduit: 181-----------------------------------------------------------------------------*/ 182typedef enum 183{ 184 CONDUIT_EMPTY_ID = @CONDUIT_EMPTY_ID@, // empty (default type) 185 CONDUIT_OBJECT_ID = @CONDUIT_OBJECT_ID@, // object 186 CONDUIT_LIST_ID = @CONDUIT_LIST_ID@, // list 187 /* signed integer types */ 188 CONDUIT_INT8_ID = @CONDUIT_INT8_ID@, // int8 and int8_array 189 CONDUIT_INT16_ID = @CONDUIT_INT16_ID@, // int16 and int16_array 190 CONDUIT_INT32_ID = @CONDUIT_INT32_ID@, // int32 and int32_array 191 CONDUIT_INT64_ID = @CONDUIT_INT64_ID@, // int64 and int64_array 192 /* unsigned integer types */ 193 CONDUIT_UINT8_ID = @CONDUIT_UINT8_ID@, // int8 and int8_array 194 CONDUIT_UINT16_ID = @CONDUIT_UINT16_ID@, // uint16 and uint16_array 195 CONDUIT_UINT32_ID = @CONDUIT_UINT32_ID@, // uint32 and uint32_array 196 CONDUIT_UINT64_ID = @CONDUIT_UINT64_ID@, // uint64 and uint64_array 197 /* floating point integer types */ 198 CONDUIT_FLOAT32_ID = @CONDUIT_FLOAT32_ID@, // float32 and float32_array 199 CONDUIT_FLOAT64_ID = @CONDUIT_FLOAT64_ID@, // float64 and float64_array 200 /* string types */ 201 CONDUIT_CHAR8_STR_ID = @CONDUIT_CHAR8_STR_ID@ // char8 string (incore c-string) 202} conduit_datatype_type_id; 203 204 205 206//----------------------------------------------------------------------------- 207// -- bitwidth style signed integer types -- 208//----------------------------------------------------------------------------- 209typedef @CONDUIT_INT8_TYPE@ conduit_int8; 210typedef @CONDUIT_INT16_TYPE@ conduit_int16; 211typedef @CONDUIT_INT32_TYPE@ conduit_int32; 212typedef @CONDUIT_INT64_TYPE@ conduit_int64; 213 214// string defs 215#define CONDUIT_INT8_NATIVE_NAME "@CONDUIT_INT8_NATIVE_TYPE@" 216#define CONDUIT_INT16_NATIVE_NAME "@CONDUIT_INT16_NATIVE_TYPE@" 217#define CONDUIT_INT32_NATIVE_NAME "@CONDUIT_INT32_NATIVE_TYPE@" 218#define CONDUIT_INT64_NATIVE_NAME "@CONDUIT_INT64_NATIVE_TYPE@" 219 220//----------------------------------------------------------------------------- 221// -- bitwidth style unsigned integer types -- 222//----------------------------------------------------------------------------- 223typedef @CONDUIT_UINT8_TYPE@ conduit_uint8; 224typedef @CONDUIT_UINT16_TYPE@ conduit_uint16; 225typedef @CONDUIT_UINT32_TYPE@ conduit_uint32; 226typedef @CONDUIT_UINT64_TYPE@ conduit_uint64; 227 228// string defs 229#define CONDUIT_UINT8_NATIVE_NAME "@CONDUIT_UINT8_NATIVE_TYPE@" 230#define CONDUIT_UINT16_NATIVE_NAME "@CONDUIT_UINT16_NATIVE_TYPE@" 231#define CONDUIT_UINT32_NATIVE_NAME "@CONDUIT_UINT32_NATIVE_TYPE@" 232#define CONDUIT_UINT64_NATIVE_NAME "@CONDUIT_UINT64_NATIVE_TYPE@" 233 234 235//----------------------------------------------------------------------------- 236// -- bitwidth style floating point types 237//----------------------------------------------------------------------------- 238typedef @CONDUIT_FLOAT32_TYPE@ conduit_float32; 239typedef @CONDUIT_FLOAT64_TYPE@ conduit_float64; 240 241// string defs 242#define CONDUIT_FLOAT32_NATIVE_NAME "@CONDUIT_FLOAT32_NATIVE_TYPE@" 243#define CONDUIT_FLOAT64_NATIVE_NAME "@CONDUIT_FLOAT64_NATIVE_TYPE@" 244 245 246//----------------------------------------------------------------------------- 247// -- c style signed integer type maps -- 248//----------------------------------------------------------------------------- 249#define CONDUIT_NATIVE_SIGNED_CHAR @CONDUIT_NATIVE_SIGNED_CHAR_TYPE@ 250#define CONDUIT_NATIVE_SIGNED_SHORT @CONDUIT_NATIVE_SIGNED_SHORT_TYPE@ 251#define CONDUIT_NATIVE_SIGNED_INT @CONDUIT_NATIVE_SIGNED_INT_TYPE@ 252#define CONDUIT_NATIVE_SIGNED_LONG @CONDUIT_NATIVE_SIGNED_LONG_TYPE@ 253#if defined(CONDUIT_HAS_LONG_LONG) 254#define CONDUIT_NATIVE_SIGNED_LONG_LONG @CONDUIT_NATIVE_SIGNED_LONG_LONG_TYPE@ 255#endif 256 257#define CONDUIT_NATIVE_SIGNED_CHAR_ID @CONDUIT_NATIVE_SIGNED_CHAR_ID@ 258#define CONDUIT_NATIVE_SIGNED_SHORT_ID @CONDUIT_NATIVE_SIGNED_SHORT_ID@ 259#define CONDUIT_NATIVE_SIGNED_INT_ID @CONDUIT_NATIVE_SIGNED_INT_ID@ 260#define CONDUIT_NATIVE_SIGNED_LONG_ID @CONDUIT_NATIVE_SIGNED_LONG_ID@ 261#if defined(CONDUIT_HAS_LONG_LONG) 262#define CONDUIT_NATIVE_SIGNED_LONG_LONG_ID @CONDUIT_NATIVE_SIGNED_LONG_LONG_ID@ 263#endif 264 265//----------------------------------------------------------------------------- 266// -- c style unsigned integer type maps -- 267//----------------------------------------------------------------------------- 268#define CONDUIT_NATIVE_UNSIGNED_CHAR @CONDUIT_NATIVE_UNSIGNED_CHAR_TYPE@ 269#define CONDUIT_NATIVE_UNSIGNED_SHORT @CONDUIT_NATIVE_UNSIGNED_SHORT_TYPE@ 270#define CONDUIT_NATIVE_UNSIGNED_INT @CONDUIT_NATIVE_UNSIGNED_INT_TYPE@ 271#define CONDUIT_NATIVE_UNSIGNED_LONG @CONDUIT_NATIVE_UNSIGNED_LONG_TYPE@ 272#if defined(CONDUIT_HAS_LONG_LONG) 273#define CONDUIT_NATIVE_UNSIGNED_LONG_LONG @CONDUIT_NATIVE_UNSIGNED_LONG_LONG_TYPE@ 274#endif 275 276#define CONDUIT_NATIVE_UNSIGNED_CHAR_ID @CONDUIT_NATIVE_UNSIGNED_CHAR_ID@ 277#define CONDUIT_NATIVE_UNSIGNED_SHORT_ID @CONDUIT_NATIVE_UNSIGNED_SHORT_ID@ 278#define CONDUIT_NATIVE_UNSIGNED_INT_ID @CONDUIT_NATIVE_UNSIGNED_INT_ID@ 279#define CONDUIT_NATIVE_UNSIGNED_LONG_ID @CONDUIT_NATIVE_UNSIGNED_LONG_ID@ 280#if defined(CONDUIT_HAS_LONG_LONG) 281#define CONDUIT_NATIVE_UNSIGNED_LONG_LONG_ID @CONDUIT_NATIVE_UNSIGNED_LONG_LONG_ID@ 282#endif 283 284//----------------------------------------------------------------------------- 285// -- c style unsigned integer type maps -- 286//----------------------------------------------------------------------------- 287#if defined(CONDUIT_CHAR_IS_UNSIGNED) 288#define CONDUIT_NATIVE_CHAR CONDUIT_NATIVE_UNSIGNED_CHAR 289#else 290#define CONDUIT_NATIVE_CHAR CONDUIT_NATIVE_SIGNED_CHAR 291#endif 292 293#define CONDUIT_NATIVE_SHORT CONDUIT_NATIVE_SIGNED_SHORT 294#define CONDUIT_NATIVE_INT CONDUIT_NATIVE_SIGNED_INT 295#define CONDUIT_NATIVE_LONG CONDUIT_NATIVE_SIGNED_LONG 296#if defined(CONDUIT_HAS_LONG_LONG) 297#define CONDUIT_NATIVE_LONG_LONG CONDUIT_NATIVE_SIGNED_LONG_LONG 298#endif 299 300#if defined(CONDUIT_CHAR_IS_UNSIGNED) 301#define CONDUIT_NATIVE_CHAR_ID CONDUIT_NATIVE_UNSIGNED_CHAR_ID 302#else 303#define CONDUIT_NATIVE_CHAR_ID CONDUIT_NATIVE_SIGNED_CHAR_ID 304#endif 305 306#define CONDUIT_NATIVE_SHORT_ID CONDUIT_NATIVE_SIGNED_SHORT_ID 307#define CONDUIT_NATIVE_INT_ID CONDUIT_NATIVE_SIGNED_INT_ID 308#define CONDUIT_NATIVE_LONG_ID CONDUIT_NATIVE_SIGNED_LONG_ID 309#if defined(CONDUIT_HAS_LONG_LONG) 310#define CONDUIT_NATIVE_LONG_LONG_ID @CONDUIT_NATIVE_SIGNED_LONG_LONG_ID@ 311#endif 312 313 314//----------------------------------------------------------------------------- 315// -- c style floating point type maps -- 316//----------------------------------------------------------------------------- 317#define CONDUIT_NATIVE_FLOAT @CONDUIT_NATIVE_FLOAT_TYPE@ 318#define CONDUIT_NATIVE_DOUBLE @CONDUIT_NATIVE_DOUBLE_TYPE@ 319#if defined(CONDUIT_USE_LONG_DOUBLE) 320#define CONDUIT_NATIVE_LONG_DOUBLE @CONDUIT_NATIVE_LONG_DOUBLE_TYPE@ 321#endif 322 323#define CONDUIT_NATIVE_FLOAT_ID @CONDUIT_NATIVE_FLOAT_ID@ 324#define CONDUIT_NATIVE_DOUBLE_ID @CONDUIT_NATIVE_DOUBLE_ID@ 325#if defined(CONDUIT_USE_LONG_DOUBLE) 326#define CONDUIT_NATIVE_LONG_DOUBLE_ID @CONDUIT_NATIVE_LONG_DOUBLE_ID@ 327#endif 328 329 330//----------------------------------------------------------------------------- 331/// Index Types 332//----------------------------------------------------------------------------- 333 334/// index typedefs 335typedef conduit_int32 conduit_index32_t; 336typedef conduit_int64 conduit_index64_t; 337 338/// use a 64-bit index, unless CONDUIT_INDEX_32 is defined. 339#ifdef CONDUIT_INDEX_32 340typedef conduit_index32_t conduit_index_t; 341#else 342typedef conduit_index64_t conduit_index_t; 343#endif 344 345//----------------------------------------------------------------------------- 346/// Bit-width type map sanity checks 347//----------------------------------------------------------------------------- 348 349// 350// check that we were able to resolve all of the bitwidth style types we want 351// to support 352 353// signed int 354#ifndef CONDUIT_INT8_NATIVE_NAME 355#error Bitwidth Style Types: no native type found that maps to int8 356#endif 357 358#ifndef CONDUIT_INT16_NATIVE_NAME 359#error Bitwidth Style Types: no native type found that maps to int16 360#endif 361 362#ifndef CONDUIT_INT32_NATIVE_NAME 363#error Bitwidth Style Types: no native type found that maps to int32 364#endif 365 366#ifndef CONDUIT_INT64_NATIVE_NAME 367#error Bitwidth Style Types: no native type found that maps to int64 368#endif 369 370// unsigned ints 371#ifndef CONDUIT_UINT8_NATIVE_NAME 372#error Bitwidth Style Types: no native type found that maps to uint8 373#endif 374 375#ifndef CONDUIT_UINT16_NATIVE_NAME 376#error Bitwidth Style Types: no native type found that maps to uint16 377#endif 378 379#ifndef CONDUIT_UINT32_NATIVE_NAME 380#error Bitwidth Style Types: no native type found that maps to uint32 381#endif 382 383#ifndef CONDUIT_UINT64_NATIVE_NAME 384#error Bitwidth Style Types: no native type found that maps to uint64 385#endif 386 387// floating points numbers 388#ifndef CONDUIT_FLOAT32_NATIVE_NAME 389#error Bitwidth Style Types: no native type found that maps to float32 390#endif 391 392#ifndef CONDUIT_FLOAT64_NATIVE_NAME 393#error Bitwidth Style Types: no native type found that maps to float64 394#endif 395 396//----------------------------------------------------------------------------- 397///End Bit-width type map sanity checks 398//----------------------------------------------------------------------------- 399 400//----------------------------------------------------------------------------- 401/// Native type map sanity checks 402//----------------------------------------------------------------------------- 403 404// 405// check that we have a mapping for all base native types to conduit types 406// 407 408// native ints 409#ifndef CONDUIT_NATIVE_CHAR 410#error C-Style Types: no conduit type found that maps to char 411#endif 412 413#ifndef CONDUIT_NATIVE_SHORT 414#error C-Style Types: no conduit type found that maps to short 415#endif 416 417#ifndef CONDUIT_NATIVE_INT 418#error C-Style Types: no conduit type found that maps to int 419#endif 420 421#ifndef CONDUIT_NATIVE_LONG 422#error C-Style Types: no conduit type found that maps to long 423#endif 424 425#if defined(CONDUIT_HAS_LONG_LONG) 426#ifndef CONDUIT_NATIVE_LONG_LONG 427#error C-Style Types: no conduit type found that maps to long long 428#endif 429#endif 430 431// signed ints 432#ifndef CONDUIT_NATIVE_SIGNED_CHAR 433#error C-Style Types: no conduit type found that maps to signed char 434#endif 435 436#ifndef CONDUIT_NATIVE_SIGNED_SHORT 437#error C-Style Types: no conduit type found that maps to signed short 438#endif 439 440#ifndef CONDUIT_NATIVE_SIGNED_INT 441#error C-Style Types: no conduit type found that maps to signed int 442#endif 443 444#ifndef CONDUIT_NATIVE_SIGNED_LONG 445#error C-Style Types: no conduit type found that maps to signed long 446#endif 447 448#if defined(CONDUIT_HAS_LONG_LONG) 449#ifndef CONDUIT_NATIVE_SIGNED_LONG_LONG 450#error C-Style Types: no conduit type found that maps to signed long long 451#endif 452#endif 453 454// unsigned ints 455#ifndef CONDUIT_NATIVE_UNSIGNED_CHAR 456#error C-Style Types: no conduit type found that maps to unsigned char 457#endif 458 459#ifndef CONDUIT_NATIVE_UNSIGNED_SHORT 460#error C-Style Types: no conduit type found that maps to unsigned short 461#endif 462 463#ifndef CONDUIT_NATIVE_UNSIGNED_INT 464#error C-Style Types: no conduit type found that maps to unsigned int 465#endif 466 467#ifndef CONDUIT_NATIVE_UNSIGNED_LONG 468#error C-Style Types: no conduit type found that maps to unsigned long 469#endif 470 471#if defined(CONDUIT_HAS_LONG_LONG) 472#ifndef CONDUIT_NATIVE_UNSIGNED_LONG_LONG 473#error C-Style Types: no conduit type found that maps to unsigned long long 474#endif 475#endif 476 477 478// native ints 479#ifndef CONDUIT_NATIVE_CHAR 480#error C-Style Types: no conduit type found that maps to char 481#endif 482 483#ifndef CONDUIT_NATIVE_SHORT 484#error C-Style Types: no conduit type found that maps to short 485#endif 486 487#ifndef CONDUIT_NATIVE_INT 488#error C-Style Types: no conduit type found that maps to int 489#endif 490 491#ifndef CONDUIT_NATIVE_LONG 492#error C-Style Types: no conduit type found that maps to long 493#endif 494 495#if defined(CONDUIT_HAS_LONG_LONG) 496#ifndef CONDUIT_NATIVE_LONG_LONG 497#error C-Style Types: no conduit type found that maps to long long 498#endif 499#endif 500 501// floating points numbers 502#ifndef CONDUIT_NATIVE_FLOAT 503#error C-Style Types: no conduit type found that maps to float 504#endif 505 506#ifndef CONDUIT_NATIVE_DOUBLE 507#error C-Style Types: no conduit type found that maps to double 508#endif 509 510//----------------------------------------------------------------------------- 511///End Bit-width type map sanity checks 512//----------------------------------------------------------------------------- 513 514 515#endif 516 517