14 #ifndef GDCMBYTEVALUE_H
15 #define GDCMBYTEVALUE_H
28 #if !defined(SWIGPYTHON) && !defined(SWIGCSHARP) && !defined(SWIGJAVA) && !defined(SWIGPHP)
39 Internal(array, array+vl),Length(vl) {
43 Internal.resize(vl+1);
49 ByteValue(std::vector<char> &v):Internal(v),Length((uint32_t)v.size()) {}
60 void PrintASCII(std::ostream &os,
VL maxlength )
const;
62 void PrintHex(std::ostream &os,
VL maxlength)
const;
66 assert( Length == 2 );
72 if( Internal.empty() ) assert( Length == 0 );
73 return Internal.empty();
82 void SetLength(
VL vl);
84 operator const std::vector<char>& ()
const {
return Internal; }
87 Internal = val.Internal;
93 if( Length != val.Length )
95 if( Internal == val.Internal )
102 return Length == bv.Length && Internal == bv.Internal;
112 if(!Internal.empty())
return &Internal[0];
117 std::vector<char>::iterator it = Internal.begin();
118 for(; it != Internal.end(); ++it) *it = c;
120 bool GetBuffer(
char *buffer,
unsigned long length)
const;
124 assert( !(Internal.size() % 2) );
125 os.write(&Internal[0], Internal.size() );
130 template <
typename TSwap,
typename TType>
131 std::istream &
Read(std::istream &is,
bool readvalues =
true) {
140 is.read(&Internal[0], Length);
141 assert( Internal.size() == Length || Internal.size() == Length + 1 );
142 TSwap::SwapArray((TType*)&Internal[0], Internal.size() /
sizeof(TType) );
146 is.seekg(Length, std::ios::cur);
152 template <
typename TSwap>
153 std::istream &
Read(std::istream &is) {
154 return Read<TSwap,uint8_t>(is);
158 template <
typename TSwap,
typename TType>
159 std::ostream
const &
Write(std::ostream &os)
const {
160 assert( !(Internal.size() % 2) );
161 if( !Internal.empty() ) {
163 std::vector<char> copy = Internal;
164 TSwap::SwapArray((TType*)©[0], Internal.size() /
sizeof(TType) );
165 os.write(©[0], copy.size());
170 template <
typename TSwap>
171 std::ostream
const &
Write(std::ostream &os)
const {
172 return Write<TSwap,uint8_t>(os);
182 assert( length <= Length );
183 for(
unsigned int i=0; i<length; i++)
185 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
186 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
196 void PrintPNXML(std::ostream &os)
const;
197 void PrintASCIIXML(std::ostream &os)
const;
198 void PrintHexXML(std::ostream &os)
const;
200 void Print(std::ostream &os)
const {
203 if( !Internal.empty() )
205 if( IsPrintable(Length) )
208 std::vector<char>::size_type length = Length;
209 if( Internal.back() == 0 ) --length;
210 std::copy(Internal.begin(), Internal.begin()+length,
211 std::ostream_iterator<char>(os));
214 os <<
"Loaded:" << Internal.size();
219 os <<
"(no value available)";
232 std::vector<char> Internal;
242 #endif //GDCMBYTEVALUE_H
ByteValue(std::vector< char > &v)
Definition: gdcmByteValue.h:49
std::istream & Read(std::istream &is, bool readvalues=true)
Definition: gdcmByteValue.h:131
bool IsPrintable(VL length) const
Checks whether a 'ByteValue' is printable or not (in order to avoid corrupting the terminal of invoca...
Definition: gdcmByteValue.h:181
Class to represent the value of a Data Element.
Definition: gdcmValue.h:31
VL GetLength() const
Definition: gdcmByteValue.h:78
~ByteValue()
Definition: gdcmByteValue.h:54
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:159
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
bool operator==(const ByteValue &val) const
Definition: gdcmByteValue.h:92
void Print(std::ostream &os) const
Definition: gdcmByteValue.h:200
Value Length.
Definition: gdcmVL.h:29
#define gdcmDebugMacro(msg)
Debug.
Definition: gdcmTrace.h:119
ByteValue(const char *array=0, VL const &vl=0)
Definition: gdcmByteValue.h:38
void Fill(char c)
Definition: gdcmByteValue.h:115
bool operator==(const Value &val) const
Definition: gdcmByteValue.h:99
Class to represent binary value (array of bytes)
Definition: gdcmByteValue.h:35
void PrintGroupLength(std::ostream &os)
Definition: gdcmByteValue.h:65
bool WriteBuffer(std::ostream &os) const
Definition: gdcmByteValue.h:121
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:171
VL ComputeLength() const
Definition: gdcmByteValue.h:80
void SetLengthOnly(VL vl)
Definition: gdcmByteValue.h:227
std::istream & Read(std::istream &is)
Definition: gdcmByteValue.h:153
void Clear()
Definition: gdcmByteValue.h:107
bool IsEmpty() const
Definition: gdcmByteValue.h:70
const char * GetPointer() const
Definition: gdcmByteValue.h:111
Definition: gdcmASN1.h:20
ByteValue & operator=(const ByteValue &val)
Definition: gdcmByteValue.h:86