WriteDatatype(Enum); \ return RawWrite(sizeof(Buffer), &Buffer); \ }; SIMPLE_TEMPLATE(bool, eBytebufferType::BOOL); SIMPLE_TEMPLATE(char, eBytebufferType::SINT8); SIMPLE_TEMPLATE(int8_t, eBytebufferType::SINT8); SIMPLE_TEMPLATE(uint8_t, eBytebufferType::UINT8); SIMPLE_TEMPLATE(int16_t, eBytebufferType::SINT16); SIMPLE_TEMPLATE(uint16_t, eBytebufferType::UINT16); SIMPLE_TEMPLATE(int32_t, eBytebufferType::SINT32); SIMPLE_TEMPLATE(uint32_t, eBytebufferType::UINT32); SIMPLE_TEMPLATE(int64_t, eBytebufferType::SINT64); SIMPLE_TEMPLATE(uint64_t, eBytebufferType::UINT64); #ifndef NO_TTMATH SIMPLE_TEMPLATE(ttmath::Int<TTMATH_BITS(128)>, eBytebufferType::SINT128); SIMPLE_TEMPLATE(ttmath::UInt<TTMATH_BITS(128)>, eBytebufferType::UINT128); #endif SIMPLE_TEMPLATE(float, eBytebufferType::FLOAT32); SIMPLE_TEMPLATE(double, eBytebufferType::FLOAT64); // Advanced storagetypes. bool Bytebuffer::ReadBlob(std::string *Output, bool Typechecked) { if (!Typechecked || ReadDatatype(eBytebufferType::BLOB)) { uint32_t BlobLength = TemplateRead<uint32_t>(); // Range check. if (InternalPosition + BlobLength > InternalBuffer.size()) {
// this is a similar example to big.cpp // but now we're using TTMATH_BITS() macro // this macro returns how many words we need to store // the given number of bits // TTMATH_BITS(64) // on a 32bit platform the macro returns 2 (2*32=64) // on a 64bit platform the macro returns 1 // TTMATH_BITS(128) // on a 32bit platform the macro returns 4 (4*32=128) // on a 64bit platform the macro returns 2 (2*64=128) // Big<exponent, mantissa> typedef ttmath::Big<TTMATH_BITS(64), TTMATH_BITS(128)> MyBig; // consequently on a 32bit platform we define: Big<2, 4> // and on a 64bit platform: Big<1, 2> // and the calculations will be the same on both platforms void SimpleCalculating(const MyBig & a, const MyBig & b) { std::cout << "Simple calculating" << std::endl; std::cout << "a = " << a << std::endl; std::cout << "b = " << b << std::endl; std::cout << "a + b = " << a+b << std::endl; std::cout << "a - b = " << a-b << std::endl; std::cout << "a * b = " << a*b << std::endl; std::cout << "a / b = " << a/b << std::endl;