rtmlib
rmtld3.h
Go to the documentation of this file.
1 #ifndef _RMTLD3_H_
2 #define _RMTLD3_H_
3 
4 #include <assert.h>
5 
6 typedef unsigned int proposition;
7 typedef float realnumber;
8 typedef std::pair<realnumber, bool> duration;
9 
12 
13 #define make_duration(r, b) std::make_pair((realnumber)r, b)
14 
15 inline duration sum_dur(const duration &lhs, const duration &rhs) {
16  return make_duration(lhs.first + rhs.first, lhs.second || rhs.second);
17 }
18 
19 inline duration mult_dur(const duration &lhs, const duration &rhs) {
20  return make_duration(lhs.first * rhs.first, lhs.second || rhs.second);
21 }
22 
23 // type conversion from three_valued_type to four_valued_type
24 #define b3_to_b4(b3) \
25  (b3 == T_TRUE) ? FV_TRUE : ((b3 == T_FALSE) ? FV_FALSE : FV_UNKNOWN)
26 
27 // convert four_valued_type into three_valued type
28 #define b4_to_b3(b4) \
29  (b4 == FV_TRUE) ? T_TRUE : ((b4 == FV_FALSE) ? T_FALSE : T_UNKNOWN)
30 
32 #define b3_or(b31, b32) \
33  (b31 == T_TRUE || b32 == T_TRUE) \
34  ? T_TRUE \
35  : ((b31 == T_FALSE && b32 == T_FALSE) ? T_FALSE : T_UNKNOWN)
36 
38 #define b3_not(b3) \
39  ((b3 == T_TRUE) ? T_FALSE : ((b3 == T_FALSE) ? T_TRUE : T_UNKNOWN))
40 
42 #define b3_lessthan(n1, n2) \
43  ((std::get<1>(n1) || std::get<1>(n2)) \
44  ? T_UNKNOWN \
45  : ((std::get<0>(n1) < std::get<0>(n2)) ? T_TRUE : T_FALSE))
46 
47 #define ASSERT_RMTLD3(l) assert(l)
48 
49 #ifndef USE_DEBUGV_RMTLD3
50 #define DEBUGV_RMTLD3(...)
51 #else
52 #include <algorithm>
53 #include <string.h>
54 
55 static int ident = 0;
56 static int r = 0;
57 
58 #define DEBUGV_RMTLD3(cformat, ...) \
59  { \
60  std::string str(cformat); \
61  const char *x, *y, *z = NULL; \
62  \
63  x = strchr(cformat, '$'); \
64  if (x != NULL) { \
65  str.erase(std::remove(str.begin(), str.end(), '$'), str.end()); \
66  for (int i = 0; i < ident; i++) \
67  printf("\t"); \
68  ident++; \
69  } \
70  \
71  y = strchr(cformat, '@'); \
72  if (y != NULL) { \
73  str.erase(std::remove(str.begin(), str.end(), '@'), str.end()); \
74  ident--; \
75  for (int i = 0; i < ident; i++) \
76  printf("\t"); \
77  } \
78  \
79  z = strchr(cformat, '\n'); \
80  if (z != NULL) { \
81  r = 0; \
82  } \
83  \
84  if (x == NULL && y == NULL && r == 0) { \
85  if (z == NULL) \
86  r++; \
87  for (int i = 0; i < ident; i++) \
88  printf("\t"); \
89  } \
90  ::printf(str.c_str(), ##__VA_ARGS__); \
91  };
92 #endif
93 
94 #ifndef USE_DEBUG_RMTLD3
95 #define DEBUG_RTMLD3(...)
96 #else
97 #define DEBUG_RTMLD3(args...) ::printf(args)
98 #endif
99 
100 #define out_p(res) \
101  (res == T_TRUE) ? "true" : ((res == T_FALSE) ? "false" : "unknown")
102 
103 #define out_fv(fv) \
104  (fv == FV_TRUE) \
105  ? "true" \
106  : ((fv == FV_FALSE) ? "false" \
107  : ((fv == FV_UNKNOWN) ? "unknown" : "symbol"))
108 
109 extern int count_until_iterations;
110 
111 #endif //_RMTLD3_H_
Definition: rmtld3.h:10
duration mult_dur(const duration &lhs, const duration &rhs)
Definition: rmtld3.h:19
four_valued_type
Definition: rmtld3.h:11
std::pair< realnumber, bool > duration
Definition: rmtld3.h:8
Definition: rmtld3.h:11
three_valued_type
Definition: rmtld3.h:10
Definition: rmtld3.h:10
Definition: rmtld3.h:11
float realnumber
Definition: rmtld3.h:7
Definition: rmtld3.h:10
duration sum_dur(const duration &lhs, const duration &rhs)
Definition: rmtld3.h:15
#define make_duration(r, b)
Definition: rmtld3.h:13
Definition: rmtld3.h:11
int count_until_iterations
Definition: rmtld3.h:11
unsigned int proposition
Definition: rmtld3.h:6