ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcppCom.h
Go to the documentation of this file.
1
8#ifndef ngcppCom_h
9#define ngcppCom_h
10
11
12
13#include <ngc/core/ngcb.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
22#define _ngcpp_swap (ngcppEndian != ngcppCOM_PROT_ENDIAN)
23
27static __inline__ void _byte_order(void *buf, int len, int n)
28{
29 if (_ngcpp_swap)
30 {
31 if (n == 2)
32 {
33 ngcbSwap2(buf, len / 2);
34 }
35 else if (n == 4)
36 {
37 ngcbSwap4(buf, len / 4);
38 }
39 else if (n == 8)
40 {
41 ngcbSwap8(buf, len / 8);
42 }
43 else
44 {
45 return;
46 }
47 }
48}
49
53static __inline__ void ngcppPutValChar(char *buf, char value, int *pos)
54{
55 buf[*pos] = value;
56 *pos += 1;
57}
58
62static __inline__ void ngcppPutValShort(char *buf, int value, int *pos)
63{
64 short shortVal = (short)(value & 0xffff);
65 char tmp[2];
66 int len = sizeof(tmp);
67 char *p = (char *)(void *)&shortVal;
68 memcpy(tmp, p, (size_t)len);
69 _byte_order(tmp, len, len);
70 memcpy(buf + *pos, tmp, (size_t)len);
71 *pos += len;
72}
73
77static __inline__ void ngcppPutValInt(char *buf, int value, int *pos)
78{
79 char tmp[4];
80 int len = sizeof(tmp);
81 char *p = (char *)(void *)&value;
82 memcpy(tmp, p, (size_t)len);
83 _byte_order(tmp, len, len);
84 memcpy(buf + *pos, tmp, (size_t)len);
85 *pos += len;
86}
87
91static __inline__ void ngcppPutValFloat(char *buf, float value, int *pos)
92{
93 char tmp[4];
94 int len = sizeof(tmp);
95 char *p = (char *)(void *)&value;
96 memcpy(tmp, p, (size_t)len);
97 _byte_order(tmp, len, len);
98 memcpy(buf + *pos, tmp, (size_t)len);
99 *pos += len;
100}
101
105static __inline__ void ngcppPutValDouble(char *buf, double value, int *pos)
106{
107 char tmp[8];
108 int len = sizeof(tmp);
109 char *p = (char *)(void *)&value;
110 memcpy(tmp, p, (size_t)len);
111 _byte_order(tmp, len, len);
112 memcpy(buf + *pos, tmp, (size_t)len);
113 *pos += len;
114}
115
119static __inline__ char ngcppGetValChar(char *buf, int *pos)
120{
121 char value;
122 value = buf[*pos];
123 *pos += 1;
124 return (value);
125}
126
130static __inline__ short ngcppGetValShort(char *buf, int *pos)
131{
132 short value;
133 int len = sizeof(short);
134 memcpy(&value, buf + *pos, (size_t)len);
135 _byte_order(&value, len, len);
136 *pos += len;
137 return (value);
138}
139
143static __inline__ int ngcppGetValInt(char *buf, int *pos)
144{
145 int value;
146 int len = sizeof(int);
147 memcpy(&value, buf + *pos, (size_t)len);
148 _byte_order(&value, len, len);
149 *pos += len;
150 return (value);
151}
152
156static __inline__ float ngcppGetValFloat(char *buf, int *pos)
157{
158 float value;
159 int len = sizeof(float);
160 memcpy(&value, buf + *pos, (size_t)len);
161 _byte_order(&value, len, len);
162 *pos += len;
163 return (value);
164}
165
169static __inline__ double ngcppGetValDouble(char *buf, int *pos)
170{
171 double value;
172 int len = sizeof(double);
173 memcpy(&value, buf + *pos, (size_t)len);
174 _byte_order(&value, len, len);
175 *pos += len;
176 return (value);
177}
178
182static __inline__ void _putVec(char *buf, const void *vec, int size, int *pos,
183 int bc)
184{
185 int len = size * bc;
186 memcpy(buf + *pos, vec, (size_t)len);
187 _byte_order(buf + *pos, len, bc);
188 *pos += len;
189}
190
194static __inline__ void _getVec(char *buf, void *vec, int size, int *pos,
195 int bc)
196{
197 int len = size * bc;
198 memcpy(vec, buf + *pos, (size_t)len);
199 _byte_order(vec, len, bc);
200 *pos += len;
201}
202
206#define ngcppPutVecChar(b,x,y,z) _putVec(b,x,y,z,1)
207
211#define ngcppPutVecShort(b,x,y,z) _putVec(b,x,y,z,2)
212
216#define ngcppPutVecInt(b,x,y,z) _putVec(b,x,y,z,4)
217
221#define ngcppPutVecFloat(b,x,y,z) _putVec(b,x,y,z,4)
222
226#define ngcppPutVecDouble(b,x,y,z) _putVec(b,x,y,z,8)
227
231#define ngcppGetVecChar(b,x,y,z) _getVec(b,x,y,z,1)
232
236#define ngcppGetVecShort(b,x,y,z) _getVec(b,x,y,z,2)
237
241#define ngcppGetVecInt(b,x,y,z) _getVec(b,x,y,z,4)
242
246#define ngcppGetVecFloat(b,x,y,z) _getVec(b,x,y,z,4)
247
251#define ngcppGetVecDouble(b,x,y,z) _getVec(b,x,y,z,8)
252
253#ifdef __cplusplus
254}
255#endif
256
257#endif
void ngcbSwap8(void *buffer, size_t length)
Definition ngcbMath.c:49
void ngcbSwap4(void *buffer, size_t length)
Definition ngcbMath.c:38
void ngcbSwap2(void *buffer, size_t length)
Definition ngcbMath.c:27
#define _ngcpp_swap
Definition ngcppCom.h:22