Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* $Id$ |
4 |
|
|
* |
5 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
6 |
|
|
* |
7 |
|
|
* This file is part of the pdserv library. |
8 |
|
|
* |
9 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
11 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
12 |
|
|
* your option) any later version. |
13 |
|
|
* |
14 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 |
|
|
* License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
* |
22 |
|
|
*****************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "DataType.h" |
25 |
|
|
#include <assert.h> |
26 |
|
|
#include <stddef.h> |
27 |
|
|
|
28 |
|
|
#include <iostream> |
29 |
|
|
using std::cout; |
30 |
|
|
using std::cerr; |
31 |
|
|
using std::endl; |
32 |
|
|
|
33 |
|
|
using namespace PdServ; |
34 |
|
|
|
35 |
|
|
struct _s2 { |
36 |
|
|
uint32_t f1; |
37 |
|
|
char y[4]; |
38 |
|
|
}; |
39 |
|
|
|
40 |
|
|
struct _s { |
41 |
|
|
uint16_t field1; |
42 |
|
|
uint8_t field4[5]; |
43 |
|
|
struct _s2 v[2]; |
44 |
|
|
double d2; |
45 |
|
|
}; |
46 |
|
|
|
47 |
|
✗ |
int main(int /*argc*/, const char * /*argv*/[]) |
48 |
|
|
{ |
49 |
|
✗ |
DataType* dt = new DataType("struct", sizeof(struct _s)); |
50 |
|
✗ |
DataType* dts2 = new DataType("struct2", sizeof(struct _s2)); |
51 |
|
✗ |
struct _s s[] = { |
52 |
|
|
{55, {88,}, {{98, {1,2,3,4}}, {77, {8,7,6,5}}}, 3.14}, |
53 |
|
|
{16, {89,}, {}, 6.14}, |
54 |
|
|
}; |
55 |
|
✗ |
struct _s s3[4]; |
56 |
|
|
|
57 |
|
✗ |
dt->addField("field1", DataType::uint16, offsetof(struct _s, field1)); |
58 |
|
✗ |
dt->addField("field4", DataType::uint8, offsetof(struct _s, field4), 5); |
59 |
|
✗ |
dt->addField("v", *dts2, offsetof(struct _s, v), 2); |
60 |
|
✗ |
dt->addField("d2", DataType::float64, offsetof(struct _s, d2)); |
61 |
|
|
|
62 |
|
✗ |
dts2->addField("f1", DataType::uint32, offsetof(struct _s2, f1)); |
63 |
|
✗ |
dts2->addField("y", DataType::int8, offsetof(struct _s2, y), 4); |
64 |
|
|
|
65 |
|
✗ |
cout << (*dt)(s,2) << endl; |
66 |
|
✗ |
cout << (*dt)(s3,4) << endl; |
67 |
|
|
|
68 |
|
✗ |
return 0; |
69 |
|
|
} |
70 |
|
|
|