forked from yeyouqun/xdeltalib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mytypes.h
182 lines (160 loc) · 4.57 KB
/
mytypes.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Copyright (C) 2013- yeyouqun@163.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#ifndef __MYTYPES_H__
#define __MYTYPES_H__
#include <exception>
#ifndef _WIN32
#include <errno.h>
extern int errno;
#endif
#include "platform.h"
/// @file
/// ÀàÐͼ°Æ½Ì¨¿ØÖÆÎļþ
namespace xdelta {
#define HAVE_UINT64 1
/*---------------------------------------------------------------------------*/
/* */
/* Type Definition Macros */
/* */
/*---------------------------------------------------------------------------*/
#ifdef _WIN32
#if defined (_M_X64) || defined (_M_AMD64)
#define __WORDSIZE 64
#else
#define __WORDSIZE 32
#endif
#pragma warning (disable:4251)
#elif defined (__GNUC__)
#if defined (__LP64__) || defined (_LP64)
#define __WORDSIZE 64
#else
#define __WORDSIZE 32
#endif
#else
#error Current platform not support temporary.
#endif
#ifdef _WIN32
struct iovec {
void *iov_base;
size_t iov_len;
};
typedef int socklen_t;
#define ssize_t size_t
#else
typedef int SOCKET;
#endif
typedef unsigned long long uint64_t;
typedef long long int64_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned char uchar_t;
typedef char char_t;
typedef unsigned short uint16_t;
typedef short int16_t;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
class DLL_EXPORT xdelta_exception : public ::std::exception
{
std::string what_;
int errno_;
#ifndef NDEBUG
std::string fname_;
int fline_;
#endif
public:
xdelta_exception (const std::string & what, int error_no
#ifndef NDEBUG
, const std::string & fname
, int fline
#endif
) : what_ (what), errno_ (error_no)
#ifndef NDEBUG
, fname_ (fname)
, fline_ (fline)
#endif
{}
virtual ~xdelta_exception () throw () {}
virtual const char* what() const throw()
{
#ifndef NDEBUG
const_cast<std::string&> (what_) =
fmt_string ("exception:%s, at file (%s), line (%d).", what_.c_str ()
, fname_.c_str (), fline_).c_str ();
#endif
return what_.c_str ();
}
int get_errno () const { return errno_; }
};
#ifndef NDEBUG
#ifdef _WIN32
#define THROW_XDELTA_EXCEPTION(errmsg) \
throw xdelta::xdelta_exception ((errmsg), ::GetLastError (), __FILE__, __LINE__)
#else
#define THROW_XDELTA_EXCEPTION(errmsg) \
throw xdelta::xdelta_exception ((errmsg), errno, __FILE__, __LINE__)
#endif
#define THROW_XDELTA_EXCEPTION_NO_ERRNO(errmsg) \
throw xdelta::xdelta_exception ((errmsg), 0, __FILE__, __LINE__)
#else
#ifdef _WIN32
#define THROW_XDELTA_EXCEPTION(errmsg) \
throw xdelta::xdelta_exception ((errmsg), ::GetLastError ())
#else
#define THROW_XDELTA_EXCEPTION(errmsg) \
throw xdelta::xdelta_exception ((errmsg), errno)
#endif
#define THROW_XDELTA_EXCEPTION_NO_ERRNO(errmsg) \
throw xdelta::xdelta_exception ((errmsg), 0)
#endif
#ifndef BYTE_ORDER
#define LITTLE_ENDIAN 0x4321
#define BIG_ENDIAN 0x1234
#ifdef _WIN32
#if defined (_M_AMD64) || defined (_M_IX86)
#define BYTE_ORDER LITTLE_ENDIAN
#else
#define BYTE_ORDER BIG_ENDIAN
#endif
#elif defined (__GNUG__) || defined (__GNUC__)
#if defined (__ORDER_LITTLE_ENDIAN__) && defined (__BYTE_ORDER__) &&
(__ORDER_LITTLE_ENDIAN__ == __BYTE_ORDER__)
#define BYTE_ORDER LITTLE_ENDIAN
#elif defined(__i386__) || defined (__amd64__)
#define BYTE_ORDER LITTLE_ENDIAN
#else
#define BYTE_ORDER BIG_ENDIAN
#endif
#else
#error Unsupportted compiler or platform.
#endif
#endif
template<class obj_t>
static inline void delete_obj (obj_t * pobj)
{
delete pobj;
}
#define BUG(mesg) do { \
std::string errmsg = fmt_string ("BUG %s IN FILE %s, LINE %d." \
, mesg, __FILE__, __LINE__);\
THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);\
}while (0)
} //namespace xdelta
#endif //__MYTYPES_H__