MeVisLab Toolbox Reference
DCMTree_Tag.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef DCM_TREE_TAG_H
14 #define DCM_TREE_TAG_H
15 
16 #include "DCMTree_Lib.h"
17 #include "DCMTree_TagInfo.h"
18 #include "DCMTree_Value.h"
19 #include "DCMTree_Defines.h"
20 
21 #ifdef _MSC_VER
22  // 4350: behavior change
23  // 4365: signed/unsigned mismatch
24  // 4548: expression before comma has no effect; expected expression with side-effect
25  #pragma warning (push)
26  #pragma warning (disable : 4350 4365 4548)
27 #endif
28 
29 #include <istream>
30 #include <ostream>
31 #include <fstream>
32 
33 #ifdef _MSC_VER
34  #pragma warning (pop)
35 #endif
36 
37 namespace DCMTree
38 {
40 
43  {
44  public:
46  Tag();
47 
52  Tag(const TagInfo &info);
53 
55  Tag(const Tag &other);
56 
60  Tag(const Tag &other, unsigned short slot);
61 
63  ~Tag() override;
64 
69  Tag &operator=(const Tag &other);
70 
75  bool operator==( const Tag& other ) const;
76  bool operator!=( const Tag& other ) const;
77 
82  bool isEqual( const Tag& other, double tolerance = 0 ) const;
83 
87  virtual TagPtr copy() const;
88 
92  const TagInfo &info() const;
93 
98  const TreePtrVector &sequenceItems() const;
99 
105 
110  boost::uint32_t numberOfSequenceItems() const;
111 
117 
122  void dropSequenceItem(unsigned idx);
123 
127  virtual boost::uint32_t numberOfValues() const;
128 
134  void dropValues();
135 
139  bool isEmpty() const;
140 
144  bool isSequence() const;
145 
150  bool isNull (unsigned idx) const;
151 
156  bool isSequenceItemNull (unsigned idx) const;
157 
162  void setInfo (const TagInfo &info);
163 
173  void addSequenceItem (const TreePtr &sequence);
174 
179 
185  void setSequenceItem (const TreePtr &sequence,unsigned idx=0);
186 
193  std::string toString (unsigned int idx, StringTrimMode trimMode = DO_NOT_TRIM) const;
194 
202  std::string toString(StringTrimMode trimMode = DO_NOT_TRIM) const;
203 
209  void setValue (std::string value,unsigned int idx=0);
210 
215  void addValue (std::string value);
216 
222  Date toDate (unsigned int idx=0) const;
223 
229  void setValue (Date value,unsigned int idx=0);
230 
235  void addValue (Date value);
236 
242  Time toTime (unsigned int idx=0) const;
243 
249  void setValue (Time value,unsigned int idx=0);
250 
255  void addValue (Time value);
256 
262  DateTime toDateTime (unsigned int idx=0) const;
263 
269  void setValue (DateTime value,unsigned int idx=0);
270 
275  void addValue (DateTime value);
276 
282  float toFloat (unsigned int idx=0) const;
283 
289  void setValue (float value,unsigned int idx=0);
290 
295  void addValue (float value);
296 
302  double toDouble (unsigned int idx=0) const;
303 
309  void setValue (double value,unsigned int idx=0);
310 
315  void addValue (double value);
316 
322  int toInt (unsigned int idx=0) const;
323 
329  void setValue (int value,unsigned int idx=0);
330 
335  void addValue (int value);
336 
342  unsigned int toUInt (unsigned int idx=0) const;
343 
349  void setValue (unsigned int value,unsigned int idx=0);
350 
355  void addValue (unsigned int value);
356 
362  short int toShort (unsigned int idx=0) const;
363 
369  void setValue (short int value,unsigned int idx=0);
370 
375  void addValue (short int value);
376 
382  unsigned short toUShort (unsigned int idx=0) const;
383 
389  void setValue (unsigned short int value,unsigned int idx=0);
390 
395  void addValue (unsigned short int value);
396 
402  const Value &getValue (unsigned int idx=0) const;
403 
409  void setValue (const Value &value,unsigned int idx=0);
410 
415  virtual Value &addValue();
416 
421  virtual boost::uint32_t getValueSize (unsigned int idx) const;
422 
426  virtual boost::uint32_t getValueSize () const;
427 
434  virtual void fromStream (std::istream &in, bool readName, size_t maxSize = 0);
435 
441  virtual void toStream (std::ostream &out, bool writeName) const;
442 
450  int compare(const Tag& tag, double tolerance = 0.0001) const;
451 
459  void setVr( Vr vr );
460 
461  void serializeX (DCMTree_Serialization::Sink &sink) const override;
463 
464  protected:
465  TagInfo const & tagInfo() const { return _info; }
466 
467  private:
474  int compareNumerical(const Tag& tag, int nMin, double tolerance) const;
475 
482  int compareBytes(const Tag& tag, int nMin) const;
483 
487  void typeAndRangeChecking (const VRCType &vrctype,const unsigned int &idx) const;
488 
492  void typeChecking (const VRCType &vrctype) const;
493 
497  bool isOfType(const VRCType &vrctype) const;
498 
502  void rangeChecking (const unsigned int &idx) const;
503 
507  void sequenceRangeChecking (const unsigned int &idx) const;
508 
509  TagInfo _info;
510  ValueVector _values;
511  TreePtrVector _sequences;
512  };
513 
514  inline std::ostream &operator << (std::ostream &out,const Tag &t)
515  {
516  t.toStream (out, false);
517  return out;
518  }
519 
520  inline std::istream &operator >> (std::istream &in,Tag &t)
521  {
522  t.fromStream (in, false);
523  return in;
524  }
525 }
526 
527 #endif
528 
529 
530 
#define DCMTREE_EXPORT
Class to carry meta information about a specific tag.
Class to represent one DICOM tag.
Definition: DCMTree_Tag.h:43
double toDouble(unsigned int idx=0) const
Returns the value of tag value idx as double.
virtual Value & addValue()
Adds a value and return a reference for further processing.
bool isEqual(const Tag &other, double tolerance=0) const
Compares the tag with all contained values for equality; use tolerance for float value comparison.
int toInt(unsigned int idx=0) const
Returns the value of tag value idx as int.
DateTime toDateTime(unsigned int idx=0) const
Returns the value of tag value idx as datetime.
bool operator==(const Tag &other) const
Compares the tag with all contained values for equality.
void setValue(std::string value, unsigned int idx=0)
Sets the value of tag value idx as string.
void serializeX(DCMTree_Serialization::Sink &sink) const override
Writes data of this object to sink.
bool operator!=(const Tag &other) const
void addValue(float value)
Adds a value of this tag as float.
virtual boost::uint32_t numberOfValues() const
Returns the number of values of this tag.
void addValue(std::string value)
Converts string to one or more values and add them to this tag.
~Tag() override
Destructor.
void addValue(Date value)
Adds a value of this tag as date.
Tag(const Tag &other)
Copy constructor that uses operator=.
void addSequenceItem(const TreePtr &sequence)
Adds the given TreePtr as a sequence to this tag.
void addValue(DateTime value)
Adds a value of this tag as datetime.
void addValue(Time value)
Adds a value of this tag as time.
bool isEmpty() const
Returns true if this tag has no sequences and no values.
unsigned short toUShort(unsigned int idx=0) const
Returns the value of tag value idx as unsigned short.
void deserializeX(DCMTree_Serialization::Source &source) override
Overwrites data of this object with data from source.
void setSequenceItem(const TreePtr &sequence, unsigned idx=0)
Sets the sequence with index idx.
virtual TagPtr copy() const
Makes a deep copy of this.
void setValue(short int value, unsigned int idx=0)
Sets the value of tag value idx as short.
void addValue(short int value)
Adds a value of this tag as short.
void addValue(double value)
Adds a value of this tag as double.
bool isSequence() const
Returns true if the VR of this tag is SQ.
void setValue(DateTime value, unsigned int idx=0)
Sets the value of tag value idx as datetime.
int compare(const Tag &tag, double tolerance=0.0001) const
Compares this to tag and returns -1 if this < tag, 0 if this == tag, and 1 if this > tag.
virtual void toStream(std::ostream &out, bool writeName) const
Copies this instance recursively into the given stream.
void dropValues()
Drop all values of this tag.
Tag(const Tag &other, unsigned short slot)
Copy constructor for private tags with a given private slot.
TagInfo const & tagInfo() const
Definition: DCMTree_Tag.h:465
short int toShort(unsigned int idx=0) const
Returns the value of tag value idx as short.
unsigned int toUInt(unsigned int idx=0) const
Returns the value of tag-value idx as unsigned int.
Tag()
Constructor.
void dropSequenceItem(unsigned idx)
Drop the idx sequences of this tag.
const TagInfo & info() const
Returns the tag information (type, etc.) of this tag.
const Value & getValue(unsigned int idx=0) const
Returns the value object with index idx.
TreePtrVector & sequenceItems()
Accesses the probably embedded sequences of this tag.
void setValue(int value, unsigned int idx=0)
Sets the value of tag value idx as int.
boost::uint32_t numberOfSequenceItems() const
Returns the number of embedded sequence items of this tag.
void setValue(double value, unsigned int idx=0)
Sets the value of tag value idx as double.
void setValue(unsigned short int value, unsigned int idx=0)
Sets the value of tag value idx as unsigned short.
Tag & operator=(const Tag &other)
Deep copies all values from other to this.
void addValue(int value)
Adds a value of this tag as int.
void setInfo(const TagInfo &info)
Sets the tag info for this tag.
const TreePtrVector & sequenceItems() const
Accesses the probably embedded sequences of this tag.
std::string toString(unsigned int idx, StringTrimMode trimMode=DO_NOT_TRIM) const
Returns the value of tag value idx as a string.
Tag(const TagInfo &info)
Constructor info defines the data type, name, etc., of this tag.
void setValue(const Value &value, unsigned int idx=0)
Sets the value object with index idx.
float toFloat(unsigned int idx=0) const
Returns the value of tag value idx as float.
void setValue(Date value, unsigned int idx=0)
Sets the value of tag value idx as date.
void setValue(Time value, unsigned int idx=0)
Sets thevalue of tag value idx as time.
void addValue(unsigned int value)
Adds a value of this tag as unsigned int.
Date toDate(unsigned int idx=0) const
Returns the value of tag value idx as date.
void setVr(Vr vr)
Sets a new value representation if the VR is unknown.
void setValue(float value, unsigned int idx=0)
Sets the value of tag value idx as float.
Time toTime(unsigned int idx=0) const
Returns the value of tag value idx as time.
void setValue(unsigned int value, unsigned int idx=0)
Sets the value of tag value idx as unsigned int.
bool isNull(unsigned idx) const
Checks whether the values with index idx is null.
virtual boost::uint32_t getValueSize(unsigned int idx) const
Returns the size in bytes of the data of the value-object with index idx.
virtual void fromStream(std::istream &in, bool readName, size_t maxSize=0)
Extracts this instance from the given stream.
virtual boost::uint32_t getValueSize() const
Returns the total size in bytes of the data of the values.
TreePtr & addSequenceItem()
Adds a sequence to this tag and returns a reference to it for further processing.
bool isSequenceItemNull(unsigned idx) const
Checks whether the sequence with index idx is null.
void addValue(unsigned short int value)
Adds a value of this tag as unsigned short.
void dropSequenceItems()
Drops all sequences of this tag.
std::string toString(StringTrimMode trimMode=DO_NOT_TRIM) const
Converts the complete tag to a string.
Class to store tag values.
Definition: DCMTree_Value.h:45
Interface that provides a method to deserialize an object.
Interface that provides a method to serialize an object.
Interface of a data sink for the serialization of objects.
Interface of a data source for the deserialization of objects.
Class to dump a DCMTree DICOM message into a human-readable file.
std::pair< Date, Time > DateTime
DateTime.
Definition: DCMTree_Lib.h:195
Vr
DICOM VR.
Definition: DCMTree_Lib.h:202
std::istream & operator>>(std::istream &in, Message &m)
VRCType
VR interpretation in C++.
Definition: DCMTree_Lib.h:211
boost::shared_ptr< Tag > TagPtr
Shared pointer to tag.
Definition: DCMTree_Lib.h:53
std::vector< TreePtr > TreePtrVector
A vector of TreePtr - used for sequences.
Definition: DCMTree_Lib.h:79
std::vector< Value > ValueVector
boost::shared_ptr< Tree > TreePtr
Shared pointer to a DCMTree::Tree.
Definition: DCMTree_Lib.h:64
StringTrimMode
Definition: DCMTree_Tag.h:39
@ TRIM_STRING
Definition: DCMTree_Tag.h:39
@ DO_NOT_TRIM
Definition: DCMTree_Tag.h:39
std::ostream & operator<<(std::ostream &out, const Message &m)
boost::graph_traits< ml_graph_ptr >::vertex_descriptor source(graph_traits< ml_graph_ptr >::edge_descriptor e, const ml_graph_ptr)
Returns the vertex descriptor for u of the edge (u,v) represented by e.
Date class for DCMTree library.
Definition: DCMTree_Lib.h:175
Time class for DCMTree library.
Definition: DCMTree_Lib.h:185