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