]> Creatis software - gdcm.git/blob - Testing/TestEnumVR.cxx
Fix mistypings
[gdcm.git] / Testing / TestEnumVR.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestEnumVR.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/11/10 18:02:26 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /*
19  * Proof of concept for using enum instead of string for representing VR
20  * This allows us to:
21  * 1. Qickly check against another VR (faster than string comparison)
22  * 2. Support the advance VR like 'OB or OW'
23  */
24
25 #include <iostream>
26 typedef enum {
27   AE = 1,
28   AS = 2,
29   AT = 4,
30   CS = 8,
31   DA = 16,
32   DS = 32,
33   DT = 64,
34   FL = 128,
35   FD = 256,
36   IS = 512,
37   LO = 1024,
38   LT = 2048,
39   OB = 4096,
40   OW = 8192,
41   PN = 16384,
42   SH = 32768,
43   SL = 65536,
44   SQ = 131072,
45   SS = 262144,
46   ST = 524288,
47   TM = 1048576,
48   UI = 2097152,
49   UL = 4194304,
50   UN = 8388608,
51   US = 16777216,
52   UT = 33554432,
53   OB_OW = OB | OW,
54   US_SS = US | SS,
55   US_SS_OW = US | SS | OW
56 } VR;
57
58 static const char *VRStrings[] = {
59   "AE",
60   "AS",
61   "AT",
62   "CS",
63   "DA",
64   "DS",
65   "DT",
66   "FL",
67   "FD",
68   "IS",
69   "LO",
70   "LT",
71   "OB",
72   "OW",
73   "PN",
74   "SH",
75   "SL",
76   "SQ",
77   "SS",
78   "ST",
79   "TM",
80   "UI",
81   "UL",
82   "UN",
83   "US",
84   "UT",
85   "OB or OW",
86   "US or SS",
87   "US or SS or OW"
88 };
89
90
91 int get_index_vr(VR vr)
92 {
93   int l;
94   switch(vr)
95     {
96   case OB_OW:
97     l =  26;
98     break;
99   case US_SS:
100     l =  27;
101     break;
102   case US_SS_OW:
103     l =  28;
104     break;
105   default:
106       {
107       int a = (int)vr;
108       for (l = 0; a > 1; ++l)
109         a >>= 1;
110       }
111     }
112   return l;
113 }
114
115 int TestEnumVR(int , char *[])
116 {
117   for(int i=0; i<26; i++)
118     {
119     int j = 1 << i;
120     int k = get_index_vr((VR)j);
121     std::cout << k << "," << VRStrings[k] << std::endl;
122     }
123
124    VR vr = OB_OW;
125    int k = get_index_vr(vr);
126    std::cout << k << "," << VRStrings[k] << std::endl;
127    vr = US_SS;
128    k = get_index_vr(vr);
129    std::cout << k << "," << VRStrings[k] << std::endl;
130    vr = US_SS_OW;
131    k = get_index_vr(vr);
132    std::cout << k << "," << VRStrings[k] << std::endl;
133
134    return 0;
135 }