File: TestElement3.cxx

package info (click to toggle)
gdcm 3.0.24-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,856 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (425 lines) | stat: -rw-r--r-- 9,134 bytes parent folder | download | duplicates (2)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include <iostream>
#include <iomanip>
#include <vector>

#include <stdint.h>

struct AE
{
  char Internal[16+1];
  void Print(std::ostream &os) {
    os << Internal;
  }
};

typedef enum {
  DAY = 'D',
  WEEK = 'W',
  MONTH = 'M',
  YEAR = 'Y'
} DateFormat;

//template <int Format> struct ASValid;
//template <> struct ASValid<'Y'> { };
struct AS
{
  unsigned short N;
  unsigned char  Format;
  void Print(std::ostream &os) {
    if( N < 1000 &&
       (Format == 'D' ||
        Format == 'W' ||
        Format == 'M' ||
        Format == 'Y' ))
       {
    os << std::setw(3) << std::setfill('0') << N << Format;
    }
    else
    {
    os << "";
    }
  }
};

struct AT
{
  // Tag Internal;
};

struct CS
{
  char Internal[16];
};

struct DA
{
  unsigned short Year : 12;
  unsigned short Month : 4;
  unsigned short Day : 5;
  void Print(std::ostream &os)
  {
    os << std::setw(4) << std::setfill('0') << Year;
    os << std::setw(2) << std::setfill('0') << Month;
    os << std::setw(2) << std::setfill('0') << Day;
  }
};

struct date {
    unsigned short day   : 5;   // 1 to 31
         unsigned short month : 4;   // 1 to 12
         unsigned short year : 12;  /* 0 to 9999 (technically :11 should be enough for a couple of years...) */
  void Print(std::ostream &os)
  {
    os << year << "." << (int)month << "." << (int)day;

  }
  };

struct DS
{
  double Internal;
  // 16 bytes as integer would mean we can have 10^16 as max int
  // which only double can hold
};


struct FL
{
  float Internal;
};

struct FD
{
  double Internal;
};

struct IS
{
  int Internal;
  void Print(std::ostream &os)
  {
    os << Internal;
  }
};

struct LO
{
  char Internal[64];
  void Print(std::ostream &os) {
    os << Internal;
  }
};

struct LT
{
  std::string Internal;
  void Print(std::ostream &os) {
    os << Internal.size();
    os << std::endl;
    os << Internal;
  }
};


struct OB
{
  explicit OB(const char *array = 0, uint32_t length = 0):Internal(array),Length(length) {}
  void Print( std::ostream &os )
  {
    const char *p = Internal;
    const char *end = Internal+Length;
    while(p != end)
    {
      os << "\\" << (int)*p++;
    }
  }
private:
  const char *Internal;
  uint32_t Length;
};

struct OF;

struct OW;

struct PN
{
  char Component[5][64];
  void Print(std::ostream &os)
  {
    //os << "Family Name Complex: " << Component[0] << std::endl;
    //os << "Given  Name Complex: " << Component[1] << std::endl;
    //os << "Middle Name        : " << Component[2] << std::endl;
    //os << "Name Suffix        : " << Component[3] << std::endl;
    //os << "Name Prefix        : " << Component[4] << std::endl;
    os << Component[0] << "^";
    os << Component[1] << "^";
    os << Component[2] << "^";
    os << Component[3] << "^";
    os << Component[4];
  }
};

struct SH
{
  char Internal[16+1];
};

struct SL
{
  signed long Internal;
};

struct SQ;

struct SS
{
  signed short Internal;
};

struct ST
{
  std::string Internal;
};

struct TM
{
  unsigned short hours:5;
  unsigned short minutes:6;
  unsigned short seconds:6;
  unsigned int fracseconds:20;
  void Print(std::ostream &os) {
    os << std::setw(2) << std::setfill('0') << hours;
    os << std::setw(2) << std::setfill('0') << minutes;
    os << std::setw(2) << std::setfill('0') << seconds;
    os << ".";
    os << std::setw(6) << std::setfill('0') << fracseconds;
  }
};

struct Tri
{
  short Internal:2;
  //operator void *() const { return Internal; }
  operator short () const { return Internal; }
};

struct DT
{
  DA da;
  TM tm;
  Tri OffsetSign;
  unsigned short Hours:5;
  unsigned short Minutes:6;
// YYYYMMDDHHMMSS.FFFFFF&ZZZZ
  void Print ( std::ostream &os)
  {
    da.Print( os );
    tm.Print( os );
    if( OffsetSign )
    {
    if ( OffsetSign == -1 ) os << "-";
    else if ( OffsetSign == +1 ) os << "+";
    else return;
    os << std::setw(2) << std::setfill('0') << Hours;
    os << std::setw(2) << std::setfill('0') << Minutes;
    }
  }
};


struct UI
{
  char Internal[64+1];
  void Print(std::ostream &os) {
    os << strlen(Internal) << std::endl;
    os << Internal;
  }
};

struct UL
{
  unsigned long Internal;
};

struct UN
{
  std::vector<char> Internal;
};

struct US
{
  unsigned short Internal;
};

struct UT
{
  std::string Internal;
};

struct S
{
  union { char s[2]; } Internal;
  //unsigned short Internal;
  void Print( std::ostream &os )
  {
    os << strlen( Internal.s ) << std::endl;
    os << Internal.s;
  }
};

int main()
{
  AE ae = { "application enti" };
  ae.Print( std::cout );
  std::cout << std::endl;

  AS as = { 1, 'Y' };
  as.Print( std::cout );
  std::cout << std::endl;

  DA da = { 10978, 11, 32 };
  da.Print( std::cout );
  std::cout << std::endl;
  std::cout << "DA:" << sizeof (DA) << std::endl;

  double dd = 10*10*10*10*10*10*10*10;
  std::cout << dd << std::endl;
  DS ds = { 10*10*10*10*10*10*10*10 + 1  };
  std::cout << ds.Internal << std::endl;

  DT dt = { 1979, 7, 6 };
  dt.Print( std::cout << "DT: "  );
  std::cout << std::endl;

  DT dt1 = { 1979, 7, 6, 23, 59, 59, 999999 };
  dt1.Print( std::cout << "DT: "  );
  std::cout << std::endl;

  DT dt2 = { 1979, 7, 6, 23, 59, 59, 999999, -1, 12, 42 };
  dt2.Print( std::cout << "DT: "  );
  std::cout << std::endl;

  DT dt3 = { 1979, 7, 6, 23, 59, 59, 999999, +1, 12, 42 };
  dt3.Print( std::cout << "DT: "  );
  std::cout << std::endl;


  IS is = { 2 << 30 };
  is.Print( std::cout );
  std::cout << std::endl;

  //std::cout << 8*8 << std::endl;
  //std::cout << 8*8*8*8 << std::endl;
  date d = {31, 12, 1978 };
  d.Print( std::cout );
  std::cout << std::endl;
  std::cout << "date:" << sizeof (date) << std::endl;


  LO lo = { "coucou" };
  lo.Print( std::cout );
  std::cout << std::endl;

  LT lt = { "very long text\0hello mathieu" };
  lt.Print( std::cout );
  std::cout << std::endl;

  OB ob("\0\1", 2);
  ob.Print( std::cout );
  std::cout << std::endl;

  PN pn1 = { "abc123", "def", "ghi", "klm", "opq" };
  pn1.Print( std::cout );
  std::cout << std::endl;

  PN pn2 = { "malaterre", "mathieu olivier patrick"};
  pn2.Print( std::cout );
  std::cout << std::endl;

// Rev. John Robert Quincy Adams, B.A. M.Div. "Adams^John Robert Quincy^^Rev.^B.A. M.Div." [One family name; three given names; no middle name; one prefix; two suffixes.]
        PN pn3 = { "Adams", "John Robert Quincy", "", "Rev.", "B.A. M.Div." };
  pn3.Print( std::cout );
  std::cout << std::endl;
// Susan Morrison-Jones, Ph.D., Chief Executive Officer "Morrison-Jones^Susan^^^Ph.D., Chief Executive Officer" [Two family names; one given name; no middle name; no prefix; two suffixes.]
        PN pn4 = { "Morrison-Jones", "Susan", "", "", "Ph.D., Chief Executive Officer" };
  pn4.Print( std::cout );
  std::cout << std::endl;

// John Doe "Doe^John" [One family name; one given name; no middle name, prefix, or suffix. Delimiters have been omitted for the three trailing null components.]
        PN pn5 = { "Doe", "John" };
  pn5.Print( std::cout );
  std::cout << std::endl;


// (for examples of the encoding of Person Names using multi-byte character sets see Annex H)
// Smith^Fluffy [A cat, rather than a
//human, whose responsible party family name is Smith, and whose own name is Fluffy]
        PN pn6 = { "Smith", "Fluffy" };
  pn6.Print( std::cout );
  std::cout << std::endl;
//ABC Farms^Running on Water [A horse whose responsible organization is named ABC Farms, and whose name is "Running On Water"]
        PN pn7 = { "ABC Farms", "Running on Water" };
  pn7.Print( std::cout );
  std::cout << std::endl;




  std::cout << "TM:" << sizeof (TM) << std::endl;
  TM tm1 = { 7, 12, 49, 999999 };
  tm1.Print( std::cout );
  std::cout << std::endl;

  TM tm2 = { 23, 59, 59, 999999 };
  tm2.Print( std::cout );
  std::cout << std::endl;

  TM tm3 = { 0, 0, 0, 0 };
  tm3.Print( std::cout );
  std::cout << std::endl;


  UI ui = {
  "1234567890.1234567890.1234567890.1234567890.1234567890.123456789" };
  ui.Print( std::cout );
  std::cout << std::endl;

  //S s = "10";
  S s = { '1' };
  s.Print(std::cout);
  std::cout << std::endl;

  std::cout << "Tri:" << std::endl;
  Tri t1 = { 0 };
  std::cout << t1.Internal << std::endl;
  Tri t2 = { 1 };
  std::cout << t2.Internal << std::endl;
  Tri t3 = { 2 };
  std::cout << t3.Internal << std::endl;
  Tri t4 = { 3 };
  std::cout << t4.Internal << std::endl;
  Tri t5 = { '+' };
  std::cout << t5.Internal << std::endl;
  Tri t6 = { '-' };
  std::cout << t6.Internal << std::endl;
  Tri t7 = { -1 };
  std::cout << t7.Internal << std::endl;

  //DateFormat df = 'Y';

  return 0;
}