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 DRTPrimaryFluenceModeSequence
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/drtpfms.h"
18
19
20 // --- item class ---
21
Item(const OFBool emptyDefaultItem)22 DRTPrimaryFluenceModeSequence::Item::Item(const OFBool emptyDefaultItem)
23 : EmptyDefaultItem(emptyDefaultItem),
24 FluenceMode(DCM_FluenceMode),
25 FluenceModeID(DCM_FluenceModeID)
26 {
27 }
28
29
Item(const Item & copy)30 DRTPrimaryFluenceModeSequence::Item::Item(const Item ©)
31 : EmptyDefaultItem(copy.EmptyDefaultItem),
32 FluenceMode(copy.FluenceMode),
33 FluenceModeID(copy.FluenceModeID)
34 {
35 }
36
37
~Item()38 DRTPrimaryFluenceModeSequence::Item::~Item()
39 {
40 }
41
42
operator =(const Item & copy)43 DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::Item::operator=(const Item ©)
44 {
45 if (this != ©)
46 {
47 EmptyDefaultItem = copy.EmptyDefaultItem;
48 FluenceMode = copy.FluenceMode;
49 FluenceModeID = copy.FluenceModeID;
50 }
51 return *this;
52 }
53
54
clear()55 void DRTPrimaryFluenceModeSequence::Item::clear()
56 {
57 if (!EmptyDefaultItem)
58 {
59 /* clear all DICOM attributes */
60 FluenceMode.clear();
61 FluenceModeID.clear();
62 }
63 }
64
65
isEmpty()66 OFBool DRTPrimaryFluenceModeSequence::Item::isEmpty()
67 {
68 return FluenceMode.isEmpty() &&
69 FluenceModeID.isEmpty();
70 }
71
72
isValid() const73 OFBool DRTPrimaryFluenceModeSequence::Item::isValid() const
74 {
75 return !EmptyDefaultItem;
76 }
77
78
read(DcmItem & item)79 OFCondition DRTPrimaryFluenceModeSequence::Item::read(DcmItem &item)
80 {
81 OFCondition result = EC_IllegalCall;
82 if (!EmptyDefaultItem)
83 {
84 /* re-initialize object */
85 clear();
86 getAndCheckElementFromDataset(item, FluenceMode, "1", "1", "PrimaryFluenceModeSequence");
87 getAndCheckElementFromDataset(item, FluenceModeID, "1", "1C", "PrimaryFluenceModeSequence");
88 result = EC_Normal;
89 }
90 return result;
91 }
92
93
write(DcmItem & item)94 OFCondition DRTPrimaryFluenceModeSequence::Item::write(DcmItem &item)
95 {
96 OFCondition result = EC_IllegalCall;
97 if (!EmptyDefaultItem)
98 {
99 result = EC_Normal;
100 addElementToDataset(result, item, new DcmCodeString(FluenceMode), "1", "1", "PrimaryFluenceModeSequence");
101 addElementToDataset(result, item, new DcmShortString(FluenceModeID), "1", "1C", "PrimaryFluenceModeSequence");
102 }
103 return result;
104 }
105
106
getFluenceMode(OFString & value,const signed long pos) const107 OFCondition DRTPrimaryFluenceModeSequence::Item::getFluenceMode(OFString &value, const signed long pos) const
108 {
109 if (EmptyDefaultItem)
110 return EC_IllegalCall;
111 else
112 return getStringValueFromElement(FluenceMode, value, pos);
113 }
114
115
getFluenceModeID(OFString & value,const signed long pos) const116 OFCondition DRTPrimaryFluenceModeSequence::Item::getFluenceModeID(OFString &value, const signed long pos) const
117 {
118 if (EmptyDefaultItem)
119 return EC_IllegalCall;
120 else
121 return getStringValueFromElement(FluenceModeID, value, pos);
122 }
123
124
setFluenceMode(const OFString & value,const OFBool check)125 OFCondition DRTPrimaryFluenceModeSequence::Item::setFluenceMode(const OFString &value, const OFBool check)
126 {
127 OFCondition result = EC_IllegalCall;
128 if (!EmptyDefaultItem)
129 {
130 result = (check) ? DcmCodeString::checkStringValue(value, "1") : EC_Normal;
131 if (result.good())
132 result = FluenceMode.putOFStringArray(value);
133 }
134 return result;
135 }
136
137
setFluenceModeID(const OFString & value,const OFBool check)138 OFCondition DRTPrimaryFluenceModeSequence::Item::setFluenceModeID(const OFString &value, const OFBool check)
139 {
140 OFCondition result = EC_IllegalCall;
141 if (!EmptyDefaultItem)
142 {
143 result = (check) ? DcmShortString::checkStringValue(value, "1") : EC_Normal;
144 if (result.good())
145 result = FluenceModeID.putOFStringArray(value);
146 }
147 return result;
148 }
149
150
151 // --- sequence class ---
152
DRTPrimaryFluenceModeSequence(const OFBool emptyDefaultSequence)153 DRTPrimaryFluenceModeSequence::DRTPrimaryFluenceModeSequence(const OFBool emptyDefaultSequence)
154 : EmptyDefaultSequence(emptyDefaultSequence),
155 SequenceOfItems(),
156 CurrentItem(),
157 EmptyItem(OFTrue /*emptyDefaultItem*/)
158 {
159 CurrentItem = SequenceOfItems.end();
160 }
161
162
DRTPrimaryFluenceModeSequence(const DRTPrimaryFluenceModeSequence & copy)163 DRTPrimaryFluenceModeSequence::DRTPrimaryFluenceModeSequence(const DRTPrimaryFluenceModeSequence ©)
164 : EmptyDefaultSequence(copy.EmptyDefaultSequence),
165 SequenceOfItems(),
166 CurrentItem(),
167 EmptyItem(OFTrue /*emptyDefaultItem*/)
168 {
169 /* create a copy of the internal sequence of items */
170 Item *item = NULL;
171 OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
172 const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
173 while (current != last)
174 {
175 item = new Item(**current);
176 if (item != NULL)
177 {
178 SequenceOfItems.push_back(item);
179 } else {
180 /* memory exhausted, there is nothing we can do about it */
181 break;
182 }
183 ++current;
184 }
185 CurrentItem = SequenceOfItems.begin();
186 }
187
188
operator =(const DRTPrimaryFluenceModeSequence & copy)189 DRTPrimaryFluenceModeSequence &DRTPrimaryFluenceModeSequence::operator=(const DRTPrimaryFluenceModeSequence ©)
190 {
191 if (this != ©)
192 {
193 clear();
194 EmptyDefaultSequence = copy.EmptyDefaultSequence;
195 /* create a copy of the internal sequence of items */
196 Item *item = NULL;
197 OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
198 const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
199 while (current != last)
200 {
201 item = new Item(**current);
202 if (item != NULL)
203 {
204 SequenceOfItems.push_back(item);
205 } else {
206 /* memory exhausted, there is nothing we can do about it */
207 break;
208 }
209 ++current;
210 }
211 CurrentItem = SequenceOfItems.begin();
212 }
213 return *this;
214 }
215
216
~DRTPrimaryFluenceModeSequence()217 DRTPrimaryFluenceModeSequence::~DRTPrimaryFluenceModeSequence()
218 {
219 clear();
220 }
221
222
clear()223 void DRTPrimaryFluenceModeSequence::clear()
224 {
225 if (!EmptyDefaultSequence)
226 {
227 CurrentItem = SequenceOfItems.begin();
228 const OFListConstIterator(Item *) last = SequenceOfItems.end();
229 /* delete all items and free memory */
230 while (CurrentItem != last)
231 {
232 delete (*CurrentItem);
233 CurrentItem = SequenceOfItems.erase(CurrentItem);
234 }
235 /* make sure that the list is empty */
236 SequenceOfItems.clear();
237 CurrentItem = SequenceOfItems.end();
238 }
239 }
240
241
isEmpty()242 OFBool DRTPrimaryFluenceModeSequence::isEmpty()
243 {
244 return SequenceOfItems.empty();
245 }
246
247
isValid() const248 OFBool DRTPrimaryFluenceModeSequence::isValid() const
249 {
250 return !EmptyDefaultSequence;
251 }
252
253
getNumberOfItems() const254 size_t DRTPrimaryFluenceModeSequence::getNumberOfItems() const
255 {
256 return SequenceOfItems.size();
257 }
258
259
gotoFirstItem()260 OFCondition DRTPrimaryFluenceModeSequence::gotoFirstItem()
261 {
262 OFCondition result = EC_IllegalCall;
263 if (!SequenceOfItems.empty())
264 {
265 CurrentItem = SequenceOfItems.begin();
266 result = EC_Normal;
267 }
268 return result;
269 }
270
271
gotoNextItem()272 OFCondition DRTPrimaryFluenceModeSequence::gotoNextItem()
273 {
274 OFCondition result = EC_IllegalCall;
275 if (CurrentItem != SequenceOfItems.end())
276 {
277 ++CurrentItem;
278 result = EC_Normal;
279 }
280 return result;
281 }
282
283
gotoItem(const size_t num,OFListIterator (Item *)& iterator)284 OFCondition DRTPrimaryFluenceModeSequence::gotoItem(const size_t num, OFListIterator(Item *) &iterator)
285 {
286 OFCondition result = EC_IllegalCall;
287 if (!SequenceOfItems.empty())
288 {
289 size_t idx = num + 1;
290 iterator = SequenceOfItems.begin();
291 const OFListConstIterator(Item *) last = SequenceOfItems.end();
292 while ((--idx > 0) && (iterator != last))
293 ++iterator;
294 /* specified list item found? */
295 if ((idx == 0) && (iterator != last))
296 result = EC_Normal;
297 else
298 result = EC_IllegalParameter;
299 }
300 return result;
301 }
302
303
gotoItem(const size_t num,OFListConstIterator (Item *)& iterator) const304 OFCondition DRTPrimaryFluenceModeSequence::gotoItem(const size_t num, OFListConstIterator(Item *) &iterator) const
305 {
306 OFCondition result = EC_IllegalCall;
307 if (!SequenceOfItems.empty())
308 {
309 size_t idx = num + 1;
310 iterator = SequenceOfItems.begin();
311 const OFListConstIterator(Item *) last = SequenceOfItems.end();
312 while ((--idx > 0) && (iterator != last))
313 ++iterator;
314 /* specified list item found? */
315 if ((idx == 0) && (iterator != last))
316 result = EC_Normal;
317 else
318 result = EC_IllegalParameter;
319 }
320 return result;
321 }
322
323
gotoItem(const size_t num)324 OFCondition DRTPrimaryFluenceModeSequence::gotoItem(const size_t num)
325 {
326 return gotoItem(num, CurrentItem);
327 }
328
329
getCurrentItem(Item * & item) const330 OFCondition DRTPrimaryFluenceModeSequence::getCurrentItem(Item *&item) const
331 {
332 OFCondition result = EC_IllegalCall;
333 if (CurrentItem != SequenceOfItems.end())
334 {
335 item = *CurrentItem;
336 result = EC_Normal;
337 }
338 return result;
339 }
340
341
getCurrentItem()342 DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::getCurrentItem()
343 {
344 if (CurrentItem != SequenceOfItems.end())
345 return **CurrentItem;
346 else
347 return EmptyItem;
348 }
349
350
getCurrentItem() const351 const DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::getCurrentItem() const
352 {
353 if (CurrentItem != SequenceOfItems.end())
354 return **CurrentItem;
355 else
356 return EmptyItem;
357 }
358
359
getItem(const size_t num,Item * & item)360 OFCondition DRTPrimaryFluenceModeSequence::getItem(const size_t num, Item *&item)
361 {
362 OFListIterator(Item *) iterator;
363 OFCondition result = gotoItem(num, iterator);
364 if (result.good())
365 item = *iterator;
366 return result;
367 }
368
369
getItem(const size_t num)370 DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::getItem(const size_t num)
371 {
372 OFListIterator(Item *) iterator;
373 if (gotoItem(num, iterator).good())
374 return **iterator;
375 else
376 return EmptyItem;
377 }
378
379
getItem(const size_t num) const380 const DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::getItem(const size_t num) const
381 {
382 OFListConstIterator(Item *) iterator;
383 if (gotoItem(num, iterator).good())
384 return **iterator;
385 else
386 return EmptyItem;
387 }
388
389
operator [](const size_t num)390 DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::operator[](const size_t num)
391 {
392 return getItem(num);
393 }
394
395
operator [](const size_t num) const396 const DRTPrimaryFluenceModeSequence::Item &DRTPrimaryFluenceModeSequence::operator[](const size_t num) const
397 {
398 return getItem(num);
399 }
400
401
addItem(Item * & item)402 OFCondition DRTPrimaryFluenceModeSequence::addItem(Item *&item)
403 {
404 OFCondition result = EC_IllegalCall;
405 if (!EmptyDefaultSequence)
406 {
407 item = new Item();
408 if (item != NULL)
409 {
410 SequenceOfItems.push_back(item);
411 result = EC_Normal;
412 } else
413 result = EC_MemoryExhausted;
414 }
415 return result;
416 }
417
418
insertItem(const size_t pos,Item * & item)419 OFCondition DRTPrimaryFluenceModeSequence::insertItem(const size_t pos, Item *&item)
420 {
421 OFCondition result = EC_IllegalCall;
422 if (!EmptyDefaultSequence)
423 {
424 OFListIterator(Item *) iterator;
425 result = gotoItem(pos, iterator);
426 if (result.good())
427 {
428 item = new Item();
429 if (item != NULL)
430 {
431 SequenceOfItems.insert(iterator, 1, item);
432 result = EC_Normal;
433 } else
434 result = EC_MemoryExhausted;
435 } else
436 result = addItem(item);
437 }
438 return result;
439 }
440
441
removeItem(const size_t pos)442 OFCondition DRTPrimaryFluenceModeSequence::removeItem(const size_t pos)
443 {
444 OFCondition result = EC_IllegalCall;
445 if (!EmptyDefaultSequence)
446 {
447 OFListIterator(Item *) iterator;
448 if (gotoItem(pos, iterator).good())
449 {
450 delete *iterator;
451 iterator = SequenceOfItems.erase(iterator);
452 result = EC_Normal;
453 } else
454 result = EC_IllegalParameter;
455 }
456 return result;
457 }
458
459
read(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)460 OFCondition DRTPrimaryFluenceModeSequence::read(DcmItem &dataset,
461 const OFString &card,
462 const OFString &type,
463 const char *moduleName)
464 {
465 OFCondition result = EC_IllegalCall;
466 if (!EmptyDefaultSequence)
467 {
468 /* re-initialize object */
469 clear();
470 /* retrieve sequence element from dataset */
471 DcmSequenceOfItems *sequence;
472 result = dataset.findAndGetSequence(DCM_PrimaryFluenceModeSequence, sequence);
473 if (sequence != NULL)
474 {
475 if (checkElementValue(*sequence, card, type, result, moduleName))
476 {
477 DcmStack stack;
478 OFBool first = OFTrue;
479 /* iterate over all sequence items */
480 while (result.good() && sequence->nextObject(stack, first /*intoSub*/).good())
481 {
482 DcmItem *ditem = OFstatic_cast(DcmItem *, stack.top());
483 if (ditem != NULL)
484 {
485 Item *item = new Item();
486 if (item != NULL)
487 {
488 result = item->read(*ditem);
489 if (result.good())
490 {
491 /* append new item to the end of the list */
492 SequenceOfItems.push_back(item);
493 first = OFFalse;
494 }
495 } else
496 result = EC_MemoryExhausted;
497 } else
498 result = EC_CorruptedData;
499 }
500 }
501 } else {
502 DcmSequenceOfItems element(DCM_PrimaryFluenceModeSequence);
503 checkElementValue(element, card, type, result, moduleName);
504 }
505 }
506 return result;
507 }
508
509
write(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)510 OFCondition DRTPrimaryFluenceModeSequence::write(DcmItem &dataset,
511 const OFString &card,
512 const OFString &type,
513 const char *moduleName)
514 {
515 OFCondition result = EC_IllegalCall;
516 if (!EmptyDefaultSequence)
517 {
518 result = EC_MemoryExhausted;
519 DcmSequenceOfItems *sequence = new DcmSequenceOfItems(DCM_PrimaryFluenceModeSequence);
520 if (sequence != NULL)
521 {
522 result = EC_Normal;
523 /* an empty optional sequence is not written */
524 if ((type == "2") || !SequenceOfItems.empty())
525 {
526 OFListIterator(Item *) iterator = SequenceOfItems.begin();
527 const OFListConstIterator(Item *) last = SequenceOfItems.end();
528 /* iterate over all sequence items */
529 while (result.good() && (iterator != last))
530 {
531 DcmItem *item = new DcmItem();
532 if (item != NULL)
533 {
534 /* append new item to the end of the sequence */
535 result = sequence->append(item);
536 if (result.good())
537 {
538 result = (*iterator)->write(*item);
539 ++iterator;
540 } else
541 delete item;
542 } else
543 result = EC_MemoryExhausted;
544 }
545 if (result.good())
546 {
547 /* insert sequence element into the dataset */
548 result = dataset.insert(sequence, OFTrue /*replaceOld*/);
549 }
550 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
551 checkElementValue(*sequence, card, type, result, moduleName);
552 if (result.good())
553 {
554 /* forget reference to sequence object (avoid deletion below) */
555 sequence = NULL;
556 }
557 }
558 else if (type == "1")
559 {
560 /* empty type 1 sequence not allowed */
561 result = RT_EC_InvalidValue;
562 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
563 checkElementValue(*sequence, card, type, result, moduleName);
564 }
565 /* delete sequence (if not inserted into the dataset) */
566 delete sequence;
567 }
568 }
569 return result;
570 }
571
572
573 // end of source file
574