GDCM  2.4.5
gdcmVL.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: GDCM (Grassroots DICOM). A DICOM library
4 
5  Copyright (c) 2006-2011 Mathieu Malaterre
6  All rights reserved.
7  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef GDCMVL_H
15 #define GDCMVL_H
16 
17 #include "gdcmTypes.h"
18 
19 #include <iostream>
20 
21 namespace gdcm
22 {
23 
30 {
31 public:
32  typedef uint32_t Type;
33  VL(uint32_t vl = 0) : ValueLength(vl) { }
34 
35  // FIXME: ugly
36  static uint32_t GetVL32Max() { return 0xFFFFFFFF; }
37  static uint16_t GetVL16Max() { return 0xFFFF; }
38 
39  bool IsUndefined() const {
40  return ValueLength == 0xFFFFFFFF;
41  }
42  void SetToUndefined() {
43  ValueLength = 0xFFFFFFFF;
44  }
45 
47  bool IsOdd() const {
48  return !IsUndefined() && ValueLength % 2;
49  }
50 
52  VL& operator+=(VL const &vl) {
53  ValueLength += vl.ValueLength;
54  return *this;
55  }
57  ++ValueLength;
58  return *this;
59  }
60  VL operator++(int) {
61  uint32_t tmp(ValueLength);
62  ++ValueLength;
63  return tmp;
64  }
65 
66  operator uint32_t () const { return ValueLength; }
67 
68  VL GetLength() const {
69  // VL cannot know it's length...well in implicit yes...
70  // TODO: need to check we cannot call this function from an Explicit element
71  return 4;
72  }
73 
74  friend std::ostream& operator<<(std::ostream& os, const VL& vl);
75 
76  // PURPOSELY not implemented (could not differenciate 16bits vs 32bits VL)
77  //friend std::istream& operator>>(std::istream& is, VL& n);
78 
79  template <typename TSwap>
80  std::istream &Read(std::istream &is)
81  {
82  is.read((char*)(&ValueLength), sizeof(uint32_t));
83  TSwap::SwapArray(&ValueLength,1);
84  return is;
85  }
86 
87  template <typename TSwap>
88  std::istream &Read16(std::istream &is)
89  {
90  uint16_t copy;
91  is.read((char*)(&copy), sizeof(uint16_t));
92  TSwap::SwapArray(&copy,1);
93  ValueLength = copy;
94  assert( ValueLength <= 65535 /*UINT16_MAX*/ ); // ?? doh !
95  return is;
96  }
97 
98  template <typename TSwap>
99  const std::ostream &Write(std::ostream &os) const
100  {
101  uint32_t copy = ValueLength;
102  if( IsOdd() )
103  {
104  ++copy;
105  }
106  TSwap::SwapArray(&copy,1);
107  return os.write((char*)(&copy), sizeof(uint32_t));
108  }
109 
110  template <typename TSwap>
111  const std::ostream &Write16(std::ostream &os) const
112  {
113  assert( ValueLength <= 65535 /*UINT16_MAX*/ );
114  uint16_t copy = (uint16_t)ValueLength;
115  if( IsOdd() )
116  {
117  ++copy;
118  }
119  TSwap::SwapArray(&copy,1);
120  return os.write((char*)(&copy), sizeof(uint16_t));
121  }
122 
123 private:
124  uint32_t ValueLength;
125 };
126 //----------------------------------------------------------------------------
127 inline std::ostream& operator<<(std::ostream& os, const VL& val)
128 {
129  os << /*std::hex <<*/ val.ValueLength;
130  return os;
131 }
132 
133 } // end namespace gdcm
134 
135 #endif //GDCMVL_H
VL GetLength() const
Definition: gdcmVL.h:68
VL operator++(int)
Definition: gdcmVL.h:60
VL(uint32_t vl=0)
Definition: gdcmVL.h:33
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
Value Length.
Definition: gdcmVL.h:29
static uint16_t GetVL16Max()
Definition: gdcmVL.h:37
bool IsOdd() const
Return whether or not the VL is odd or not.
Definition: gdcmVL.h:47
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition: gdcmDirectory.h:88
std::istream & Read(std::istream &is)
Definition: gdcmVL.h:80
void SetToUndefined()
Definition: gdcmVL.h:42
const std::ostream & Write16(std::ostream &os) const
Definition: gdcmVL.h:111
const std::ostream & Write(std::ostream &os) const
Definition: gdcmVL.h:99
static uint32_t GetVL32Max()
Definition: gdcmVL.h:36
bool IsUndefined() const
Definition: gdcmVL.h:39
VL & operator+=(VL const &vl)
+= operator
Definition: gdcmVL.h:52
std::istream & Read16(std::istream &is)
Definition: gdcmVL.h:88
Definition: gdcmASN1.h:20
VL & operator++()
Definition: gdcmVL.h:56
uint32_t Type
Definition: gdcmVL.h:32

Generated on Fri Sep 25 2015 17:58:24 for GDCM by doxygen 1.8.9.1
SourceForge.net Logo