X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Finttypes.h;fp=source%2Fcore%2Finttypes.h;h=3bdac35c160925aae2a0b3aef5c6b45a66cdefa0;hb=4bd704ea84b36dc8e83db51cd5eab4111eb48c2a;hp=0000000000000000000000000000000000000000;hpb=380580a1783dfb043ad4352cef1120da44317bbd;p=libs%2Fcore.git diff --git a/source/core/inttypes.h b/source/core/inttypes.h new file mode 100644 index 0000000..3bdac35 --- /dev/null +++ b/source/core/inttypes.h @@ -0,0 +1,61 @@ +#ifndef MSP_CORE_INTTYPES_H_ +#define MSP_CORE_INTTYPES_H_ + +#include +#include "typelist.h" + +namespace Msp { + +// Define lists of standard types, both signed and unsigned variants +typedef TypeList::Type StandardSignedTypes; +typedef TypeList::Type StandardUnsignedTypes; + +// Then add possible nonstandard types +#if defined(__GNUC__) +#if (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=6)) && defined(__LP64__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-pedantic" +typedef TypeList::Type PlatformSignedTypes; +typedef TypeList::Type PlatformUnsignedTypes; +#pragma GCC diagnostic pop +#else +typedef TypeList::Type PlatformSignedTypes; +typedef TypeList::Type PlatformUnsignedTypes; +#endif +#elif defined(_MSC_VER) +typedef TypeList::Type PlatformSignedTypes; +typedef TypeList::Type PlatformUnsignedTypes; +#else +typedef StandardSignedTypes PlatformSignedTypes; +typedef StandardUnsignedTypes PlatformUnsignedTypes; +#endif + +/** A helper for choosing an integer type of a specific size. The size +parameter is in bits. The resulting types can be obtained from the SignedType +and UnsignedType typedefs. */ +template +struct Int +{ + template + struct Predicate + { + enum { value = (sizeof(T)*CHAR_BIT==size) }; + }; + + typedef typename TypeChooser::Type SignedType; + typedef typename TypeChooser::Type UnsignedType; +}; + +// Finally define convenient shorthands for the actual integer types +typedef Int<8>::SignedType Int8; +typedef Int<8>::UnsignedType UInt8; +typedef Int<16>::SignedType Int16; +typedef Int<16>::UnsignedType UInt16; +typedef Int<32>::SignedType Int32; +typedef Int<32>::UnsignedType UInt32; +typedef Int<64>::SignedType Int64; +typedef Int<64>::UnsignedType UInt64; + +} // namespace Msp + +#endif