DCL 3.7.6
Loading...
Searching...
No Matches
PqTypes.h
Go to the documentation of this file.
1#ifndef __DCL_PQ_TYPES_H__
2#define __DCL_PQ_TYPES_H__ 20260106
3
4#ifdef __WINNT__
5 #define bswap_16(_x) _byteswap_ushort(_x)
6 #define bswap_32(_x) _byteswap_ulong(_x)
7 #define bswap_64(_x) _byteswap_uint64(_x)
8#elif defined(__APPLE__)
9 #define bswap_16(_x) OSSwapInt16(_x)
10 #define bswap_32(_x) OSSwapInt32(_x)
11 #define bswap_64(_x) OSSwapInt64(_x)
12#else
13 // __linux__ __FreeBSD__
14 #include <byteswap.h> // bswap
15#endif
16
17__DCL_BEGIN_NAMESPACE
18
19// undef for FreeBSD
20#undef __htons
21#undef __htonl
22#undef __htonll
23#undef __htonf
24#undef __htond
25#undef __ntohs
26#undef __ntohl
27#undef __ntohll
28#undef __ntohf
29#undef __ntohd
30
31inline uint16_t __htons(uint16_t _x)
32{
33#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
34 return bswap_16(_x);
35#else
36 return _x
37#endif
38}
39
40inline uint32_t __htonl(uint32_t _x)
41{
42#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
43 return bswap_32(_x);
44#else
45 return _x
46#endif
47}
48
49inline uint64_t __htonll(uint64_t _x)
50{
51#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
52 return bswap_64(_x);
53#else
54 return _x
55#endif
56}
57
58#define __ntohs(_x) __htons(_x)
59#define __ntohl(_x) __htonl(_x)
60#define __ntohll(_x) __htonll(_x)
61
62inline void __copy__(void* _dst, const void* _src, size_t _size)
63{
64 unsigned char* dst = (unsigned char*)_dst;
65 const unsigned char* src = (unsigned char*)_src;
66 while (_size--) {
67 *dst++ = *src++;
68 }
69}
70
71inline void __rcopy__(void* _dst, const void* _src, size_t _size)
72{
73 unsigned char* dst = (unsigned char*)_dst;
74 const unsigned char* src = (unsigned char*)_src + _size;
75 while (_size--) {
76 *dst++ = *(--src);
77 }
78}
79
80inline uint32_t __htonf(float _x)
81{
82 uint32_t x;
83#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
84 __rcopy__(&x, &_x, sizeof(_x));
85#else
86 __copy__(&x, &_x, sizeof(_x));
87#endif
88 return x;
89}
90
91inline uint64_t __htond(double _x)
92{
93 uint64_t x;
94#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
95 __rcopy__(&x, &_x, sizeof(_x));
96#else
97 __copy__(&x, &_x, sizeof(_x));
98#endif
99 return x;
100}
101
102inline float __ntohf(uint32_t _x)
103{
104 float x;
105#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
106 __rcopy__(&x, &_x, sizeof(_x));
107#else
108 __copy__(&x, &_x, sizeof(_x));
109#endif
110 return x;
111}
112
113inline double __ntohd(uint64_t _x)
114{
115 double x;
116#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
117 __rcopy__(&x, &_x, sizeof(_x));
118#else
119 __copy__(&x, &_x, sizeof(_x));
120#endif
121 return x;
122}
123
124inline bool __is_hex_escaped(const char* _src)
125{
126 return *_src++ == '\\' && (*_src == 'x' || *_src == 'X');
127}
128
129// return false는 오류 데이터가 포함되었음을 의미한다.
130// 오류 데이터는 무시된다. _dstend는 unescape된 길이를 지시한다.
131bool __unescape_hex(
132 const char* _src, const char*& _srcend,
133 char* _dst, char*& _dstend
134);
135
136// return false는 오류 데이터가 포함되었음을 의미한다.
137// 오류 데이터는 무시된다. _dstend는 unescape된 길이를 지시한다.
138bool __unescape_oct(
139 const char* _src, const char*& _srcend,
140 char* _dst, char*& _dstend
141);
142
143// _s는 '\0' 종결문자열 이어야 한다. _endptr는 _s의 최종 위치를 반환한다.
144// return false는 오류데이터를 포함하고 있고, _r 값은 사용할 수 없다.
146 const char* _s, const char** _endptr,
148);
149
150// _s는 '\0' 종결문자열 이어야 한다. _endptr는 _s의 최종 위치를 반환한다.
151// return false는 오류데이터를 포함하고 있고, _r 값은 사용할 수 없다
153 const char* _s, const char** _endptr,
154 SQL::Interval& _r
155);
156
157const wchar_t* __dataTypeName(Oid _oid);
158
159__DCL_END_NAMESPACE
160
161#endif // __DCL_PQ_TYPES_H__
uint64_t __htond(double _x)
Definition PqTypes.h:91
void __copy__(void *_dst, const void *_src, size_t _size)
Definition PqTypes.h:62
bool __is_hex_escaped(const char *_src)
Definition PqTypes.h:124
bool __unescape_hex(const char *_src, const char *&_srcend, char *_dst, char *&_dstend)
Definition PqTypes.cpp:59
bool __unescape_oct(const char *_src, const char *&_srcend, char *_dst, char *&_dstend)
Definition PqTypes.cpp:108
bool __decode_timestamp_iso(const char *_s, const char **_endptr, SQL::TimeStamp &_r)
Definition PqTypes.cpp:176
uint32_t __htonf(float _x)
Definition PqTypes.h:80
float __ntohf(uint32_t _x)
Definition PqTypes.h:102
__DCL_BEGIN_NAMESPACE uint16_t __htons(uint16_t _x)
Definition PqTypes.h:31
uint64_t __htonll(uint64_t _x)
Definition PqTypes.h:49
void __rcopy__(void *_dst, const void *_src, size_t _size)
Definition PqTypes.h:71
uint32_t __htonl(uint32_t _x)
Definition PqTypes.h:40
bool __decode_interval_iso(const char *_s, const char **_endptr, SQL::Interval &_r)
Definition PqTypes.cpp:308
const wchar_t * __dataTypeName(Oid _oid)
Definition PqTypes.cpp:418
double __ntohd(uint64_t _x)
Definition PqTypes.h:113