1 /*
2  *
3  *  Copyright (C) 2008-2012, OFFIS e.V. and ICSMED AG, Oldenburg, Germany
4  *  Copyright (C) 2013-2017, J. Riesmeier, Oldenburg, Germany
5  *  All rights reserved.  See COPYRIGHT file for details.
6  *
7  *  Source file for class DRTShieldingDeviceSequence
8  *
9  *  Generated automatically from DICOM PS 3.3-2017e
10  *  File created on 2017-12-05 09:30:54
11  *
12  */
13 
14 
15 #include "dcmtk/config/osconfig.h"     // make sure OS specific configuration is included first
16 
17 #include "dcmtk/dcmrt/seq/drtshds.h"
18 
19 
20 // --- item class ---
21 
Item(const OFBool emptyDefaultItem)22 DRTShieldingDeviceSequence::Item::Item(const OFBool emptyDefaultItem)
23   : EmptyDefaultItem(emptyDefaultItem),
24     AccessoryCode(DCM_AccessoryCode),
25     ShieldingDeviceDescription(DCM_ShieldingDeviceDescription),
26     ShieldingDeviceLabel(DCM_ShieldingDeviceLabel),
27     ShieldingDevicePosition(DCM_ShieldingDevicePosition),
28     ShieldingDeviceType(DCM_ShieldingDeviceType)
29 {
30 }
31 
32 
Item(const Item & copy)33 DRTShieldingDeviceSequence::Item::Item(const Item &copy)
34   : EmptyDefaultItem(copy.EmptyDefaultItem),
35     AccessoryCode(copy.AccessoryCode),
36     ShieldingDeviceDescription(copy.ShieldingDeviceDescription),
37     ShieldingDeviceLabel(copy.ShieldingDeviceLabel),
38     ShieldingDevicePosition(copy.ShieldingDevicePosition),
39     ShieldingDeviceType(copy.ShieldingDeviceType)
40 {
41 }
42 
43 
~Item()44 DRTShieldingDeviceSequence::Item::~Item()
45 {
46 }
47 
48 
operator =(const Item & copy)49 DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::Item::operator=(const Item &copy)
50 {
51     if (this != &copy)
52     {
53         EmptyDefaultItem = copy.EmptyDefaultItem;
54         AccessoryCode = copy.AccessoryCode;
55         ShieldingDeviceDescription = copy.ShieldingDeviceDescription;
56         ShieldingDeviceLabel = copy.ShieldingDeviceLabel;
57         ShieldingDevicePosition = copy.ShieldingDevicePosition;
58         ShieldingDeviceType = copy.ShieldingDeviceType;
59     }
60     return *this;
61 }
62 
63 
clear()64 void DRTShieldingDeviceSequence::Item::clear()
65 {
66     if (!EmptyDefaultItem)
67     {
68         /* clear all DICOM attributes */
69         ShieldingDeviceType.clear();
70         ShieldingDeviceLabel.clear();
71         ShieldingDeviceDescription.clear();
72         ShieldingDevicePosition.clear();
73         AccessoryCode.clear();
74     }
75 }
76 
77 
isEmpty()78 OFBool DRTShieldingDeviceSequence::Item::isEmpty()
79 {
80     return ShieldingDeviceType.isEmpty() &&
81            ShieldingDeviceLabel.isEmpty() &&
82            ShieldingDeviceDescription.isEmpty() &&
83            ShieldingDevicePosition.isEmpty() &&
84            AccessoryCode.isEmpty();
85 }
86 
87 
isValid() const88 OFBool DRTShieldingDeviceSequence::Item::isValid() const
89 {
90     return !EmptyDefaultItem;
91 }
92 
93 
read(DcmItem & item)94 OFCondition DRTShieldingDeviceSequence::Item::read(DcmItem &item)
95 {
96     OFCondition result = EC_IllegalCall;
97     if (!EmptyDefaultItem)
98     {
99         /* re-initialize object */
100         clear();
101         getAndCheckElementFromDataset(item, ShieldingDeviceType, "1", "1", "ShieldingDeviceSequence");
102         getAndCheckElementFromDataset(item, ShieldingDeviceLabel, "1", "2", "ShieldingDeviceSequence");
103         getAndCheckElementFromDataset(item, ShieldingDeviceDescription, "1", "3", "ShieldingDeviceSequence");
104         getAndCheckElementFromDataset(item, ShieldingDevicePosition, "1", "3", "ShieldingDeviceSequence");
105         getAndCheckElementFromDataset(item, AccessoryCode, "1", "3", "ShieldingDeviceSequence");
106         result = EC_Normal;
107     }
108     return result;
109 }
110 
111 
write(DcmItem & item)112 OFCondition DRTShieldingDeviceSequence::Item::write(DcmItem &item)
113 {
114     OFCondition result = EC_IllegalCall;
115     if (!EmptyDefaultItem)
116     {
117         result = EC_Normal;
118         addElementToDataset(result, item, new DcmCodeString(ShieldingDeviceType), "1", "1", "ShieldingDeviceSequence");
119         addElementToDataset(result, item, new DcmShortString(ShieldingDeviceLabel), "1", "2", "ShieldingDeviceSequence");
120         addElementToDataset(result, item, new DcmShortText(ShieldingDeviceDescription), "1", "3", "ShieldingDeviceSequence");
121         addElementToDataset(result, item, new DcmShortString(ShieldingDevicePosition), "1", "3", "ShieldingDeviceSequence");
122         addElementToDataset(result, item, new DcmLongString(AccessoryCode), "1", "3", "ShieldingDeviceSequence");
123     }
124     return result;
125 }
126 
127 
getAccessoryCode(OFString & value,const signed long pos) const128 OFCondition DRTShieldingDeviceSequence::Item::getAccessoryCode(OFString &value, const signed long pos) const
129 {
130     if (EmptyDefaultItem)
131         return EC_IllegalCall;
132     else
133         return getStringValueFromElement(AccessoryCode, value, pos);
134 }
135 
136 
getShieldingDeviceDescription(OFString & value,const signed long pos) const137 OFCondition DRTShieldingDeviceSequence::Item::getShieldingDeviceDescription(OFString &value, const signed long pos) const
138 {
139     if (EmptyDefaultItem)
140         return EC_IllegalCall;
141     else
142         return getStringValueFromElement(ShieldingDeviceDescription, value, pos);
143 }
144 
145 
getShieldingDeviceLabel(OFString & value,const signed long pos) const146 OFCondition DRTShieldingDeviceSequence::Item::getShieldingDeviceLabel(OFString &value, const signed long pos) const
147 {
148     if (EmptyDefaultItem)
149         return EC_IllegalCall;
150     else
151         return getStringValueFromElement(ShieldingDeviceLabel, value, pos);
152 }
153 
154 
getShieldingDevicePosition(OFString & value,const signed long pos) const155 OFCondition DRTShieldingDeviceSequence::Item::getShieldingDevicePosition(OFString &value, const signed long pos) const
156 {
157     if (EmptyDefaultItem)
158         return EC_IllegalCall;
159     else
160         return getStringValueFromElement(ShieldingDevicePosition, value, pos);
161 }
162 
163 
getShieldingDeviceType(OFString & value,const signed long pos) const164 OFCondition DRTShieldingDeviceSequence::Item::getShieldingDeviceType(OFString &value, const signed long pos) const
165 {
166     if (EmptyDefaultItem)
167         return EC_IllegalCall;
168     else
169         return getStringValueFromElement(ShieldingDeviceType, value, pos);
170 }
171 
172 
setAccessoryCode(const OFString & value,const OFBool check)173 OFCondition DRTShieldingDeviceSequence::Item::setAccessoryCode(const OFString &value, const OFBool check)
174 {
175     OFCondition result = EC_IllegalCall;
176     if (!EmptyDefaultItem)
177     {
178         result = (check) ? DcmLongString::checkStringValue(value, "1") : EC_Normal;
179         if (result.good())
180             result = AccessoryCode.putOFStringArray(value);
181     }
182     return result;
183 }
184 
185 
setShieldingDeviceDescription(const OFString & value,const OFBool check)186 OFCondition DRTShieldingDeviceSequence::Item::setShieldingDeviceDescription(const OFString &value, const OFBool check)
187 {
188     OFCondition result = EC_IllegalCall;
189     if (!EmptyDefaultItem)
190     {
191         result = (check) ? DcmShortText::checkStringValue(value) : EC_Normal;
192         if (result.good())
193             result = ShieldingDeviceDescription.putOFStringArray(value);
194     }
195     return result;
196 }
197 
198 
setShieldingDeviceLabel(const OFString & value,const OFBool check)199 OFCondition DRTShieldingDeviceSequence::Item::setShieldingDeviceLabel(const OFString &value, const OFBool check)
200 {
201     OFCondition result = EC_IllegalCall;
202     if (!EmptyDefaultItem)
203     {
204         result = (check) ? DcmShortString::checkStringValue(value, "1") : EC_Normal;
205         if (result.good())
206             result = ShieldingDeviceLabel.putOFStringArray(value);
207     }
208     return result;
209 }
210 
211 
setShieldingDevicePosition(const OFString & value,const OFBool check)212 OFCondition DRTShieldingDeviceSequence::Item::setShieldingDevicePosition(const OFString &value, const OFBool check)
213 {
214     OFCondition result = EC_IllegalCall;
215     if (!EmptyDefaultItem)
216     {
217         result = (check) ? DcmShortString::checkStringValue(value, "1") : EC_Normal;
218         if (result.good())
219             result = ShieldingDevicePosition.putOFStringArray(value);
220     }
221     return result;
222 }
223 
224 
setShieldingDeviceType(const OFString & value,const OFBool check)225 OFCondition DRTShieldingDeviceSequence::Item::setShieldingDeviceType(const OFString &value, const OFBool check)
226 {
227     OFCondition result = EC_IllegalCall;
228     if (!EmptyDefaultItem)
229     {
230         result = (check) ? DcmCodeString::checkStringValue(value, "1") : EC_Normal;
231         if (result.good())
232             result = ShieldingDeviceType.putOFStringArray(value);
233     }
234     return result;
235 }
236 
237 
238 // --- sequence class ---
239 
DRTShieldingDeviceSequence(const OFBool emptyDefaultSequence)240 DRTShieldingDeviceSequence::DRTShieldingDeviceSequence(const OFBool emptyDefaultSequence)
241   : EmptyDefaultSequence(emptyDefaultSequence),
242     SequenceOfItems(),
243     CurrentItem(),
244     EmptyItem(OFTrue /*emptyDefaultItem*/)
245 {
246     CurrentItem = SequenceOfItems.end();
247 }
248 
249 
DRTShieldingDeviceSequence(const DRTShieldingDeviceSequence & copy)250 DRTShieldingDeviceSequence::DRTShieldingDeviceSequence(const DRTShieldingDeviceSequence &copy)
251   : EmptyDefaultSequence(copy.EmptyDefaultSequence),
252     SequenceOfItems(),
253     CurrentItem(),
254     EmptyItem(OFTrue /*emptyDefaultItem*/)
255 {
256     /* create a copy of the internal sequence of items */
257     Item *item = NULL;
258     OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
259     const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
260     while (current != last)
261     {
262         item = new Item(**current);
263         if (item != NULL)
264         {
265             SequenceOfItems.push_back(item);
266         } else {
267             /* memory exhausted, there is nothing we can do about it */
268             break;
269         }
270         ++current;
271     }
272     CurrentItem = SequenceOfItems.begin();
273 }
274 
275 
operator =(const DRTShieldingDeviceSequence & copy)276 DRTShieldingDeviceSequence &DRTShieldingDeviceSequence::operator=(const DRTShieldingDeviceSequence &copy)
277 {
278     if (this != &copy)
279     {
280         clear();
281         EmptyDefaultSequence = copy.EmptyDefaultSequence;
282         /* create a copy of the internal sequence of items */
283         Item *item = NULL;
284         OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
285         const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
286         while (current != last)
287         {
288             item = new Item(**current);
289             if (item != NULL)
290             {
291                 SequenceOfItems.push_back(item);
292             } else {
293                 /* memory exhausted, there is nothing we can do about it */
294                 break;
295             }
296             ++current;
297         }
298         CurrentItem = SequenceOfItems.begin();
299     }
300     return *this;
301 }
302 
303 
~DRTShieldingDeviceSequence()304 DRTShieldingDeviceSequence::~DRTShieldingDeviceSequence()
305 {
306     clear();
307 }
308 
309 
clear()310 void DRTShieldingDeviceSequence::clear()
311 {
312     if (!EmptyDefaultSequence)
313     {
314         CurrentItem = SequenceOfItems.begin();
315         const OFListConstIterator(Item *) last = SequenceOfItems.end();
316         /* delete all items and free memory */
317         while (CurrentItem != last)
318         {
319             delete (*CurrentItem);
320             CurrentItem = SequenceOfItems.erase(CurrentItem);
321         }
322         /* make sure that the list is empty */
323         SequenceOfItems.clear();
324         CurrentItem = SequenceOfItems.end();
325     }
326 }
327 
328 
isEmpty()329 OFBool DRTShieldingDeviceSequence::isEmpty()
330 {
331     return SequenceOfItems.empty();
332 }
333 
334 
isValid() const335 OFBool DRTShieldingDeviceSequence::isValid() const
336 {
337     return !EmptyDefaultSequence;
338 }
339 
340 
getNumberOfItems() const341 size_t DRTShieldingDeviceSequence::getNumberOfItems() const
342 {
343     return SequenceOfItems.size();
344 }
345 
346 
gotoFirstItem()347 OFCondition DRTShieldingDeviceSequence::gotoFirstItem()
348 {
349     OFCondition result = EC_IllegalCall;
350     if (!SequenceOfItems.empty())
351     {
352         CurrentItem = SequenceOfItems.begin();
353         result = EC_Normal;
354     }
355     return result;
356 }
357 
358 
gotoNextItem()359 OFCondition DRTShieldingDeviceSequence::gotoNextItem()
360 {
361     OFCondition result = EC_IllegalCall;
362     if (CurrentItem != SequenceOfItems.end())
363     {
364         ++CurrentItem;
365         result = EC_Normal;
366     }
367     return result;
368 }
369 
370 
gotoItem(const size_t num,OFListIterator (Item *)& iterator)371 OFCondition DRTShieldingDeviceSequence::gotoItem(const size_t num, OFListIterator(Item *) &iterator)
372 {
373     OFCondition result = EC_IllegalCall;
374     if (!SequenceOfItems.empty())
375     {
376         size_t idx = num + 1;
377         iterator = SequenceOfItems.begin();
378         const OFListConstIterator(Item *) last = SequenceOfItems.end();
379         while ((--idx > 0) && (iterator != last))
380             ++iterator;
381         /* specified list item found? */
382         if ((idx == 0) && (iterator != last))
383             result = EC_Normal;
384         else
385             result = EC_IllegalParameter;
386     }
387     return result;
388 }
389 
390 
gotoItem(const size_t num,OFListConstIterator (Item *)& iterator) const391 OFCondition DRTShieldingDeviceSequence::gotoItem(const size_t num, OFListConstIterator(Item *) &iterator) const
392 {
393     OFCondition result = EC_IllegalCall;
394     if (!SequenceOfItems.empty())
395     {
396         size_t idx = num + 1;
397         iterator = SequenceOfItems.begin();
398         const OFListConstIterator(Item *) last = SequenceOfItems.end();
399         while ((--idx > 0) && (iterator != last))
400             ++iterator;
401         /* specified list item found? */
402         if ((idx == 0) && (iterator != last))
403             result = EC_Normal;
404         else
405             result = EC_IllegalParameter;
406     }
407     return result;
408 }
409 
410 
gotoItem(const size_t num)411 OFCondition DRTShieldingDeviceSequence::gotoItem(const size_t num)
412 {
413     return gotoItem(num, CurrentItem);
414 }
415 
416 
getCurrentItem(Item * & item) const417 OFCondition DRTShieldingDeviceSequence::getCurrentItem(Item *&item) const
418 {
419     OFCondition result = EC_IllegalCall;
420     if (CurrentItem != SequenceOfItems.end())
421     {
422         item = *CurrentItem;
423         result = EC_Normal;
424     }
425     return result;
426 }
427 
428 
getCurrentItem()429 DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::getCurrentItem()
430 {
431     if (CurrentItem != SequenceOfItems.end())
432         return **CurrentItem;
433     else
434         return EmptyItem;
435 }
436 
437 
getCurrentItem() const438 const DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::getCurrentItem() const
439 {
440     if (CurrentItem != SequenceOfItems.end())
441         return **CurrentItem;
442     else
443         return EmptyItem;
444 }
445 
446 
getItem(const size_t num,Item * & item)447 OFCondition DRTShieldingDeviceSequence::getItem(const size_t num, Item *&item)
448 {
449     OFListIterator(Item *) iterator;
450     OFCondition result = gotoItem(num, iterator);
451     if (result.good())
452         item = *iterator;
453     return result;
454 }
455 
456 
getItem(const size_t num)457 DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::getItem(const size_t num)
458 {
459     OFListIterator(Item *) iterator;
460     if (gotoItem(num, iterator).good())
461         return **iterator;
462     else
463         return EmptyItem;
464 }
465 
466 
getItem(const size_t num) const467 const DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::getItem(const size_t num) const
468 {
469     OFListConstIterator(Item *) iterator;
470     if (gotoItem(num, iterator).good())
471         return **iterator;
472     else
473         return EmptyItem;
474 }
475 
476 
operator [](const size_t num)477 DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::operator[](const size_t num)
478 {
479     return getItem(num);
480 }
481 
482 
operator [](const size_t num) const483 const DRTShieldingDeviceSequence::Item &DRTShieldingDeviceSequence::operator[](const size_t num) const
484 {
485     return getItem(num);
486 }
487 
488 
addItem(Item * & item)489 OFCondition DRTShieldingDeviceSequence::addItem(Item *&item)
490 {
491     OFCondition result = EC_IllegalCall;
492     if (!EmptyDefaultSequence)
493     {
494         item = new Item();
495         if (item != NULL)
496         {
497             SequenceOfItems.push_back(item);
498             result = EC_Normal;
499         } else
500             result = EC_MemoryExhausted;
501     }
502     return result;
503 }
504 
505 
insertItem(const size_t pos,Item * & item)506 OFCondition DRTShieldingDeviceSequence::insertItem(const size_t pos, Item *&item)
507 {
508     OFCondition result = EC_IllegalCall;
509     if (!EmptyDefaultSequence)
510     {
511         OFListIterator(Item *) iterator;
512         result = gotoItem(pos, iterator);
513         if (result.good())
514         {
515             item = new Item();
516             if (item != NULL)
517             {
518                 SequenceOfItems.insert(iterator, 1, item);
519                 result = EC_Normal;
520             } else
521                 result = EC_MemoryExhausted;
522         } else
523             result = addItem(item);
524     }
525     return result;
526 }
527 
528 
removeItem(const size_t pos)529 OFCondition DRTShieldingDeviceSequence::removeItem(const size_t pos)
530 {
531     OFCondition result = EC_IllegalCall;
532     if (!EmptyDefaultSequence)
533     {
534         OFListIterator(Item *) iterator;
535         if (gotoItem(pos, iterator).good())
536         {
537             delete *iterator;
538             iterator = SequenceOfItems.erase(iterator);
539             result = EC_Normal;
540         } else
541             result = EC_IllegalParameter;
542     }
543     return result;
544 }
545 
546 
read(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)547 OFCondition DRTShieldingDeviceSequence::read(DcmItem &dataset,
548                                              const OFString &card,
549                                              const OFString &type,
550                                              const char *moduleName)
551 {
552     OFCondition result = EC_IllegalCall;
553     if (!EmptyDefaultSequence)
554     {
555         /* re-initialize object */
556         clear();
557         /* retrieve sequence element from dataset */
558         DcmSequenceOfItems *sequence;
559         result = dataset.findAndGetSequence(DCM_ShieldingDeviceSequence, sequence);
560         if (sequence != NULL)
561         {
562             if (checkElementValue(*sequence, card, type, result, moduleName))
563             {
564                 DcmStack stack;
565                 OFBool first = OFTrue;
566                 /* iterate over all sequence items */
567                 while (result.good() && sequence->nextObject(stack, first /*intoSub*/).good())
568                 {
569                     DcmItem *ditem = OFstatic_cast(DcmItem *, stack.top());
570                     if (ditem != NULL)
571                     {
572                         Item *item = new Item();
573                         if (item != NULL)
574                         {
575                             result = item->read(*ditem);
576                             if (result.good())
577                             {
578                                 /* append new item to the end of the list */
579                                 SequenceOfItems.push_back(item);
580                                 first = OFFalse;
581                             }
582                         } else
583                             result = EC_MemoryExhausted;
584                     } else
585                         result = EC_CorruptedData;
586                 }
587             }
588         } else {
589             DcmSequenceOfItems element(DCM_ShieldingDeviceSequence);
590             checkElementValue(element, card, type, result, moduleName);
591         }
592     }
593     return result;
594 }
595 
596 
write(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)597 OFCondition DRTShieldingDeviceSequence::write(DcmItem &dataset,
598                                               const OFString &card,
599                                               const OFString &type,
600                                               const char *moduleName)
601 {
602     OFCondition result = EC_IllegalCall;
603     if (!EmptyDefaultSequence)
604     {
605         result = EC_MemoryExhausted;
606         DcmSequenceOfItems *sequence = new DcmSequenceOfItems(DCM_ShieldingDeviceSequence);
607         if (sequence != NULL)
608         {
609             result = EC_Normal;
610             /* an empty optional sequence is not written */
611             if ((type == "2") || !SequenceOfItems.empty())
612             {
613                 OFListIterator(Item *) iterator = SequenceOfItems.begin();
614                 const OFListConstIterator(Item *) last = SequenceOfItems.end();
615                 /* iterate over all sequence items */
616                 while (result.good() && (iterator != last))
617                 {
618                     DcmItem *item = new DcmItem();
619                     if (item != NULL)
620                     {
621                         /* append new item to the end of the sequence */
622                         result = sequence->append(item);
623                         if (result.good())
624                         {
625                             result = (*iterator)->write(*item);
626                             ++iterator;
627                         } else
628                             delete item;
629                     } else
630                         result = EC_MemoryExhausted;
631                 }
632                 if (result.good())
633                 {
634                     /* insert sequence element into the dataset */
635                     result = dataset.insert(sequence, OFTrue /*replaceOld*/);
636                 }
637                 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
638                     checkElementValue(*sequence, card, type, result, moduleName);
639                 if (result.good())
640                 {
641                     /* forget reference to sequence object (avoid deletion below) */
642                     sequence = NULL;
643                 }
644             }
645             else if (type == "1")
646             {
647                 /* empty type 1 sequence not allowed */
648                 result = RT_EC_InvalidValue;
649                 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
650                     checkElementValue(*sequence, card, type, result, moduleName);
651             }
652             /* delete sequence (if not inserted into the dataset) */
653             delete sequence;
654         }
655     }
656     return result;
657 }
658 
659 
660 // end of source file
661