Coverage Report

Created: 2026-06-05 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dcmtk-install/include/dcmtk/dcmdata/dcitem.h
Line
Count
Source
1
/*
2
 *
3
 *  Copyright (C) 1994-2026, 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:  dcmdata
15
 *
16
 *  Author:  Gerd Ehlers
17
 *
18
 *  Purpose: Interface of class DcmItem
19
 *
20
 */
21
22
23
#ifndef DCITEM_H
24
#define DCITEM_H
25
26
#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
27
28
#include "dcmtk/ofstd/offile.h"       /* for offile_off_t */
29
#include "dcmtk/dcmdata/dctypes.h"
30
#include "dcmtk/dcmdata/dcobject.h"
31
#include "dcmtk/dcmdata/dclist.h"
32
#include "dcmtk/dcmdata/dcpcache.h"
33
34
35
// forward declarations
36
class DcmElement;
37
class DcmJsonFormat;
38
class DcmSequenceOfItems;
39
class DcmSpecificCharacterSet;
40
41
42
/** a class representing a list of DICOM elements in which each
43
 *  element has a different tag and elements are maintained in
44
 *  increasing order of tags. In particular, a sequence item.
45
 */
46
class DCMTK_DCMDATA_EXPORT DcmItem
47
  : public DcmObject
48
{
49
  public:
50
51
    // be friend with "greater than" and "less than" operators that are defined
52
    // outside of this class
53
    friend OFBool operator< (const DcmItem& lhs, const DcmItem& rhs);
54
    friend OFBool operator> (const DcmItem& lhs, const DcmItem& rhs);
55
    friend OFBool operator<=(const DcmItem& lhs, const DcmItem& rhs);
56
    friend OFBool operator>=(const DcmItem& lhs, const DcmItem& rhs);
57
58
    /** default constructor
59
     */
60
    DcmItem();
61
62
    /** constructor.
63
     *  Create new item from given tag and length.
64
     *  @param tag DICOM tag for the new element
65
     *  @param len value length for the new element
66
     */
67
    DcmItem(const DcmTag &tag,
68
            const Uint32 len = 0);
69
70
    /** copy constructor
71
     *  @param old item to be copied
72
     */
73
    DcmItem(const DcmItem &old);
74
75
    /** assignment operator. Private creator cache is not copied
76
     *  as it is also the case for clone().
77
     *  @param obj the item to be copied
78
     *  @return Reference to this object after assignment
79
     */
80
    DcmItem &operator=(const DcmItem &obj);
81
82
    /** comparison operator that compares the value of this object
83
     *  with a given object of the same type. The tag of the element is also
84
     *  considered as the first component that is compared, followed by the
85
     *  object types (VR, i.e. DCMTK'S EVR) and the comparison of all value
86
     *  components of the object, preferably in the order declared in the
87
     *  object (if applicable). For item values that means that all elements
88
     *  within the items are compared to each other in ascending tag order.
89
     *  This may be an expensive operation.
90
     *  @param  rhs the right hand side of the comparison
91
     *  @return 0 if the object values are equal.
92
     *          -1 if this element has fewer components than the rhs element.
93
     *          Also -1 if the value of the first component that does not match
94
     *          is lower in this object than in rhs. Also returned if rhs
95
     *          cannot be casted to this object type or both objects are of
96
     *          different VR (i.e. the DcmEVR returned by the element's ident()
97
     *          call are different).
98
     *          1 if either this element has more components than the rhs
99
     *          element, or if the first component that does not match is
100
     *          greater in this object than in rhs object.
101
     */
102
    virtual int compare(const DcmItem& rhs) const;
103
104
    /** destructor
105
     */
106
    virtual ~DcmItem();
107
108
    /** clone method
109
     *  @return deep copy of this object
110
     */
111
    virtual DcmObject *clone() const
112
    {
113
      return new DcmItem(*this);
114
    }
115
116
    /** Virtual object copying. This method can be used for DcmObject
117
     *  and derived classes to get a deep copy of an object. Internally
118
     *  the assignment operator is called if the given DcmObject parameter
119
     *  is of the same type as "this" object instance. If not, an error
120
     *  is returned. This function permits copying an object by value
121
     *  in a virtual way which therefore is different to just calling the
122
     *  assignment operator of DcmElement which could result in slicing
123
     *  the object.
124
     *  @param rhs - [in] The instance to copy from. Has to be of the same
125
     *                class type as "this" object
126
     *  @return EC_Normal if copying was successful, error otherwise
127
     */
128
    virtual OFCondition copyFrom(const DcmObject& rhs);
129
130
    /** get type identifier
131
     *  @return type identifier of this class (EVR_item)
132
     */
133
    virtual DcmEVR ident() const;
134
135
    /** get value multiplicity
136
     *  @return always returns 1 (according to the DICOM standard)
137
     */
138
    virtual unsigned long getVM();
139
140
    /** get number of values (elements) stored in this item.
141
     *  The result is the same as card() unless overwritten in a derived class.
142
     *  @return number of elements in this item
143
     */
144
    virtual unsigned long getNumberOfValues();
145
146
    /** get cardinality of this item
147
     *  @return number of elements in this item
148
     */
149
    virtual unsigned long card() const;
150
151
    /** check if this element is a leaf node in a dataset tree.
152
     *  All subclasses of DcmElement except for DcmSequenceOfItems
153
     *  are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset etc.
154
     *  are not.
155
     *  @return true if leaf node, false otherwise.
156
     */
157
    virtual OFBool isLeaf() const { return OFFalse; }
158
159
    /** check if this item is nested in a sequence of items, i.e.\ not a
160
     *  top-level or stand-alone item/dataset
161
     *  @return true if this item is nested, false otherwise
162
     */
163
    virtual OFBool isNested() const;
164
165
    /** print all elements of the item to a stream
166
     *  @param out output stream
167
     *  @param flags optional flag used to customize the output (see DCMTypes::PF_xxx)
168
     *  @param level current level of nested items. Used for indentation.
169
     *  @param pixelFileName not used
170
     *  @param pixelCounter not used
171
     */
172
    virtual void print(STD_NAMESPACE ostream &out,
173
                       const size_t flags = 0,
174
                       const int level = 0,
175
                       const char *pixelFileName = NULL,
176
                       size_t *pixelCounter = NULL);
177
178
    /** @copydoc DcmObject::calcElementLength()
179
     */
180
    virtual Uint32 calcElementLength(const E_TransferSyntax xfer,
181
                                     const E_EncodingType enctype);
182
183
    /** calculate the value length (without attribute tag, VR and length field)
184
     *  of this DICOM element when encoded with the given transfer syntax and
185
     *  the given encoding type for sequences.
186
     *  If length encoding is set to be explicit and the item content is larger
187
     *  than the available 32-bit length field, then undefined length is
188
     *  returned. If "dcmWriteOversizedSeqsAndItemsUndefined" is disabled,
189
     *  also the internal DcmObject errorFlag is set to
190
     *  EC_SeqOrItemContentOverflow.
191
     *  @param xfer transfer syntax for length calculation
192
     *  @param enctype sequence encoding type for length calculation
193
     *  @return value length of DICOM element
194
     */
195
    virtual Uint32 getLength(const E_TransferSyntax xfer = EXS_LittleEndianImplicit,
196
                             const E_EncodingType enctype = EET_UndefinedLength);
197
198
    /** initialize the transfer state of this object. This method must be called
199
     *  before this object is written to a stream or read (parsed) from a stream.
200
     */
201
    virtual void transferInit();
202
203
    /** finalize the transfer state of this object. This method must be called
204
     *  when reading/writing this object from/to a stream has been completed.
205
     */
206
    virtual void transferEnd();
207
208
    /** get parent item of this object, i.e.\ the item/dataset in which the
209
     *  surrounding sequence element is stored.
210
     *  @return pointer to the parent item of this object (might be NULL)
211
     */
212
    virtual DcmItem *getParentItem();
213
214
    /** check if this DICOM object can be encoded in the given transfer syntax.
215
     *  @param newXfer transfer syntax in which the DICOM object is to be encoded
216
     *  @param oldXfer transfer syntax in which the DICOM object was read or created.
217
     *  @return true if object can be encoded in desired transfer syntax, false otherwise.
218
     */
219
    virtual OFBool canWriteXfer(const E_TransferSyntax newXfer,
220
                                const E_TransferSyntax oldXfer);
221
222
    /** This function reads the information of all attributes which
223
     *  are captured in the input stream and captures this information
224
     *  in elementList. Each attribute is represented as an element
225
     *  in this list. If not all information for an attribute could be
226
     *  read from the stream, the function returns EC_StreamNotifyClient.
227
     *  @param inStream      The stream which contains the information.
228
     *  @param ixfer         The transfer syntax which was used to encode
229
     *                       the information in inStream.
230
     *  @param glenc         Encoding type for group length; specifies
231
     *                       what will be done with group length tags.
232
     *  @param maxReadLength Maximum read length for reading an attribute value.
233
     *  @return status, EC_Normal if successful, an error code otherwise
234
     */
235
    virtual OFCondition read(DcmInputStream &inStream,
236
                             const E_TransferSyntax ixfer,
237
                             const E_GrpLenEncoding glenc = EGL_noChange,
238
                             const Uint32 maxReadLength = DCM_MaxReadLength);
239
240
    /** This function reads the information of all attributes which
241
     *  are captured in the input stream and captures this information
242
     *  in elementList, up to the attribute tag stopParsingAtElement.
243
     *  Each attribute is represented as an element
244
     *  in this list. If not all information for an attribute could be
245
     *  read from the stream, the function returns EC_StreamNotifyClient.
246
     *  @param inStream      The stream which contains the information.
247
     *  @param ixfer         The transfer syntax which was used to encode
248
     *                       the information in inStream.
249
     *  @param glenc         Encoding type for group length; specifies
250
     *                       what will be done with group length tags.
251
     *  @param maxReadLength Maximum read length for reading an attribute value.
252
     *  @param stopParsingAtElement parsing of the input stream is stopped when
253
     *                       this tag key or any higher tag is encountered.
254
     *  @return status, EC_Normal if successful, an error code otherwise
255
     */
256
    virtual OFCondition readUntilTag(DcmInputStream &inStream,
257
                                     const E_TransferSyntax ixfer,
258
                                     const E_GrpLenEncoding glenc = EGL_noChange,
259
                                     const Uint32 maxReadLength = DCM_MaxReadLength,
260
                                     const DcmTagKey &stopParsingAtElement = DCM_UndefinedTagKey);
261
262
    /** write object to a stream
263
     *  @param outStream DICOM output stream
264
     *  @param oxfer output transfer syntax
265
     *  @param enctype encoding types (undefined or explicit length)
266
     *  @param wcache pointer to write cache object, may be NULL
267
     *  @return status, EC_Normal if successful, an error code otherwise
268
     */
269
    virtual OFCondition write(DcmOutputStream &outStream,
270
                              const E_TransferSyntax oxfer,
271
                              const E_EncodingType enctype,
272
                              DcmWriteCache *wcache);
273
274
    /** write object in XML format
275
     *  @param out output stream to which the XML document is written
276
     *  @param flags optional flag used to customize the output (see DCMTypes::XF_xxx)
277
     *  @return status, EC_Normal if successful, an error code otherwise
278
     */
279
    virtual OFCondition writeXML(STD_NAMESPACE ostream &out,
280
                                 const size_t flags = 0);
281
282
    /** write object in JSON format
283
     *  @param out output stream to which the JSON document is written
284
     *  @param format used to format and customize the output
285
     *  @return status, EC_Normal if successful, an error code otherwise
286
     */
287
    virtual OFCondition writeJson(STD_NAMESPACE ostream &out,
288
                                  DcmJsonFormat &format);
289
290
    /** write object in JSON format and control whether the output
291
     *  is encapsulated in braces
292
     *  @param out output stream to which the JSON document is written
293
     *  @param format used to format and customize the output
294
     *  @param printBraces true if output should be encapsulated in braces
295
     *  @param printNewline true if a newline should be printed after a closing brace
296
     *  @return status, EC_Normal if successful, an error code otherwise
297
     */
298
    virtual OFCondition writeJsonExt(STD_NAMESPACE ostream &out,
299
                                  DcmJsonFormat &format,
300
                                  OFBool printBraces,
301
                                  OFBool printNewline);
302
303
    /** special write method for creation of digital signatures
304
     *  @param outStream DICOM output stream
305
     *  @param oxfer output transfer syntax
306
     *  @param enctype encoding types (undefined or explicit length)
307
     *  @param wcache pointer to write cache object, may be NULL
308
     *  @return status, EC_Normal if successful, an error code otherwise
309
     */
310
    virtual OFCondition writeSignatureFormat(DcmOutputStream &outStream,
311
                                             const E_TransferSyntax oxfer,
312
                                             const E_EncodingType enctype,
313
                                             DcmWriteCache *wcache);
314
315
    /** returns true if the object contains an element with Unknown VR at any nesting level
316
     *  @return true if the object contains an element with Unknown VR, false otherwise
317
     */
318
    virtual OFBool containsUnknownVR() const;
319
320
    /** check if this object contains non-ASCII characters at any nesting level. Please note
321
     *  that this check is pretty simple and only works for single-byte character sets that
322
     *  do include the 7-bit ASCII codes, e.g. for the ISO 8859 family. In other words: All
323
     *  character codes below 128 are considered to be ASCII codes and all others are
324
     *  considered to be non-ASCII.
325
     *  @param checkAllStrings if true, also check elements with string values not affected
326
     *    by SpecificCharacterSet (0008,0005). By default, only check PN, LO, LT, SH, ST,
327
     *    UC and UT.
328
     *  @return true if object contains non-ASCII characters, false otherwise
329
     */
330
    virtual OFBool containsExtendedCharacters(const OFBool checkAllStrings = OFFalse);
331
332
    /** check if this object is affected by SpecificCharacterSet at any nesting level.
333
     *  In detail, it is checked whether this object contains any data elements that
334
     *  according to their VR are affected by the SpecificCharacterSet (0008,0005)
335
     *  element. This is true for the following VRs: PN, LO, LT, SH, ST, UC and UT
336
     *  @return true if object is affected by SpecificCharacterSet, false otherwise
337
     */
338
    virtual OFBool isAffectedBySpecificCharacterSet() const;
339
340
    /** mode specifying whether the SpecificCharacterSet (0008,0005) element should be
341
     *  checked by convertCharacterSet() or not, i.e.\ whether this element might be
342
     *  present on this dataset-level. This method is reimplemented in derived classes.
343
     *  @return always returns OFFalse, i.e.\ SpecificCharacterSet should not be checked
344
     */
345
    virtual OFBool checkForSpecificCharacterSet() const { return OFFalse; }
346
347
    /** convert all element values that are contained in this item and that are affected
348
     *  by SpecificCharacterSet from the given source character set to the given
349
     *  destination character set. The defined terms for a particular character set can
350
     *  be found in the DICOM standard, e.g. "ISO_IR 100" for ISO 8859-1 (Latin 1) or
351
     *  "ISO_IR 192" for Unicode in UTF-8. An empty string denotes the default character
352
     *  repertoire, which is ASCII (7-bit). If multiple values are given for 'fromCharset'
353
     *  (separated by a backslash) code extension techniques are used and escape sequences
354
     *  may be encountered in the source string to switch between the specified character
355
     *  sets.
356
     *  @note The conversion code does not perform a thorough validation of the strings to
357
     *    be converted. For example, characters that are permitted in the source character
358
     *    set but forbidden in DICOM (such as byte positions 0x80-0x9F in ISO_IR 100) may
359
     *    be converted without warning or error.
360
     *  @param fromCharset name of the source character set(s) used for the conversion
361
     *  @param toCharset name of the destination character set used for the conversion.
362
     *    Only a single value is permitted (i.e. no code extensions).
363
     *  @param flags optional flag used to customize the conversion (see DCMTypes::CF_xxx)
364
     *  @param updateCharset if OFTrue, the SpecificCharacterSet (0008,0005) element is
365
     *    updated, i.e.\ the current value is either replaced or a new element is inserted
366
     *    or the existing element is deleted. If OFFalse the SpecificCharacterSet element
367
     *    remains unchanged.
368
     *  @return status, EC_Normal if successful, an error code otherwise
369
     */
370
    virtual OFCondition convertCharacterSet(const OFString &fromCharset,
371
                                            const OFString &toCharset,
372
                                            const size_t flags = 0,
373
                                            const OFBool updateCharset = OFFalse);
374
375
    /** convert all element values that are contained in this item and that are affected
376
     *  by SpecificCharacterSet to the given destination character set. If not disabled,
377
     *  the source character set is determined automatically from the value of the
378
     *  SpecificCharacterSet (0008,0005) element. The defined terms for the destination
379
     *  character set can be found in the DICOM standard, e.g. "ISO_IR 100" for ISO 8859-1
380
     *  (Latin 1) or "ISO_IR 192" for Unicode in UTF-8. An empty string denotes the
381
     *  default character repertoire, which is ASCII (7-bit).
382
     *  @note The conversion code does not perform a thorough validation of the strings to
383
     *    be converted. For example, characters that are permitted in the source character
384
     *    set but forbidden in DICOM (such as byte positions 0x80-0x9F in ISO_IR 100) may
385
     *    be converted without warning or error.
386
     *  @param toCharset name of the destination character set used for the conversion.
387
     *    Only a single value is permitted (i.e. no code extensions).
388
     *  @param flags optional flag used to customize the conversion (see DCMTypes::CF_xxx)
389
     *  @param ignoreCharset if OFTrue, the value of SpecificCharacterSet is ignored,
390
     *    otherwise the element value is updated. Also see checkForSpecificCharacterSet().
391
     *  @return status, EC_Normal if successful, an error code otherwise
392
     */
393
    virtual OFCondition convertCharacterSet(const OFString &toCharset,
394
                                            const size_t flags = 0,
395
                                            const OFBool ignoreCharset = OFFalse);
396
397
    /** convert all element values that are contained in this item and that are affected
398
     *  by SpecificCharacterSet from the currently selected source character set to the
399
     *  currently selected destination character set.
400
     *  @note The conversion code does not perform a thorough validation of the strings to
401
     *    be converted. For example, characters that are permitted in the source character
402
     *    set but forbidden in DICOM (such as byte positions 0x80-0x9F in ISO_IR 100) may
403
     *    be converted without warning or error.
404
     *  @param converter character set converter to be used to convert the element values
405
     *  @return status, EC_Normal if successful, an error code otherwise
406
     */
407
    virtual OFCondition convertCharacterSet(DcmSpecificCharacterSet &converter);
408
409
    /** convert all element values that are contained in this item and that are affected
410
     *  by SpecificCharacterSet to UTF-8 (Unicode). The value of the SpecificCharacterSet
411
     *  (0008,0005) element is updated, set or deleted automatically if needed. The
412
     *  transliteration mode is disabled, i.e. the conversion flags are explicitly set to
413
     *  0 - see convertCharacterSet().
414
     *  @return status, EC_Normal if successful, an error code otherwise
415
     */
416
    virtual OFCondition convertToUTF8();
417
418
    /** update the SpecificCharacterSet (0008,0005) element depending on the given
419
     *  parameters. The current value of this element is either replaced or a new
420
     *  element is inserted or the existing element is deleted.
421
     *  @note This method is called by convertCharacterSet() and convertToUTF8() when
422
     *    needed, so there is usually no reason to call it directly.
423
     *  @param status error status of previous operations (might also be updated)
424
     *  @param converter character set converter used to convert element values
425
     */
426
    virtual void updateSpecificCharacterSet(OFCondition &status,
427
                                            const DcmSpecificCharacterSet &converter);
428
429
    /** insert a new element into the list of elements maintained by this item.
430
     *  The list of elements is always kept in ascending tag order.
431
     *  @param elem element to be inserted, must not be contained in this or
432
     *    any other item.  Will be deleted upon destruction of this item object.
433
     *  @param replaceOld if true, this element replaces any other element with
434
     *    the same tag which may already be contained in the item.  If false,
435
     *    insert fails if another element with the same tag is already present.
436
     *  @param checkInsertOrder if true, a warning message is sent to the console
437
     *    if the element is not inserted at the end of the list.  This is used
438
     *    in the read() method to detect datasets with out-of-order elements.
439
     *  @return status, EC_Normal if successful, an error code otherwise
440
     */
441
    virtual OFCondition insert(DcmElement *elem,
442
                               OFBool replaceOld = OFFalse,
443
                               OFBool checkInsertOrder = OFFalse);
444
445
    /** access an element from the item. This method returns a pointer to one
446
     *  of the elements in the item, and not a copy.
447
     *  @param num index number of element, must be < card()
448
     *  @return pointer to element if found, NULL if num >= card()
449
     */
450
    virtual DcmElement *getElement(const unsigned long num);
451
452
    /** this method enables a stack based, depth-first traversal of a complete
453
     *  hierarchical DICOM dataset (that is, classes derived from DcmItem or
454
     *  DcmSequenceOfItems). With each call of this method, the next object
455
     *  in the tree is located and marked on the stack.
456
     *  @param stack "cursor" for current position in the dataset. The stack
457
     *    will contain a pointer to each dataset, sequence, item and element
458
     *    from the main dataset down to the current element, and is updated
459
     *    upon each call to this method. An empty stack is equivalent to a stack
460
     *    containing a pointer to this object only.
461
     *  @param intoSub if true, the nextObject method will perform a hierarchical
462
     *    search through the dataset (depth-first), if false, only the current
463
     *    container object will be traversed (e.g., all elements of an item
464
     *    or all items of a sequence).
465
     *  @return EC_Normal if value length is correct, an error code otherwise
466
     */
467
    virtual OFCondition nextObject(DcmStack &stack,
468
                                   const OFBool intoSub);
469
470
    /** this method is only used in container classes,
471
     *  that is, DcmItem and DcmSequenceOfItems. It returns a pointer to the
472
     *  next object in the list AFTER the given object. If the caller passes NULL,
473
     *  a pointer to the first object in the list is returned. If the given object
474
     *  is not found, the given object is the last one in the list or the list is
475
     *  empty, NULL is returned.
476
     *  @param obj pointer to one object in the container; we are looking for the
477
     *    next entry after this one. NULL if looking for the first entry.
478
     *  @return pointer to next object in container or NULL if not found
479
     */
480
    virtual DcmObject *nextInContainer(const DcmObject *obj);
481
482
    /** remove element from list. If found, the element is not deleted but
483
     *  returned to the caller who is responsible for further management of the
484
     *  DcmElement object.
485
     *  @param num index number of element, must be < card()
486
     *  @return pointer to DcmElement if found, NULL otherwise
487
     */
488
    virtual DcmElement *remove(const unsigned long num);
489
490
    /** remove element from list. If found, the element is not deleted but
491
     *  returned to the caller who is responsible for further management of the
492
     *  DcmElement object.
493
     *  @param elem pointer to element (as type DcmObject *) to be removed from list
494
     *  @return pointer to element (as type DcmElement *) if found, NULL otherwise
495
     */
496
    virtual DcmElement *remove(DcmObject *elem);
497
498
    /** remove element from list. If found, the element is not deleted but
499
     *  returned to the caller who is responsible for further management of the
500
     *  DcmElement object.
501
     *  @param tag attribute tag of element to be removed
502
     *  @return pointer to DcmElement if found, NULL otherwise
503
     */
504
    virtual DcmElement *remove(const DcmTagKey &tag);
505
506
    /** check if this item is empty
507
     *  @param normalize not used for this class
508
     *  @return true if item is empty, i.e.\ has no elements, false otherwise
509
     */
510
    virtual OFBool isEmpty(const OFBool normalize = OFTrue);
511
512
    /** clear (remove) all attributes from item and delete them from memory.
513
     *  @return EC_Normal if successful, an error code otherwise
514
     */
515
    virtual OFCondition clear();
516
517
    /** check the currently stored element value
518
     *  @param autocorrect correct value length if OFTrue
519
     *  @return status, EC_Normal if value length is correct, an error code otherwise
520
     */
521
    virtual OFCondition verify(const OFBool autocorrect = OFFalse );
522
523
    /** a complex, stack-based, hierarchical search method. It allows for a search
524
     *  for a DICOM object with a given attribute within a given container,
525
     *  hierarchically, from a starting position identified through a cursor stack.
526
     *  @param xtag the DICOM attribute tag we are searching for
527
     *  @param resultStack Depending on the search mode (see below), this parameter
528
     *     either serves as an input and output parameter, or as an output parameter
529
     *     only (the latter being the default). When used as an input parameter,
530
     *     the cursor stack defines the start position for the search within a
531
     *     hierarchical DICOM dataset. Upon successful return, the stack contains
532
     *     the position of the element found, in the form of a pointer to each dataset,
533
     *     sequence, item and element from the main dataset down to the found element.
534
     *  @param mode search mode, controls how the search stack is handled.
535
     *     In the default mode, ESM_fromHere, the stack is ignored on input, and
536
     *     the search starts in the object for which this method is called.
537
     *     In the other modes, the stack is used both as an input and an output
538
     *     parameter and defines the starting point for the search.
539
     *  @param searchIntoSub if true, the search will be performed hierarchically descending
540
     *    into the sequences and items of the dataset. If false, only the current container
541
     *    (sequence or item) will be traversed.
542
     *  @return EC_Normal if found, EC_TagNotFound if not found, an error code is something
543
     *    went wrong.
544
     */
545
    virtual OFCondition search(const DcmTagKey &xtag,              // in
546
                               DcmStack &resultStack,              // inout
547
                               E_SearchMode mode = ESM_fromHere,   // in
548
                               OFBool searchIntoSub = OFTrue );    // in
549
550
    /** this method loads all attribute values maintained by this object and
551
     *  all sub-objects (in case of a container such as DcmDataset) into memory.
552
     *  After a call to this method, the file from which a dataset was read may safely
553
     *  be deleted or replaced. For large files, this method may obviously allocate large
554
     *  amounts of memory.
555
     *  @return EC_Normal if successful, an error code otherwise
556
     */
557
    virtual OFCondition loadAllDataIntoMemory();
558
559
    /** iterate over all elements and remove those element values from memory which exceed
560
     *  a given length and which can be loaded from file when needed again. For all other
561
     *  elements, nothing is done.
562
     *  @param maxLength maximum length (number of bytes) allowed without removing the value
563
     */
564
    virtual void compactElements(const Uint32 maxLength);
565
566
    /** This function takes care of group length and padding elements
567
     *  in the current element list according to what is specified in
568
     *  glenc and padenc. If required, this function does the following
569
     *  two things:
570
     *    a) it calculates the group length of all groups which are
571
     *       contained in this item and sets the calculated values
572
     *       in the corresponding group length elements and
573
     *    b) it inserts a corresponding padding element (or, in case
574
     *       of sequences: padding elements) with a corresponding correct
575
     *       size into the element list.
576
     *  @param glenc          Encoding type for group length; specifies what shall
577
     *                        be done with group length tags.
578
     *  @param padenc         Encoding type for padding; specifies what shall be
579
     *                        done with padding tags.
580
     *  @param xfer           The transfer syntax that shall be used.
581
     *  @param enctype        Encoding type for sequences; specifies how sequences
582
     *                        will be handled.
583
     *  @param padlen         The length up to which the dataset shall be padded,
584
     *                        if padding is desired.
585
     *  @param subPadlen      For sequences (i.e. sub elements), the length up to
586
     *                        which item shall be padded, if padding is desired.
587
     *  @param instanceLength Number of extra bytes added to the item/dataset
588
     *                        length used when computing the padding; this
589
     *                        parameter is for instance used to pass the length
590
     *                        of the file meta header from the DcmFileFormat to
591
     *                        the DcmDataset object.
592
     *  @return status, EC_Normal if successful, an error code otherwise
593
     */
594
    virtual OFCondition computeGroupLengthAndPadding(const E_GrpLenEncoding glenc,
595
                                                     const E_PaddingEncoding padenc = EPD_noChange,
596
                                                     const E_TransferSyntax xfer = EXS_Unknown,
597
                                                     const E_EncodingType enctype = EET_ExplicitLength,
598
                                                     const Uint32 padlen = 0,
599
                                                     const Uint32 subPadlen = 0,
600
                                                     Uint32 instanceLength = 0);
601
602
603
    /** check if an element with the given attribute tag exists in the dataset
604
     *  @param key tag key to be searched
605
     *  @param searchIntoSub if true, do hierarchical search within sequences,
606
     *    if false only search through this dataset
607
     *  @return true if tag found, false otherwise
608
     */
609
    OFBool tagExists(const DcmTagKey &key,
610
                     OFBool searchIntoSub = OFFalse);
611
612
    /** check if an element with the given attribute tag exists in the dataset
613
     *  and has a non-empty value
614
     *  @param key tag key to be searched
615
     *  @param searchIntoSub if true, do hierarchical search within sequences,
616
     *    if false only search through this dataset
617
     *  @return true if tag found and element non-empty, false otherwise
618
     */
619
    OFBool tagExistsWithValue(const DcmTagKey &key,
620
                              OFBool searchIntoSub = OFFalse);
621
622
    /* --- findAndGet functions: find an element and get it or the value, respectively --- */
623
624
    /** find element and get a pointer to it (or copy it).
625
     *  The result variable 'element' is automatically set to NULL if an error occurs.
626
     *  @note Applicable to all DICOM value representations (VR).
627
     *  @param tagKey DICOM tag specifying the attribute to be searched for
628
     *  @param element variable in which the reference to (or copy of) the element is stored
629
     *  @param searchIntoSub flag indicating whether to search into sequences or not
630
     *  @param createCopy create a copy of the element if true, return a reference otherwise
631
     *  @return EC_Normal upon success, an error code otherwise.
632
     */
633
    OFCondition findAndGetElement(const DcmTagKey &tagKey,
634
                                  DcmElement *&element,
635
                                  const OFBool searchIntoSub = OFFalse,
636
                                  const OFBool createCopy = OFFalse);
637
638
    /** find all elements matching a particular tag and return references to them on a stack.
639
     *  This functions always performs a deep search (i.e. searches into sequence of items).
640
     *  @note Applicable to all DICOM value representations (VR).
641
     *  @param tagKey DICOM tag specifying the attribute to be searched for
642
     *  @param resultStack stack where references to the elements are stored (added to).
643
     *    If no element is found, the stack is not modified (e.g. cleared).
644
     *  @return EC_Normal if at least one matching tag is found, an error code otherwise.
645
     */
646
    OFCondition findAndGetElements(const DcmTagKey &tagKey,
647
                                   DcmStack &resultStack);
648
649
    /** find element and get value as a reference to a C string. NB: The string is not copied!
650
     *  Since the getString() routine is called internally the resulting string reference represents
651
     *  the (possibly multi-valued) value as stored in the dataset, i.e. no normalization is performed.
652
     *  The result variable 'value' is automatically set to NULL if an error occurs.
653
     *  @note Applicable to the following VRs: AE, AS, CS, DA, DS, DT, IS, LO, LT, PN, SH, ST, TM,
654
     *    UC, UI, UR, UT.
655
     *  @param tagKey DICOM tag specifying the attribute to be searched for
656
     *  @param value variable in which the reference to the element value is stored (might be NULL)
657
     *  @param searchIntoSub flag indicating whether to search into sequences or not
658
     *  @return EC_Normal upon success, an error code otherwise.
659
     */
660
    OFCondition findAndGetString(const DcmTagKey &tagKey,
661
                                 const char *&value,
662
                                 const OFBool searchIntoSub = OFFalse);
663
664
    /** find element and get value as a reference to a C string. NB: The string is not copied!
665
     *  Since the getString() routine is called internally the resulting string reference represents
666
     *  the (possibly multi-valued) value as stored in the dataset, i.e. no normalization is performed.
667
     *  The result variable 'value' is automatically set to NULL and 'length' is set to 0 if an error
668
     *  occurs.
669
     *  Please note that since the length is returned separately, the string value can contain more
670
     *  than one NULL byte.
671
     *  @note Applicable to the following VRs: AE, AS, CS, DA, DS, DT, IS, LO, LT, PN, SH, ST, TM,
672
     *    UC, UI, UR, UT.
673
     *  @param tagKey DICOM tag specifying the attribute to be searched for
674
     *  @param value variable in which the reference to the element value is stored (might be NULL)
675
     *  @param length length of the string (number of characters without the trailing NULL byte)
676
     *  @param searchIntoSub flag indicating whether to search into sequences or not
677
     *  @return EC_Normal upon success, an error code otherwise.
678
     */
679
    OFCondition findAndGetString(const DcmTagKey &tagKey,
680
                                 const char *&value,
681
                                 Uint32 &length,
682
                                 const OFBool searchIntoSub = OFFalse);
683
684
    /** find element and get value as a C++ string (only one component).
685
     *  Since the getOFString() routine is called internally the resulting string is normalized, i.e.
686
     *  leading and/or trailing spaces are removed according to the associated value representation,
687
     *  or the element value is converted to a character string (for non-string VRs) - see documentation
688
     *  in the corresponding header file.
689
     *  In contrast to the above and below function only the specified component (see parameter 'pos')
690
     *  is returned. The result variable 'value' is automatically set to an empty string if an error
691
     *  occurs.
692
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, OB, OD,
693
     *    OF, OL, OV, OW, PN, SH, SL, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
694
     *  @param tagKey DICOM tag specifying the attribute to be searched for
695
     *  @param value variable in which the element value is stored
696
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
697
     *  @param searchIntoSub flag indicating whether to search into sequences or not
698
     *  @return EC_Normal upon success, an error code otherwise.
699
     */
700
    OFCondition findAndGetOFString(const DcmTagKey &tagKey,
701
                                   OFString &value,
702
                                   const unsigned long pos = 0,
703
                                   const OFBool searchIntoSub = OFFalse);
704
705
    /** find element and get value as a C++ string (all components).
706
     *  Since the getOFStringArray() routine is called internally the resulting string is normalized,
707
     *  i.e. leading and/or trailing spaces are removed according to the associated value representation
708
     *  or the element values are converted to character strings (for non-string VRs) - see documentation
709
     *  in the corresponding header file.
710
     *  The result variable 'value' is automatically set to an empty string if an error occurs.
711
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, OB, OD,
712
     *    OF, OL, OV, OW, PN, SH, SL, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
713
     *  @param tagKey DICOM tag specifying the attribute to be searched for
714
     *  @param value variable in which the element value is stored
715
     *  @param searchIntoSub flag indicating whether to search into sequences or not
716
     *  @return EC_Normal upon success, an error code otherwise.
717
     */
718
    OFCondition findAndGetOFStringArray(const DcmTagKey &tagKey,
719
                                        OFString &value,
720
                                        const OFBool searchIntoSub = OFFalse);
721
722
    /** find element and get value as an unsigned 8-bit integer.
723
     *  The result variable 'value' is automatically set to zero if an error occurs.
724
     *  @note Applicable to the following VRs: OB.
725
     *  @param tagKey DICOM tag specifying the attribute to be searched for
726
     *  @param value variable in which the element value is stored
727
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
728
     *  @param searchIntoSub flag indicating whether to search into sequences or not
729
     *  @return EC_Normal upon success, an error code otherwise.
730
     */
731
    OFCondition findAndGetUint8(const DcmTagKey &tagKey,
732
                                Uint8 &value,
733
                                const unsigned long pos = 0,
734
                                const OFBool searchIntoSub = OFFalse);
735
736
    /** find element and get value as an array of unsigned 8-bit integers.
737
     *  The result variable 'value' is automatically set to NULL if an error occurs.
738
     *  @note Applicable to the following VRs: OB.
739
     *  @param tagKey DICOM tag specifying the attribute to be searched for
740
     *  @param value variable in which the reference to the element value is stored
741
     *  @param count stores number of items in the result array (if not NULL)
742
     *  @param searchIntoSub flag indicating whether to search into sequences or not
743
     *  @return EC_Normal upon success, an error code otherwise.
744
     */
745
    OFCondition findAndGetUint8Array(const DcmTagKey &tagKey,
746
                                     const Uint8 *&value,
747
                                     unsigned long *count = NULL,
748
                                     const OFBool searchIntoSub = OFFalse);
749
750
    /** find element and get value as an unsigned 16-bit integer.
751
     *  The result variable 'value' is automatically set to zero if an error occurs.
752
     *  @note Applicable to the following VRs: OW, US.
753
     *  @param tagKey DICOM tag specifying the attribute to be searched for
754
     *  @param value variable in which the element value is stored
755
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
756
     *  @param searchIntoSub flag indicating whether to search into sequences or not
757
     *  @return EC_Normal upon success, an error code otherwise.
758
     */
759
    OFCondition findAndGetUint16(const DcmTagKey &tagKey,
760
                                 Uint16 &value,
761
                                 const unsigned long pos = 0,
762
                                 const OFBool searchIntoSub = OFFalse);
763
764
    /** find element and get value as an array of unsigned 16-bit integers.
765
     *  The result variable 'value' is automatically set to NULL if an error occurs.
766
     *  @note Applicable to the following VRs: AT, OW, US.
767
     *  @param tagKey DICOM tag specifying the attribute to be searched for
768
     *  @param value variable in which the reference to the element value is stored
769
     *  @param count stores number of items in the result array (if not NULL)
770
     *  @param searchIntoSub flag indicating whether to search into sequences or not
771
     *  @return EC_Normal upon success, an error code otherwise.
772
     */
773
    OFCondition findAndGetUint16Array(const DcmTagKey &tagKey,
774
                                      const Uint16 *&value,
775
                                      unsigned long *count = NULL,
776
                                      const OFBool searchIntoSub = OFFalse);
777
778
    /** find element and get value as a signed 16-bit integer.
779
     *  The result variable 'value' is automatically set to zero if an error occurs.
780
     *  @note Applicable to the following VRs: SS.
781
     *  @param tagKey DICOM tag specifying the attribute to be searched for
782
     *  @param value variable in which the element value is stored
783
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
784
     *  @param searchIntoSub flag indicating whether to search into sequences or not
785
     *  @return EC_Normal upon success, an error code otherwise.
786
     */
787
    OFCondition findAndGetSint16(const DcmTagKey &tagKey,
788
                                 Sint16 &value,
789
                                 const unsigned long pos = 0,
790
                                 const OFBool searchIntoSub = OFFalse);
791
792
    /** find element and get value as an array of signed 16-bit integers.
793
     *  The result variable 'value' is automatically set to NULL if an error occurs.
794
     *  @note Applicable to the following VRs: SS.
795
     *  @param tagKey DICOM tag specifying the attribute to be searched for
796
     *  @param value variable in which the reference to the element value is stored
797
     *  @param count stores number of items in the result array (if not NULL)
798
     *  @param searchIntoSub flag indicating whether to search into sequences or not
799
     *  @return EC_Normal upon success, an error code otherwise.
800
     */
801
    OFCondition findAndGetSint16Array(const DcmTagKey &tagKey,
802
                                      const Sint16 *&value,
803
                                      unsigned long *count = NULL,
804
                                      const OFBool searchIntoSub = OFFalse);
805
806
    /** find element and get value as an unsigned 32-bit integer.
807
     *  The result variable 'value' is automatically set to zero if an error occurs.
808
     *  @note Applicable to the following VRs: OL, UL.
809
     *  @param tagKey DICOM tag specifying the attribute to be searched for
810
     *  @param value variable in which the element value is stored
811
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
812
     *  @param searchIntoSub flag indicating whether to search into sequences or not
813
     *  @return EC_Normal upon success, an error code otherwise.
814
     */
815
    OFCondition findAndGetUint32(const DcmTagKey &tagKey,
816
                                 Uint32 &value,
817
                                 const unsigned long pos = 0,
818
                                 const OFBool searchIntoSub = OFFalse);
819
820
    /** find element and get value as an array of unsigned 32-bit integers.
821
     *  The result variable 'value' is automatically set to NULL if an error occurs.
822
     *  @note Applicable to the following VRs: OL, UL.
823
     *  @param tagKey DICOM tag specifying the attribute to be searched for
824
     *  @param value variable in which the reference to the element value is stored
825
     *  @param count stores number of items in the result array (if not NULL)
826
     *  @param searchIntoSub flag indicating whether to search into sequences or not
827
     *  @return EC_Normal upon success, an error code otherwise.
828
     */
829
    OFCondition findAndGetUint32Array(const DcmTagKey &tagKey,
830
                                      const Uint32 *&value,
831
                                      unsigned long *count = NULL,
832
                                      const OFBool searchIntoSub = OFFalse);
833
834
    /** find element and get value as a signed 32-bit integer.
835
     *  The result variable 'value' is automatically set to zero if an error occurs.
836
     *  @note Applicable to the following VRs: IS, SL.
837
     *  @param tagKey DICOM tag specifying the attribute to be searched for
838
     *  @param value variable in which the element value is stored
839
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
840
     *  @param searchIntoSub flag indicating whether to search into sequences or not
841
     *  @return EC_Normal upon success, an error code otherwise.
842
     */
843
    OFCondition findAndGetSint32(const DcmTagKey &tagKey,
844
                                 Sint32 &value,
845
                                 const unsigned long pos = 0,
846
                                 const OFBool searchIntoSub = OFFalse);
847
848
    /** find element and get value as an array of signed 32-bit integers.
849
     *  The result variable 'value' is automatically set to NULL if an error occurs.
850
     *  @note Applicable to the following VRs: SL.
851
     *  @param tagKey DICOM tag specifying the attribute to be searched for
852
     *  @param value variable in which the reference to the element value is stored
853
     *  @param count stores number of items in the result array (if not NULL)
854
     *  @param searchIntoSub flag indicating whether to search into sequences or not
855
     *  @return EC_Normal upon success, an error code otherwise.
856
     */
857
    OFCondition findAndGetSint32Array(const DcmTagKey &tagKey,
858
                                      const Sint32 *&value,
859
                                      unsigned long *count = NULL,
860
                                      const OFBool searchIntoSub = OFFalse);
861
862
    /** find element and get value as an unsigned 64-bit integer.
863
     *  The result variable 'value' is automatically set to zero if an error occurs.
864
     *  @note Applicable to the following VRs: OV, UV.
865
     *  @param tagKey DICOM tag specifying the attribute to be searched for
866
     *  @param value variable in which the element value is stored
867
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
868
     *  @param searchIntoSub flag indicating whether to search into sequences or not
869
     *  @return EC_Normal upon success, an error code otherwise.
870
     */
871
    OFCondition findAndGetUint64(const DcmTagKey &tagKey,
872
                                 Uint64 &value,
873
                                 const unsigned long pos = 0,
874
                                 const OFBool searchIntoSub = OFFalse);
875
876
    /** find element and get value as an array of unsigned 64-bit integers.
877
     *  The result variable 'value' is automatically set to NULL if an error occurs.
878
     *  @note Applicable to the following VRs: OV, UV.
879
     *  @param tagKey DICOM tag specifying the attribute to be searched for
880
     *  @param value variable in which the reference to the element value is stored
881
     *  @param count stores number of items in the result array (if not NULL)
882
     *  @param searchIntoSub flag indicating whether to search into sequences or not
883
     *  @return EC_Normal upon success, an error code otherwise.
884
     */
885
    OFCondition findAndGetUint64Array(const DcmTagKey &tagKey,
886
                                      const Uint64 *&value,
887
                                      unsigned long *count = NULL,
888
                                      const OFBool searchIntoSub = OFFalse);
889
890
    /** find element and get value as a signed 64-bit integer.
891
     *  The result variable 'value' is automatically set to zero if an error occurs.
892
     *  @note Applicable to the following VRs: SV.
893
     *  @param tagKey DICOM tag specifying the attribute to be searched for
894
     *  @param value variable in which the element value is stored
895
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
896
     *  @param searchIntoSub flag indicating whether to search into sequences or not
897
     *  @return EC_Normal upon success, an error code otherwise.
898
     */
899
    OFCondition findAndGetSint64(const DcmTagKey &tagKey,
900
                                 Sint64 &value,
901
                                 const unsigned long pos = 0,
902
                                 const OFBool searchIntoSub = OFFalse);
903
904
    /** find element and get value as an array of signed 64-bit integers.
905
     *  The result variable 'value' is automatically set to NULL if an error occurs.
906
     *  @note Applicable to the following VRs: SV.
907
     *  @param tagKey DICOM tag specifying the attribute to be searched for
908
     *  @param value variable in which the reference to the element value is stored
909
     *  @param count stores number of items in the result array (if not NULL)
910
     *  @param searchIntoSub flag indicating whether to search into sequences or not
911
     *  @return EC_Normal upon success, an error code otherwise.
912
     */
913
    OFCondition findAndGetSint64Array(const DcmTagKey &tagKey,
914
                                      const Sint64 *&value,
915
                                      unsigned long *count = NULL,
916
                                      const OFBool searchIntoSub = OFFalse);
917
918
    /** find element and get value as a (signed) long integer.
919
     *  The result variable 'value' is automatically set to zero if an error occurs.
920
     *  @note Applicable to the following VRs: IS, OL, SL, SS, UL, US.
921
     *  @param tagKey DICOM tag specifying the attribute to be searched for
922
     *  @param value variable in which the element value is stored
923
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
924
     *  @param searchIntoSub flag indicating whether to search into sequences or not
925
     *  @return EC_Normal upon success, an error code otherwise.
926
     */
927
    OFCondition findAndGetLongInt(const DcmTagKey &tagKey,
928
                                  long int &value,
929
                                  const unsigned long pos = 0,
930
                                  const OFBool searchIntoSub = OFFalse);
931
932
    /** find element and get value as a 32-bit floating point.
933
     *  The result variable 'value' is automatically set to zero if an error occurs.
934
     *  @note Applicable to the following VRs: FL, OF.
935
     *  @param tagKey DICOM tag specifying the attribute to be searched for
936
     *  @param value variable in which the element value is stored
937
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
938
     *  @param searchIntoSub flag indicating whether to search into sequences or not
939
     *  @return EC_Normal upon success, an error code otherwise.
940
     */
941
    OFCondition findAndGetFloat32(const DcmTagKey &tagKey,
942
                                  Float32 &value,
943
                                  const unsigned long pos = 0,
944
                                  const OFBool searchIntoSub = OFFalse);
945
946
    /** find element and get value as an array of 32-bit floating point values.
947
     *  The result variable 'value' is automatically set to NULL if an error occurs.
948
     *  @note Applicable to the following VRs: FL, OF.
949
     *  @param tagKey DICOM tag specifying the attribute to be searched for
950
     *  @param value variable in which the reference to the element value is stored
951
     *  @param count stores number of items in the result array (if not NULL)
952
     *  @param searchIntoSub flag indicating whether to search into sequences or not
953
     *  @return EC_Normal upon success, an error code otherwise.
954
     */
955
    OFCondition findAndGetFloat32Array(const DcmTagKey &tagKey,
956
                                       const Float32 *&value,
957
                                       unsigned long *count = NULL,
958
                                       const OFBool searchIntoSub = OFFalse);
959
960
    /** find element and get value as a 64-bit floating point.
961
     *  The result variable 'value' is automatically set to zero if an error occurs.
962
     *  @note Applicable to the following VRs: DS, FD, OD.
963
     *  @param tagKey DICOM tag specifying the attribute to be searched for
964
     *  @param value variable in which the element value is stored
965
     *  @param pos index of the value in case of multi-valued elements (0..vm-1)
966
     *  @param searchIntoSub flag indicating whether to search into sequences or not
967
     *  @return EC_Normal upon success, an error code otherwise.
968
     */
969
    OFCondition findAndGetFloat64(const DcmTagKey &tagKey,
970
                                  Float64 &value,
971
                                  const unsigned long pos = 0,
972
                                  const OFBool searchIntoSub = OFFalse);
973
974
    /** find element and get value as an array of 64-bit floating point values.
975
     *  The result variable 'value' is automatically set to NULL if an error occurs.
976
     *  @note Applicable to the following VRs: FD, OD.
977
     *  @param tagKey DICOM tag specifying the attribute to be searched for
978
     *  @param value variable in which the reference to the element value is stored
979
     *  @param count stores number of items in the result array (if not NULL)
980
     *  @param searchIntoSub flag indicating whether to search into sequences or not
981
     *  @return EC_Normal upon success, an error code otherwise.
982
     */
983
    OFCondition findAndGetFloat64Array(const DcmTagKey &tagKey,
984
                                       const Float64 *&value,
985
                                       unsigned long *count = NULL,
986
                                       const OFBool searchIntoSub = OFFalse);
987
988
    /** looks up and returns a given sequence.
989
     *  The result variable 'sequence' is automatically set to NULL if an error occurs
990
     *  (e.g. if 'seqTagKey' does not refer to a sequence attribute).
991
     *  @note Applicable to the following VRs: SQ, (pixelSQ).
992
     *  @param seqTagKey DICOM tag specifying the sequence attribute to be searched for
993
     *  @param sequence variable in which the reference to (or copy of) the sequence is stored
994
     *  @param searchIntoSub flag indicating whether to search into sub-sequences or not
995
     *  @param createCopy create a copy of the sequence if true, return a reference otherwise
996
     *  @return EC_Normal upon success, an error otherwise.
997
     */
998
    OFCondition findAndGetSequence(const DcmTagKey &seqTagKey,
999
                                   DcmSequenceOfItems *&sequence,
1000
                                   const OFBool searchIntoSub = OFFalse,
1001
                                   const OFBool createCopy = OFFalse);
1002
1003
    /** looks up and returns a given sequence item, if it exists. Otherwise sets 'item'
1004
     *  to NULL and returns EC_TagNotFound (specified sequence does not exist) or
1005
     *  EC_IllegalParameter (specified item does not exist). Only the top-most level of
1006
     *  the dataset/item is examined (i.e. no deep-search is performed).
1007
     *  Please note that an instance of the DcmPixelItem class cannot be retrieved.
1008
     *  @note Applicable to the following VRs: SQ, (pixelSQ).
1009
     *  @param seqTagKey DICOM tag specifying the sequence attribute to be searched for
1010
     *  @param item variable in which the reference to (or copy of) the item is stored
1011
     *  @param itemNum number of the item to be searched for (0..n-1, -1 for last)
1012
     *  @param createCopy create a copy of the item if true, return a reference otherwise
1013
     *  @return EC_Normal upon success, an error otherwise.
1014
     */
1015
    OFCondition findAndGetSequenceItem(const DcmTagKey &seqTagKey,
1016
                                       DcmItem *&item,
1017
                                       const signed long itemNum = 0,
1018
                                       const OFBool createCopy = OFFalse);
1019
1020
1021
    /* --- findOrCreate functions: find an element or create a new one --- */
1022
1023
    /** looks up the given sequence in the current dataset and returns the given item.
1024
     *  If either the sequence or the item do not exist, they are created. If necessary,
1025
     *  multiple empty items are inserted. Only the top-most level of the dataset/item
1026
     *  is examined (i.e. no deep-search is performed).
1027
     *  Please note that an instance of the DcmPixelItem class cannot be retrieved or
1028
     *  created.
1029
     *  @note Applicable to the following VRs: SQ, (pixelSQ).
1030
     *  @param seqTag DICOM tag specifying the sequence attribute to be searched for
1031
     *    (or to be created)
1032
     *  @param item variable in which the reference to the sequence item is stored
1033
     *  @param itemNum number of the item to be searched for (0..n-1, -1 for last,
1034
     *    -2 for append new)
1035
     *  @return EC_Normal upon success, an error otherwise.
1036
     */
1037
    OFCondition findOrCreateSequenceItem(const DcmTag &seqTag,
1038
                                         DcmItem *&item,
1039
                                         const signed long itemNum = 0);
1040
1041
    /* --- findAndXXX functions: find an element and do something with it --- */
1042
1043
    /** find element, create a copy and insert it into the given destination dataset.
1044
     *  This functions never performs a deep search (i.e. does not search into sequence
1045
     *  of items). Empty elements are also copied. However, if the given tag is not
1046
     *  found in the current dataset, EC_TagNotFound is returned and the destination
1047
     *  dataset remains unchanged.
1048
     *  @note Applicable to all DICOM value representations (VR).
1049
     *  @param tagKey DICOM tag specifying the attribute to be searched for
1050
     *  @param destItem destination dataset to which the copied element is inserted
1051
     *  @param replaceOld flag indicating whether to replace an existing element or not
1052
     *  @return EC_Normal upon success, an error code otherwise
1053
     */
1054
    OFCondition findAndInsertCopyOfElement(const DcmTagKey &tagKey,
1055
                                           DcmItem *destItem,
1056
                                           const OFBool replaceOld = OFTrue);
1057
1058
    /** find element, remove it from the dataset and free the associated memory.
1059
     *  @note Applicable to all DICOM value representations (VR).
1060
     *  @param tagKey DICOM tag specifying the attribute to be searched for
1061
     *  @param allOccurrences flag indicating whether to delete all occurrences of the
1062
     *    attribute tag or the first one only (implies 'searchIntoSub' to be true)
1063
     *  @param searchIntoSub flag indicating whether to search into sequences or not
1064
     *  @return EC_Normal upon success, an error code otherwise.
1065
     */
1066
    OFCondition findAndDeleteElement(const DcmTagKey &tagKey,
1067
                                     const OFBool allOccurrences = OFFalse,
1068
                                     const OFBool searchIntoSub = OFFalse);
1069
1070
    /** looks up the given sequence in the current dataset and deletes the given item.
1071
     *  @note Applicable to the following VRs: SQ, (pixelSQ).
1072
     *  @param seqTagKey DICOM tag specifying the sequence attribute to be searched for
1073
     *  @param itemNum number of the item to be deleted (0..n-1, -1 for last)
1074
     *  @return EC_Normal upon success, an error otherwise.
1075
     */
1076
    OFCondition findAndDeleteSequenceItem(const DcmTagKey &seqTagKey,
1077
                                          const signed long itemNum);
1078
1079
1080
    /* --- putAndInsert functions: put value and insert new element --- */
1081
1082
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1083
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, OB,
1084
     *    OD, OF, OL, OV, OW, PN, SH, SL, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
1085
     *  @param tag DICOM tag specifying the attribute to be created
1086
     *  @param value string value to be set for the new element (might be empty or NULL).  The format
1087
     *    of the string value is specified by the putString() method of the corresponding VR class.
1088
     *  @param replaceOld flag indicating whether to replace an existing element or not
1089
     *  @return EC_Normal upon success, an error code otherwise.
1090
     */
1091
    OFCondition putAndInsertString(const DcmTag &tag,
1092
                                   const char *value,
1093
                                   const OFBool replaceOld = OFTrue);
1094
1095
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1096
     *  Please note that since the length of the string has to be specified explicitly, the string
1097
     *  can contain more than one NULL byte.
1098
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, OB,
1099
     *    OD, OF, OL, OV, OW, PN, SH, SL, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
1100
     *  @param tag DICOM tag specifying the attribute to be created
1101
     *  @param value string value to be set for the new element (might be empty or NULL).  The format
1102
     *    of the string value is specified by the putString() method of the corresponding VR class.
1103
     *  @param length length of the string (number of characters without the trailing NULL byte)
1104
     *  @param replaceOld flag indicating whether to replace an existing element or not
1105
     *  @return EC_Normal upon success, an error code otherwise.
1106
     */
1107
    OFCondition putAndInsertString(const DcmTag &tag,
1108
                                   const char *value,
1109
                                   const Uint32 length,
1110
                                   const OFBool replaceOld = OFTrue);
1111
1112
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1113
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT, OB,
1114
     *    OD, OF, OL, OV, OW, PN, SH, SL, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
1115
     *  @param tag DICOM tag specifying the attribute to be created
1116
     *  @param value string value to be set for the new element (might be empty).  The format of the
1117
     *    string value is specified by the putOFStringArray() method of the corresponding VR class.
1118
     *  @param replaceOld flag indicating whether to replace an existing element or not
1119
     *  @return EC_Normal upon success, an error code otherwise.
1120
     */
1121
    OFCondition putAndInsertOFStringArray(const DcmTag &tag,
1122
                                          const OFString &value,
1123
                                          const OFBool replaceOld = OFTrue);
1124
1125
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1126
     *  @note Applicable to the following VRs: OB, ox (polymorph OB/OW), px (pixel data).
1127
     *  @param tag DICOM tag specifying the attribute to be created
1128
     *  @param value value to be set for the new element (might be NULL)
1129
     *  @param count number of values (= bytes in this case) to be copied from 'value'
1130
     *  @param replaceOld flag indicating whether to replace an existing element or not
1131
     *  @return EC_Normal upon success, an error code otherwise.
1132
     */
1133
    OFCondition putAndInsertUint8Array(const DcmTag &tag,
1134
                                       const Uint8 *value,
1135
                                       const unsigned long count,
1136
                                       const OFBool replaceOld = OFTrue);
1137
1138
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1139
     *  @note Applicable to the following VRs: US, xs (US or SS).
1140
     *  @param tag DICOM tag specifying the attribute to be created
1141
     *  @param value value to be set for the new element
1142
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1143
     *    the end of or inserted within the existing value field.
1144
     *  @param replaceOld flag indicating whether to replace an existing element or not
1145
     *  @return EC_Normal upon success, an error code otherwise.
1146
     */
1147
    OFCondition putAndInsertUint16(const DcmTag &tag,
1148
                                   const Uint16 value,
1149
                                   const unsigned long pos = 0,
1150
                                   const OFBool replaceOld = OFTrue);
1151
1152
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1153
     *  @note Applicable to the following VRs: AT, OW, US, ox (polymorph OB/OW), px (pixel data),
1154
     *    xs (US or SS).
1155
     *  @param tag DICOM tag specifying the attribute to be created
1156
     *  @param value value to be set for the new element (might be NULL)
1157
     *  @param count number of values (not bytes!) to be copied from 'value'
1158
     *  @param replaceOld flag indicating whether to replace an existing element or not
1159
     *  @return EC_Normal upon success, an error code otherwise.
1160
     */
1161
    OFCondition putAndInsertUint16Array(const DcmTag &tag,
1162
                                        const Uint16 *value,
1163
                                        const unsigned long count,
1164
                                        const OFBool replaceOld = OFTrue);
1165
1166
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1167
     *  @note Applicable to the following VRs: SS, xs (US or SS).
1168
     *  @param tag DICOM tag specifying the attribute to be created
1169
     *  @param value value to be set for the new element
1170
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1171
     *    the end of or inserted within the existing value field.
1172
     *  @param replaceOld flag indicating whether to replace an existing element or not
1173
     *  @return EC_Normal upon success, an error code otherwise.
1174
     */
1175
    OFCondition putAndInsertSint16(const DcmTag &tag,
1176
                                   const Sint16 value,
1177
                                   const unsigned long pos = 0,
1178
                                   const OFBool replaceOld = OFTrue);
1179
1180
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1181
     *  @note Applicable to the following VRs: SS, xs (US or SS).
1182
     *  @param tag DICOM tag specifying the attribute to be created
1183
     *  @param value value to be set for the new element
1184
     *  @param count number of values (not bytes!) to be copied from 'value'
1185
     *  @param replaceOld flag indicating whether to replace an existing element or not
1186
     *  @return EC_Normal upon success, an error code otherwise.
1187
     */
1188
    OFCondition putAndInsertSint16Array(const DcmTag &tag,
1189
                                        const Sint16 *value,
1190
                                        const unsigned long count,
1191
                                        const OFBool replaceOld = OFTrue);
1192
1193
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1194
     *  @note Applicable to the following VRs: OL, UL.
1195
     *  @param tag DICOM tag specifying the attribute to be created
1196
     *  @param value value to be set for the new element
1197
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1198
     *    the end of or inserted within the existing value field.
1199
     *  @param replaceOld flag indicating whether to replace an existing element or not
1200
     *  @return EC_Normal upon success, an error code otherwise.
1201
     */
1202
    OFCondition putAndInsertUint32(const DcmTag &tag,
1203
                                   const Uint32 value,
1204
                                   const unsigned long pos = 0,
1205
                                   const OFBool replaceOld = OFTrue);
1206
1207
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1208
     *  @note Applicable to the following VRs: OL, UL.
1209
     *  @param tag DICOM tag specifying the attribute to be created
1210
     *  @param value value to be set for the new element
1211
     *  @param count number of values (not bytes!) to be copied from 'value'
1212
     *  @param replaceOld flag indicating whether to replace an existing element or not
1213
     *  @return EC_Normal upon success, an error code otherwise.
1214
     */
1215
    OFCondition putAndInsertUint32Array(const DcmTag &tag,
1216
                                       const Uint32 *value,
1217
                                       const unsigned long count,
1218
                                       const OFBool replaceOld = OFTrue);
1219
1220
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1221
     *  @note Applicable to the following VRs: SL.
1222
     *  @param tag DICOM tag specifying the attribute to be created
1223
     *  @param value value to be set for the new element
1224
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1225
     *    the end of or inserted within the existing value field.
1226
     *  @param replaceOld flag indicating whether to replace an existing element or not
1227
     *  @return EC_Normal upon success, an error code otherwise.
1228
     */
1229
    OFCondition putAndInsertSint32(const DcmTag &tag,
1230
                                   const Sint32 value,
1231
                                   const unsigned long pos = 0,
1232
                                   const OFBool replaceOld = OFTrue);
1233
1234
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1235
     *  @note Applicable to the following VRs: SL.
1236
     *  @param tag DICOM tag specifying the attribute to be created
1237
     *  @param value value to be set for the new element
1238
     *  @param count number of values (not bytes!) to be copied from 'value'
1239
     *  @param replaceOld flag indicating whether to replace an existing element or not
1240
     *  @return EC_Normal upon success, an error code otherwise.
1241
     */
1242
    OFCondition putAndInsertSint32Array(const DcmTag &tag,
1243
                                        const Sint32 *value,
1244
                                        const unsigned long count,
1245
                                        const OFBool replaceOld = OFTrue);
1246
1247
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1248
     *  @note Applicable to the following VRs: OV, UV.
1249
     *  @param tag DICOM tag specifying the attribute to be created
1250
     *  @param value value to be set for the new element
1251
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1252
     *    the end of or inserted within the existing value field.
1253
     *  @param replaceOld flag indicating whether to replace an existing element or not
1254
     *  @return EC_Normal upon success, an error code otherwise.
1255
     */
1256
    OFCondition putAndInsertUint64(const DcmTag &tag,
1257
                                   const Uint64 value,
1258
                                   const unsigned long pos = 0,
1259
                                   const OFBool replaceOld = OFTrue);
1260
1261
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1262
     *  @note Applicable to the following VRs: OV, UV.
1263
     *  @param tag DICOM tag specifying the attribute to be created
1264
     *  @param value value to be set for the new element
1265
     *  @param count number of values (not bytes!) to be copied from 'value'
1266
     *  @param replaceOld flag indicating whether to replace an existing element or not
1267
     *  @return EC_Normal upon success, an error code otherwise.
1268
     */
1269
    OFCondition putAndInsertUint64Array(const DcmTag &tag,
1270
                                       const Uint64 *value,
1271
                                       const unsigned long count,
1272
                                       const OFBool replaceOld = OFTrue);
1273
1274
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1275
     *  @note Applicable to the following VRs: SV.
1276
     *  @param tag DICOM tag specifying the attribute to be created
1277
     *  @param value value to be set for the new element
1278
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1279
     *    the end of or inserted within the existing value field.
1280
     *  @param replaceOld flag indicating whether to replace an existing element or not
1281
     *  @return EC_Normal upon success, an error code otherwise.
1282
     */
1283
    OFCondition putAndInsertSint64(const DcmTag &tag,
1284
                                   const Sint64 value,
1285
                                   const unsigned long pos = 0,
1286
                                   const OFBool replaceOld = OFTrue);
1287
1288
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1289
     *  @note Applicable to the following VRs: SV.
1290
     *  @param tag DICOM tag specifying the attribute to be created
1291
     *  @param value value to be set for the new element
1292
     *  @param count number of values (not bytes!) to be copied from 'value'
1293
     *  @param replaceOld flag indicating whether to replace an existing element or not
1294
     *  @return EC_Normal upon success, an error code otherwise.
1295
     */
1296
    OFCondition putAndInsertSint64Array(const DcmTag &tag,
1297
                                        const Sint64 *value,
1298
                                        const unsigned long count,
1299
                                        const OFBool replaceOld = OFTrue);
1300
1301
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1302
     *  @note Applicable to the following VRs: FL, OF.
1303
     *  @param tag DICOM tag specifying the attribute to be created
1304
     *  @param value value to be set for the new element
1305
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1306
     *    the end of or inserted within the existing value field.
1307
     *  @param replaceOld flag indicating whether to replace an existing element or not
1308
     *  @return EC_Normal upon success, an error code otherwise.
1309
     */
1310
    OFCondition putAndInsertFloat32(const DcmTag &tag,
1311
                                    const Float32 value,
1312
                                    const unsigned long pos = 0,
1313
                                    const OFBool replaceOld = OFTrue);
1314
1315
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1316
     *  @note Applicable to the following VRs: FL, OF.
1317
     *  @param tag DICOM tag specifying the attribute to be created
1318
     *  @param value value to be set for the new element
1319
     *  @param count number of values (not bytes!) to be copied from 'value'
1320
     *  @param replaceOld flag indicating whether to replace an existing element or not
1321
     *  @return EC_Normal upon success, an error code otherwise.
1322
     */
1323
    OFCondition putAndInsertFloat32Array(const DcmTag &tag,
1324
                                         const Float32 *value,
1325
                                         const unsigned long count,
1326
                                         const OFBool replaceOld = OFTrue);
1327
1328
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1329
     *  @note Applicable to the following VRs: DS, FD, OD
1330
     *  @param tag DICOM tag specifying the attribute to be created
1331
     *  @param value value to be set for the new element
1332
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1333
     *    the end of or inserted within the existing value field.
1334
     *  @param replaceOld flag indicating whether to replace an existing element or not
1335
     *  @return EC_Normal upon success, an error code otherwise.
1336
     */
1337
    OFCondition putAndInsertFloat64(const DcmTag &tag,
1338
                                    const Float64 value,
1339
                                    const unsigned long pos = 0,
1340
                                    const OFBool replaceOld = OFTrue);
1341
1342
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1343
     *  @note Applicable to the following VRs: FD, OD.
1344
     *  @param tag DICOM tag specifying the attribute to be created
1345
     *  @param value value to be set for the new element
1346
     *  @param count number of values (not bytes!) to be copied from 'value'
1347
     *  @param replaceOld flag indicating whether to replace an existing element or not
1348
     *  @return EC_Normal upon success, an error code otherwise.
1349
     */
1350
    OFCondition putAndInsertFloat64Array(const DcmTag &tag,
1351
                                         const Float64 *value,
1352
                                         const unsigned long count,
1353
                                         const OFBool replaceOld = OFTrue);
1354
1355
    /** create a new element, put specified value to it and insert the element into the dataset/item.
1356
     *  @note Applicable to the following VRs: AT.
1357
     *  @param tag DICOM tag specifying the attribute to be created
1358
     *  @param value value to be set for the new element
1359
     *  @param pos index of the value to be set (0..vm). A value can be appended to
1360
     *    the end of or inserted within the existing value field.
1361
     *  @param replaceOld flag indicating whether to replace an existing element or not
1362
     *  @return EC_Normal upon success, an error code otherwise.
1363
     */
1364
    OFCondition putAndInsertTagKey(const DcmTag &tag,
1365
                                   const DcmTagKey &value,
1366
                                   const unsigned long pos = 0,
1367
                                   const OFBool replaceOld = OFTrue);
1368
1369
    /* --- insertXXX functions: insert new element --- */
1370
1371
    /** create a new element (with no value) and insert it into the dataset/item.
1372
     *  @note Applicable to the following VRs: AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, LT,
1373
     *    OB, OD, OF, OL, OV, OW, PN, SH, SL, SQ, SS, ST, SV, TM, UC, UI, UL, UR, US, UT, UV.
1374
     *  @param tag DICOM tag specifying the attribute to be created
1375
     *  @param replaceOld flag indicating whether to replace an existing element or not
1376
     *  @return EC_Normal upon success, an error code otherwise.
1377
     */
1378
    OFCondition insertEmptyElement(const DcmTag &tag,
1379
                                   const OFBool replaceOld = OFTrue);
1380
1381
    /** looks up the given sequence in the current dataset and inserts the given item.
1382
     *  If the sequence does not exist, it is created. If necessary, multiple empty items
1383
     *  are inserted before the specified item position. Only the top-most level of the
1384
     *  dataset/item is examined (i.e. no deep-search is performed).
1385
     *  Please note that an instance of the DcmPixelItem class cannot be inserted.
1386
     *  @note Applicable to the following VRs: SQ, (pixelSQ).
1387
     *  @param seqTag DICOM tag specifying the sequence attribute to be searched for
1388
     *    (or to be created)
1389
     *  @param item item to be inserted into the sequence, must not be contained in this
1390
     *    or any other sequence. Will be deleted upon destruction of the sequence object.
1391
     *  @param itemNum position of the item (0..n-1, -1 = before last, -2 = after last)
1392
     *  @return EC_Normal upon success, an error otherwise (delete 'item' manually!).
1393
     */
1394
    OFCondition insertSequenceItem(const DcmTag &seqTag,
1395
                                   DcmItem *item,
1396
                                   const signed long itemNum = -2);
1397
1398
    /** creates new DICOM element from given attribute tag.
1399
     *  Creation of unknown attributes (e.g. private tag not being registered
1400
     *  in the dictionary) will result in a DcmElement instance of derived type
1401
     *  DcmOtherByteOtherWord.
1402
     *  @param tag attribute tag of the element to be created
1403
     *  @param privateCreator private creator identifier of the element, if element
1404
     *    tag is private (default: NULL, i.e. non-private DICOM standard tag)
1405
     *  @return pointer to newly created element upon success, NULL pointer otherwise
1406
     *
1407
     */
1408
     static DcmElement *newDicomElement(const DcmTagKey &tag,
1409
                                        const char *privateCreator = NULL);
1410
1411
    /** creates new DICOM element from given attribute tag.
1412
     *  Creation of unknown attributes (e.g. private tag not being registered
1413
     *  in the dictionary) will result in a DcmElement instance of derived type
1414
     *  DcmOtherByteOtherWord.
1415
     *  @param newElement pointer to newly created element returned in this parameter
1416
     *    upon success, NULL pointer otherwise
1417
     *  @param tag attribute tag of the element to be created
1418
     *  @param privateCreator private creator identifier of the element, if element
1419
     *    tag is private (default: NULL, i.e. non-private DICOM standard tag)
1420
     *  @return EC_Normal upon success, an error code otherwise
1421
     */
1422
    static OFCondition newDicomElement(DcmElement *&newElement,
1423
                                       const DcmTagKey &tag,
1424
                                       const char *privateCreator = NULL);
1425
1426
    /** creates new DICOM element from given attribute tag and VR.
1427
     *  Creation of unknown attributes (e.g. private tag not being registered
1428
     *  in the dictionary) will result in a DcmElement instance of derived type
1429
     *  DcmOtherByteOtherWord.
1430
     *  @param newElement pointer to newly created element returned in this parameter
1431
     *    upon success, NULL pointer otherwise
1432
     *  @param tag attribute tag and VR of the element to be created
1433
     *  @return EC_Normal upon success, an error code otherwise
1434
     */
1435
     static OFCondition newDicomElementWithVR(DcmElement *&newElement,
1436
                                              const DcmTag &tag);
1437
1438
  protected:
1439
1440
    /// the list of elements maintained by this object
1441
    DcmList *elementList;
1442
1443
    /** flag used during suspended I/O. Indicates whether the last element
1444
     *  was completely or only partially read/written during the last call
1445
     *  to read/write.
1446
     */
1447
    OFBool lastElementComplete;
1448
1449
    /** used during reading. Contains the position in the stream where
1450
     *  the item started (needed for calculating the remaining number of
1451
     *  bytes available for a fixed-length item).
1452
     */
1453
    offile_off_t fStartPosition;
1454
1455
    /** This function reads tag and length information from inStream and
1456
     *  returns this information to the caller. When reading information,
1457
     *  the transfer syntax which was passed is accounted for. If the
1458
     *  transfer syntax shows an explicit value representation, the data
1459
     *  type of this object is also read from the stream. In general, this
1460
     *  function follows the rules which are specified in the DICOM standard
1461
     *  (see DICOM standard (year 2000) part 5, section 7) (or the corresponding
1462
     *  section in a later version of the standard) concerning the encoding
1463
     *  of a dataset.
1464
     *  @param inStream  The stream which contains the information.
1465
     *  @param xfer      The transfer syntax which was used to encode the
1466
     *                   information in inStream.
1467
     *  @param tag       Contains in the end the tag that was read.
1468
     *  @param length    Contains in the end the length value that was read.
1469
     *  @param bytesRead Contains in the end the amount of bytes which were
1470
     *                   read from inStream.
1471
     *  @return status, EC_Normal if successful, an error code otherwise
1472
     */
1473
    OFCondition readTagAndLength(DcmInputStream &inStream,       // inout
1474
                                 const E_TransferSyntax xfer,    // in
1475
                                 DcmTag &tag,                    // out
1476
                                 Uint32 &length,                 // out
1477
                                 Uint32 &bytesRead);             // out
1478
1479
    /** This function creates a new DcmElement object on the basis of the newTag
1480
     *  and newLength information which was passed, inserts this new element into
1481
     *  elementList, reads the actual data value which belongs to this element
1482
     *  (attribute) from the inStream and also assigns this information to the
1483
     *  object which was created at the beginning.
1484
     *  @param inStream      The stream which contains the information.
1485
     *  @param newTag        The tag of the element of which the information is
1486
     *                       being read.
1487
     *  @param newLength     The length of the information which is being read.
1488
     *  @param xfer          The transfer syntax which was used to encode the
1489
     *                       information in inStream.
1490
     *  @param glenc         Encoding type for group length. Specifies what will
1491
     *                       be done with group length tags.
1492
     *  @param maxReadLength Maximum read length for reading the attribute value.
1493
     *  @return status, EC_Normal if successful, an error code otherwise
1494
     */
1495
    OFCondition readSubElement(DcmInputStream &inStream,         // inout
1496
                               DcmTag &newTag,                   // inout
1497
                               const Uint32 newLength,           // in
1498
                               const E_TransferSyntax xfer,      // in
1499
                               const E_GrpLenEncoding glenc,     // in
1500
                               const Uint32 maxReadLength = DCM_MaxReadLength);
1501
1502
    /** This function reads the first 6 bytes from the input stream and determines
1503
     *  the transfer syntax which was used to code the information in the stream.
1504
     *  The decision is based on two questions: a) Did we encounter a valid tag?
1505
     *  and b) Do the last 2 bytes which were read from the stream represent a valid
1506
     *  VR? In certain special cases, where the transfer syntax cannot be determined
1507
     *  without doubt, we want to guess the most likely transfer syntax (see code).
1508
     *  @param inStream The stream which contains the coded information.
1509
     *  @return The transfer syntax which was determined.
1510
     */
1511
    E_TransferSyntax checkTransferSyntax(DcmInputStream &inStream);
1512
1513
    /** check whether the given tag requires some special handling regarding the VR
1514
     *  (i.e.\ in case it is undefined and multiple values are possible). If required,
1515
     *  the VR of the given element tag is then updated according to the DICOM
1516
     *  standard, e.g. the VR of PixelPaddingValue (if undefined) is set to 'SS' or
1517
     *  'US' depending on the value of PixelRepresentation.
1518
     *  @param item dataset or item that can be used to lookup other element values
1519
     *  @param tag tag of the element to be checked and updated (if required)
1520
     *  @return OFTrue if the VR has changed, OFFalse otherwise
1521
     */
1522
    OFBool checkAndUpdateVR(DcmItem &item,
1523
                            DcmTag &tag);
1524
1525
    /** creates new DICOM element from given attribute tag.
1526
     *  Helper function used by DICOM parser (friend of this class) and thus
1527
     *  hidden from the public interface. DcmItem's readSubElement() uses
1528
     *  this function when reading new elements from input data. This method
1529
     *  internally sets the length of the new element, but does not allocate
1530
     *  any memory for the element's value. Thus subsequent access to an element
1531
     *  created by this method can lead to crashes. DcmItem instead initializes
1532
     *  the value itself a bit later during the read process.
1533
     *  @param newElement pointer to newly created element returned in this
1534
     *    parameter upon success, NULL pointer otherwise
1535
     *  @param tag attribute tag of the element to be created. VR of tag may be
1536
     *    updated within the method.
1537
     *  @param length attribute value length of the element to be created
1538
     *  @param privateCreatorCache cache object for private creator elements
1539
     *    in the current dataset
1540
     *  @param readAsUN flag indicating whether parser is currently handling
1541
     *    UN element that must be read in implicit VR little endian; updated
1542
     *    upon return
1543
     *  @return EC_Normal upon success, an error code otherwise
1544
     */
1545
    static OFCondition newDicomElement(DcmElement *&newElement,
1546
                                       DcmTag &tag,
1547
                                       const Uint32 length,
1548
                                       DcmPrivateTagCache *privateCreatorCache,
1549
                                       OFBool& readAsUN);
1550
1551
  private:
1552
1553
    /** helper function for search(). May only be called if elementList is non-empty.
1554
     *  Performs hierarchical search for given tag and pushes pointer of sub-element
1555
     *  on result stack if found
1556
     *  @param tag tag key to be searched
1557
     *  @param resultStack upon successful return, pointer to element pushed onto this stack
1558
     *  @param searchIntoSub flag indicating whether recursive search is desired
1559
     *  @return EC_Normal if tag found and stack modified, EC_TagNotFound if tag not found
1560
     *    and stack unmodified
1561
     */
1562
    OFCondition searchSubFromHere(const DcmTagKey &tag,          // in
1563
                                  DcmStack &resultStack,         // inout
1564
                                  OFBool searchIntoSub );        // in
1565
1566
    /** helper function that interprets the given pointer as a pointer to an
1567
     *  array of two characters and checks whether these two characters form
1568
     *  a valid standard DICOM VR.
1569
     *  @param atposition pointer to array of (at least) two bytes interpreted as VR
1570
     *  @return true if standard VR, false otherwise
1571
     */
1572
    static OFBool foundVR(const Uint8* atposition);
1573
1574
    /// cache for private creator tags and identifiers
1575
    DcmPrivateTagCache privateCreatorCache;
1576
1577
    /// maximum sequence nesting depth for parsing
1578
    /// (0 = compile-time default DCMTK_MAX_SEQUENCE_NESTING, -1 = unlimited)
1579
    Sint32 maxNestingDepth;
1580
1581
  public:
1582
1583
    /** set the maximum permitted sequence nesting depth for parsing.
1584
     *  This limit is applied to the input stream before parsing in
1585
     *  loadFile() and read().
1586
     *  - Value 0 (default): apply the compile-time default
1587
     *    (DCMTK_MAX_SEQUENCE_NESTING, default is 64)
1588
     *  - Value -1: disable the check (allow unlimited nesting)
1589
     *  - Value > 0: use this value as the maximum permitted nesting depth
1590
     *  @param maxDepth maximum nesting depth setting
1591
     */
1592
0
    void setMaxNestingDepth(Sint32 maxDepth) { maxNestingDepth = maxDepth; }
1593
1594
    /** return the maximum permitted sequence nesting depth for parsing.
1595
     *  @return maximum nesting depth setting
1596
     *    (0 = compile-time default DCMTK_MAX_SEQUENCE_NESTING, -1 = unlimited)
1597
     */
1598
    Sint32 getMaxNestingDepth() const { return maxNestingDepth; }
1599
};
1600
1601
/** Checks whether left hand side item is smaller than right hand side
1602
 *  item. Uses DcmItem's compare() method in order to perform the
1603
 *  comparison. See DcmItem::compare() for details.
1604
 *  @param lhs left hand side of the comparison
1605
 *  @param rhs right hand side of the comparison
1606
 *  @return OFTrue if lhs is smaller than rhs, OFFalse otherwise
1607
 */
1608
inline OFBool operator< (const DcmItem& lhs, const DcmItem& rhs)
1609
0
{
1610
0
  return ( lhs.compare(rhs) < 0 );
1611
0
}
1612
1613
/** Checks whether left hand side item is greater than right hand side
1614
 *  item. Uses DcmItem's compare() method in order to perform the
1615
 *  comparison. See DcmItem::compare() for details.
1616
 *  @param lhs left hand side of the comparison
1617
 *  @param rhs right hand side of the comparison
1618
 *  @return OFTrue if lhs is greater than rhs, OFFalse otherwise
1619
 */
1620
inline OFBool operator> (const DcmItem& lhs, const DcmItem& rhs)
1621
0
{
1622
0
  return rhs < lhs;
1623
0
}
1624
1625
/** Checks whether left hand side item is smaller than or equal to right hand
1626
 *  side item. Uses DcmItem's compare() method in order to perform the
1627
 *  comparison. See DcmItem::compare() for details.
1628
 *  @param lhs left hand side of the comparison
1629
 *  @param rhs right hand side of the comparison
1630
 *  @return OFTrue if lhs is smaller than rhs or both are equal, OFFalse
1631
 *          otherwise
1632
 */
1633
inline OFBool operator<=(const DcmItem& lhs, const DcmItem& rhs)
1634
0
{
1635
0
  return !(lhs > rhs);
1636
0
}
1637
1638
/** Checks whether left hand side element is greater than or equal to right hand
1639
 *  side element. Uses DcmElement's compare() method in order to perform the
1640
 *  comparison. See DcmElement::compare() for details.
1641
 *  @param lhs left hand side of the comparison
1642
 *  @param rhs right hand side of the comparison
1643
 *  @return OFTrue if lhs is greater than rhs or both are equal, OFFalse
1644
 *          otherwise
1645
 */
1646
inline OFBool operator>=(const DcmItem& lhs, const DcmItem& rhs)
1647
0
{
1648
0
  return !(lhs < rhs);
1649
0
}
1650
1651
//
1652
// SUPPORT FUNCTIONS
1653
//
1654
1655
1656
/** helper function for DcmElement::nextObject.
1657
 *  hierarchically traverses all datasets/items after the position indicated by the call stack
1658
 *  @param st stack
1659
 *  @return EC_Normal upon success, an error code otherwise
1660
 */
1661
DCMTK_DCMDATA_EXPORT OFCondition nextUp(DcmStack &st);
1662
1663
1664
#endif // DCITEM_H