-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.h
74 lines (60 loc) · 1.75 KB
/
types.h
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
/**
* Some basic type wrappers
*
* PileOfCrap (http://code.google.com/p/pileofcrap/)
* 2011 Michal 'GiM' Spadlinski
*/
#ifndef GIM_TYPES_H
#define GIM_TYPES_H
#if defined(_MSC_VER)
typedef signed __int8 e_byte;
typedef unsigned __int8 e_ubyte;
typedef signed __int16 e_short;
typedef unsigned __int16 e_ushort;
typedef signed __int32 e_int;
typedef unsigned __int32 e_uint;
typedef signed __int64 e_long;
typedef unsigned __int64 e_ulong;
#else /* !_MSC_VER */
/* size_t */
# include <stddef.h>
# include <stdint.h>
typedef int8_t e_byte;
typedef uint8_t e_ubyte;
typedef int16_t e_short;
typedef uint16_t e_ushort;
typedef int32_t e_int;
typedef uint32_t e_uint;
typedef int64_t e_long;
typedef uint64_t e_ulong;
#endif /* _MSC_VER */
namespace POD {
template <class Ch>
struct TBuffer
{
typedef TBuffer<Ch> Buf;
// this should allow conversion from Buffer -> ConstBuffer, but
// a) not in the other direction,
// b) shouldn't allow other conversions (like TBuffer<uint> -> TBuffer<char>)
template <class Ch2>
TBuffer(const TBuffer<Ch2>& oth) : ptr(oth.ptr), len(oth.len) {}
// ATM allow only assigmnet between matching TBuffers
Buf& operator=(const Buf& oth) {
if (this != &oth) {
ptr = oth.ptr;
len = oth.len;
}
return *this;
}
// default copy ctor will do
//TBuffer(const TBuffer& oth) : ptr(oth.ptr), len(oth.len) {}
TBuffer(Ch* ptr, size_t len) : ptr(ptr), len(len) {}
template <size_t S>
TBuffer(Ch (&buf)[S]) : ptr(buf), len(S*sizeof(Ch)) {}
Ch* ptr;
size_t len;
};
typedef TBuffer<const char> ConstBuffer;
typedef TBuffer<char> Buffer;
}
#endif /* GIM_TYPES_H */