1 /*
2  * Copyright (C) 2014-2018 Muhammad Tayyab Akram
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _SB_PUBLIC_BASE_H
18 #define _SB_PUBLIC_BASE_H
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 /**
24  * A type to represent an 8-bit signed integer.
25  */
26 typedef int8_t                      SBInt8;
27 
28 /**
29  * A type to represent a 16-bit signed integer.
30  */
31 typedef int16_t                     SBInt16;
32 
33 /**
34  * A type to represent a 32-bit signed integer.
35  */
36 typedef int32_t                     SBInt32;
37 
38 /**
39  * A type to represent an 8-bit unsigned integer.
40  */
41 typedef uint8_t                     SBUInt8;
42 
43 /**
44  * A type to represent a 16-bit unsigned integer.
45  */
46 typedef uint16_t                    SBUInt16;
47 
48 /**
49  * A type to represent a 32-bit unsigned integer.
50  */
51 typedef uint32_t                    SBUInt32;
52 
53 /**
54  * A signed integer type whose width is equal to the width of the machine word.
55  */
56 typedef intptr_t                    SBInteger;
57 
58 /**
59  * An unsigned integer type whose width is equal to the width of the machine word.
60  */
61 typedef uintptr_t                   SBUInteger;
62 
63 /**
64  * Constants that specify the states of a boolean.
65  */
66 enum {
67     SBFalse = 0, /**< A value representing the false state. */
68     SBTrue  = 1  /**< A value representing the true state. */
69 };
70 /**
71  * A type to represent a boolean value.
72  */
73 typedef SBUInt8                     SBBoolean;
74 
75 #define SBUInt8InRange(v, s, e)     \
76 (                                   \
77     (SBUInt8)((v) - (s))            \
78  <= (SBUInt8)((e) - (s))            \
79 )
80 
81 #define SBUInt16InRange(v, s, e)    \
82 (                                   \
83     (SBUInt16)((v) - (s))           \
84  <= (SBUInt16)((e) - (s))           \
85 )
86 
87 #define SBUInt32InRange(v, s, e)    \
88 (                                   \
89     (SBUInt32)((v) - (s))           \
90  <= (SBUInt32)((e) - (s))           \
91 )
92 
93 
94 /**
95  * A type to represent a bidi level.
96  */
97 typedef SBUInt8                     SBLevel;
98 
99 /**
100  * A value representing an invalid bidi level.
101  */
102 #define SBLevelInvalid              0xFF
103 
104 /**
105  * A value representing maximum explicit embedding level.
106  */
107 #define SBLevelMax                  125
108 
109 /**
110  * A value specifying to set base level to zero (left-to-right) if there is no strong character.
111  */
112 #define SBLevelDefaultLTR           0xFE
113 
114 /**
115  * A value specifying to set base level to one (right-to-left) if there is no strong character.
116  */
117 #define SBLevelDefaultRTL           0xFD
118 
119 #endif
120