libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
coreUtils.hpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
8#ifndef TRITON_CORE_UTIL_H
9#define TRITON_CORE_UTIL_H
10
11#include <sstream>
12#include <string>
13#include <type_traits>
14
15#include <triton/config.hpp>
16#include <triton/dllexport.hpp>
18
19
20
22namespace triton {
29 namespace utils {
37 template<typename T>
38 inline std::string toString(const T& obj) {
39 std::stringstream ss;
40 ss << obj;
41 return ss.str();
42 }
43
45 TRITON_EXPORT void fromUintToBuffer(triton::uint80 value, triton::uint8* buffer);
46
48 TRITON_EXPORT void fromUintToBuffer(triton::uint128 value, triton::uint8* buffer);
49
51 TRITON_EXPORT void fromUintToBuffer(triton::uint256 value, triton::uint8* buffer);
52
54 TRITON_EXPORT void fromUintToBuffer(triton::uint512 value, triton::uint8* buffer);
55
57 template <typename T>
58 constexpr T cast(const triton::uint512& value) {
59 return static_cast<T>(value);
60 }
61
63 template <typename T>
64 constexpr T cast(const triton::uint80& value) {
65 return static_cast<T>(value);
66 }
67
69 template <typename T> T cast(const triton::uint8* buffer) {
70 // We want to always trigger the static assert when this function is defined (use with a type without specialization)
71 // so we have to set the value to false with dependency on T type.
72 static_assert(not std::is_same<T, T>::value, "cast have no implementation for this type");
73 return {};
74 }
75
76 template <> TRITON_EXPORT triton::uint80 cast(const triton::uint8* buffer);
77 template <> TRITON_EXPORT triton::uint128 cast(const triton::uint8* buffer);
78 template <> TRITON_EXPORT triton::uint256 cast(const triton::uint8* buffer);
79 template <> TRITON_EXPORT triton::uint512 cast(const triton::uint8* buffer);
80
81 template <> TRITON_EXPORT triton::uint80 cast(const triton::uint512& value);
82 template <> TRITON_EXPORT triton::uint512 cast(const triton::uint80& value);
83
85 };
87};
88
89#endif /* TRITON_CORE_UTIL_H */
math::wide_integer::uint128_t uint128
unsigned 128-bits
math::wide_integer::uint256_t uint256
unsigned 256-bits
math::wide_integer::uintwide_t< static_cast< size_t >(UINT32_C(80)), std::uint16_t > uint80
unsigned 80-bits
math::wide_integer::uint512_t uint512
unsigned 512-bits
std::uint8_t uint8
unisgned 8-bits
TRITON_EXPORT void fromUintToBuffer(triton::uint80 value, triton::uint8 *buffer)
Inject the value into the buffer. Make sure that the buffer contains at least 10 allocated bytes.
Definition coreUtils.cpp:16
constexpr T cast(const triton::uint512 &value)
Casts an triton::uint512 to T.
Definition coreUtils.hpp:58
std::string toString(const T &obj)
Converts an object to a string.
Definition coreUtils.hpp:38
The Triton namespace.