/
basicTypes.c
167 lines (116 loc) · 3.1 KB
/
basicTypes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* VERSION: For the version of VDM2C used to generate this project, refer to one of the generated files. */
/*
Code automatically generated by asn1scc tool
*/
#include <limits.h>
#include <string.h>
#include <math.h>
#include "basicTypes.h"
#if !defined(_MSC_VER) || _MSC_VER >= 1800
void VdmBoolean_Initialize(VdmBoolean* pVal)
{
*pVal = (VdmBoolean) FALSE;
}
#endif
flag VdmBoolean_IsConstraintValid(const VdmBoolean* pVal, int* pErrCode)
{
flag ret = TRUE;
*pErrCode=0;
(void)pVal;
ret = TRUE; *pErrCode = 0;
return ret;
}
flag VdmBoolean_Equal(const VdmBoolean* pVal1, const VdmBoolean* pVal2)
{
flag ret=TRUE;
ret = ( (*pVal1 && *pVal2) || (!*pVal1 && !*pVal2));
return ret;
}
flag VdmBoolean_Encode(const VdmBoolean* pVal, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints)
{
flag ret = TRUE;
ret = bCheckConstraints ? VdmBoolean_IsConstraintValid(pVal, pErrCode) : TRUE ;
if (ret) {
BitStream_AppendBit(pBitStrm,*pVal);
}
return ret;
}
flag VdmBoolean_Decode(VdmBoolean* pVal, BitStream* pBitStrm, int* pErrCode)
{
flag ret = TRUE;
ret = BitStream_ReadBit(pBitStrm, pVal);
*pErrCode = ret ? 0 : 268435457;
return ret;
}
#if !defined(_MSC_VER) || _MSC_VER >= 1800
void VdmInteger_Initialize(VdmInteger* pVal)
{
*pVal = (VdmInteger) 0;
}
#endif
flag VdmInteger_IsConstraintValid(const VdmInteger* pVal, int* pErrCode)
{
flag ret = TRUE;
*pErrCode=0;
(void)pVal;
ret = TRUE; *pErrCode = 0;
return ret;
}
flag VdmInteger_Equal(const VdmInteger* pVal1, const VdmInteger* pVal2)
{
flag ret=TRUE;
ret = (*pVal1 == *pVal2);
return ret;
}
flag VdmInteger_Encode(const VdmInteger* pVal, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints)
{
flag ret = TRUE;
ret = bCheckConstraints ? VdmInteger_IsConstraintValid(pVal, pErrCode) : TRUE ;
if (ret) {
BitStream_EncodeUnConstraintWholeNumber(pBitStrm, *pVal);
}
return ret;
}
flag VdmInteger_Decode(VdmInteger* pVal, BitStream* pBitStrm, int* pErrCode)
{
flag ret = TRUE;
ret = BitStream_DecodeUnConstraintWholeNumber(pBitStrm, pVal);
*pErrCode = ret ? 0 : 268435458;
return ret;
}
#if !defined(_MSC_VER) || _MSC_VER >= 1800
void VdmReal_Initialize(VdmReal* pVal)
{
*pVal = (VdmReal) 0.00000000000000000000E+000;
}
#endif
flag VdmReal_IsConstraintValid(const VdmReal* pVal, int* pErrCode)
{
flag ret = TRUE;
*pErrCode=0;
(void)pVal;
ret = TRUE; *pErrCode = 0;
return ret;
}
flag VdmReal_Equal(const VdmReal* pVal1, const VdmReal* pVal2)
{
flag ret=TRUE;
ret = *pVal1 == *pVal2 ? TRUE : (*pVal1 == 0.0 ? *pVal2 ==0.0 : (fabs((*pVal1 - *pVal2) / *pVal1) < 0.00001));
return ret;
}
flag VdmReal_Encode(const VdmReal* pVal, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints)
{
flag ret = TRUE;
ret = bCheckConstraints ? VdmReal_IsConstraintValid(pVal, pErrCode) : TRUE ;
if (ret) {
BitStream_EncodeReal(pBitStrm, *pVal);
}
return ret;
}
flag VdmReal_Decode(VdmReal* pVal, BitStream* pBitStrm, int* pErrCode)
{
flag ret = TRUE;
BitStream_DecodeReal(pBitStrm, pVal);
*pErrCode = ret ? 0 : 268435459;
return ret;
}