1 /*
2 *
3 * Copyright (C) 1998-2010, OFFIS e.V.
4 * All rights reserved. See COPYRIGHT file for details.
5 *
6 * This software and supporting documentation were developed by
7 *
8 * OFFIS e.V.
9 * R&D Division Health
10 * Escherweg 2
11 * D-26121 Oldenburg, Germany
12 *
13 *
14 * Module: dcmpstat
15 *
16 * Author: Marco Eichelberg
17 *
18 * Purpose:
19 * classes: DVPSOverlay_PList
20 *
21 */
22
23 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
24 #include "dcmtk/dcmpstat/dvpsovl.h"
25 #include "dcmtk/dcmpstat/dvpsov.h" /* for DVPSOverlay */
26
27
DVPSOverlay_PList()28 DVPSOverlay_PList::DVPSOverlay_PList()
29 : list_()
30 {
31 }
32
DVPSOverlay_PList(const DVPSOverlay_PList & arg)33 DVPSOverlay_PList::DVPSOverlay_PList(const DVPSOverlay_PList &arg)
34 : list_()
35 {
36 OFListConstIterator(DVPSOverlay *) first = arg.list_.begin();
37 OFListConstIterator(DVPSOverlay *) last = arg.list_.end();
38 while (first != last)
39 {
40 list_.push_back((*first)->clone());
41 ++first;
42 }
43 }
44
~DVPSOverlay_PList()45 DVPSOverlay_PList::~DVPSOverlay_PList()
46 {
47 clear();
48 }
49
clear()50 void DVPSOverlay_PList::clear()
51 {
52 OFListIterator(DVPSOverlay *) first = list_.begin();
53 OFListIterator(DVPSOverlay *) last = list_.end();
54 while (first != last)
55 {
56 delete (*first);
57 first = list_.erase(first);
58 }
59 }
60
read(DcmItem & dset)61 OFCondition DVPSOverlay_PList::read(DcmItem &dset)
62 {
63 OFCondition result = EC_Normal;
64 DcmStack stack;
65 DcmTagKey key(0x6000,0x3000);
66 DVPSOverlay *newOverlay = NULL;
67
68 for (Uint8 i=0; i<16; i+=2)
69 {
70 if (result==EC_Normal)
71 {
72 stack.clear();
73 key.setGroup(0x6000+i);
74 if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
75 {
76 newOverlay = new DVPSOverlay();
77 if (newOverlay)
78 {
79 result = newOverlay->read(dset,i);
80 list_.push_back(newOverlay);
81 } else result = EC_MemoryExhausted;
82 }
83 }
84 }
85 return result;
86 }
87
write(DcmItem & dset)88 OFCondition DVPSOverlay_PList::write(DcmItem &dset)
89 {
90 OFCondition result = EC_Normal;
91 OFListIterator(DVPSOverlay *) first = list_.begin();
92 OFListIterator(DVPSOverlay *) last = list_.end();
93 while (first != last)
94 {
95 if (result==EC_Normal) result = (*first)->write(dset);
96 ++first;
97 }
98 return result;
99 }
100
haveOverlayGroup(Uint16 group)101 OFBool DVPSOverlay_PList::haveOverlayGroup(Uint16 group)
102 {
103 if (getOverlayGroup(group)) return OFTrue; else return OFFalse;
104 }
105
getOverlayGroup(Uint16 group)106 DVPSOverlay *DVPSOverlay_PList::getOverlayGroup(Uint16 group)
107 {
108 Uint8 lowergroup = (Uint8)(group & 0x00FF);
109 OFListIterator(DVPSOverlay *) first = list_.begin();
110 OFListIterator(DVPSOverlay *) last = list_.end();
111 while (first != last)
112 {
113 if ((*first)->getOverlayGroup() == lowergroup) return *first;
114 ++first;
115 }
116 return NULL;
117 }
118
getOverlay(size_t idx)119 DVPSOverlay *DVPSOverlay_PList::getOverlay(size_t idx)
120 {
121 OFListIterator(DVPSOverlay *) first = list_.begin();
122 OFListIterator(DVPSOverlay *) last = list_.end();
123 while (first != last)
124 {
125 if (idx==0) return *first;
126 idx--;
127 ++first;
128 }
129 return NULL;
130 }
131
removeOverlay(size_t idx)132 OFCondition DVPSOverlay_PList::removeOverlay(size_t idx)
133 {
134 OFListIterator(DVPSOverlay *) first = list_.begin();
135 OFListIterator(DVPSOverlay *) last = list_.end();
136 while (first != last)
137 {
138 if (idx==0)
139 {
140 delete (*first);
141 first = list_.erase(first);
142 return EC_Normal;
143 }
144 idx--;
145 ++first;
146 }
147 return EC_IllegalCall;
148 }
149
150
changeOverlayGroup(size_t idx,Uint16 newGroup)151 OFCondition DVPSOverlay_PList::changeOverlayGroup(size_t idx, Uint16 newGroup)
152 {
153 if ((newGroup < 0x6000)||(newGroup > 0x601F)) return EC_IllegalCall;
154 DVPSOverlay *overlay = getOverlay(idx);
155 if (overlay)
156 {
157 if (newGroup == (overlay->getOverlayGroup()+0x6000)) return EC_Normal;
158 if (haveOverlayGroup(newGroup)) return EC_IllegalCall; // don't allocate twice
159 overlay->setOverlayGroup((Uint8)(newGroup-0x6000));
160 return EC_Normal;
161 }
162 return EC_IllegalCall;
163 }
164
addOverlay(DcmItem & overlayIOD,Uint16 groupInItem,Uint16 newGroup)165 OFCondition DVPSOverlay_PList::addOverlay(DcmItem& overlayIOD, Uint16 groupInItem, Uint16 newGroup)
166 {
167 if ((groupInItem < 0x6000)||(groupInItem > 0x601F)) return EC_IllegalCall;
168 if ((newGroup < 0x6000)||(newGroup > 0x601F)) return EC_IllegalCall;
169 if (haveOverlayGroup(newGroup)) return EC_IllegalCall; // don't allocate twice
170
171 DcmStack stack;
172 DcmTagKey key(groupInItem,0x3000);
173 DVPSOverlay *newOverlay = NULL;
174
175 OFCondition result = overlayIOD.search(key, stack, ESM_fromHere, OFFalse);
176 if (EC_Normal == result)
177 {
178 newOverlay = new DVPSOverlay();
179 if (newOverlay)
180 {
181 result = newOverlay->read(overlayIOD,(Uint8)(groupInItem-0x6000), (Uint8)(newGroup-0x6000));
182 if (EC_Normal==result) list_.push_back(newOverlay); else delete newOverlay;
183 } else result = EC_MemoryExhausted;
184 }
185 return result;
186 }
187