ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
bigint.h
Go to the documentation of this file.
1// LOOK AT <util/message/format.h> FOR MORE INFO ABOUT
2// WHAT THIS FILE IS ABOUT!!!
3
4#ifndef ESBMC_FORMATS_START_ASSERTION
5# error Do not include this header directly, use <util/message/format.h>
6#endif
7
8// BigInt Specialization
9#include <big-int/bigint.hh>
10template <>
11struct fmt::formatter<BigInt>
12{
13 // Presentation format: 'd' - decimal (default). (Add on demand)
14 char presentation = 'd'; // default
15
16 // This will parse and look for the expected presentation mode
17 constexpr auto parse(format_parse_context &ctx)
18 {
19 auto it = ctx.begin(), end = ctx.end();
20 if (it != end && (*it == 'd'))
21 presentation = *it++;
22 if (it != end && *it != '}')
23 throw format_error("invalid format");
24 return it;
25 }
26
27 // This will teach fmt how to convert BigInt into a str.
28 template <typename FormatContext>
29 auto format(const BigInt &p, FormatContext &ctx) const
30 {
31 int base;
32 switch (presentation)
33 {
34 case 'd':
35 base = 10;
36 break;
37 default:
38 throw format_error("unsupported presentation for bigint");
39 }
40 char tmp[128];
41 char *number;
42 number = p.as_string(tmp, 128, base);
43 return fmt::format_to(ctx.out(), "{}", number);
44 }
45};
static const twodig_t base
Definition bigint.cpp:28
Definition bigint.hh:58
@ number
Definition nested_func_transform.cpp:64
char presentation
Definition bigint.h:14
auto format(const BigInt &p, FormatContext &ctx) const
Definition bigint.h:29
constexpr auto parse(format_parse_context &ctx)
Definition bigint.h:17