vil_dicom_stream.cxx
Go to the documentation of this file.
1 #include <limits>
2 #include <vil/vil_config.h>
3 #if HAS_DCMTK
4 
5 #include "vil_dicom_stream.h"
6 #include <vil/vil_stream.h>
7 #include <dcmtk/dcmdata/dcerror.h>
8 
9 #include <cassert>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
14 // ===========================================================================
15 // stream producer
16 
19  : vs_( in_vs )
20 {
21  vs_->ref();
22 }
23 
24 
27 {
28  vs_->unref();
29 }
30 
31 
32 OFBool
34 good() const
35 {
36  return vs_->ok();
37 }
38 
39 
40 OFCondition
42 status() const
43 {
44  return good() ? EC_Normal : EC_InvalidStream;
45 }
46 
47 
48 OFBool
50 eos()
51 {
52  return vs_->tell() >= vs_->file_size();
53 }
54 
55 
56 offile_off_t
58 avail()
59 {
60  vil_streampos n = vs_->file_size() - vs_->tell();
61  assert( n >= 0 );
62  //assert ensures that the cast will succeed.
63  //apparently dicom streams only support 32 bit positions
64  //whereas vil_streams now support 64 bit positions (when
65  //available)
66  assert( n <= (vil_streampos)std::numeric_limits<offile_off_t>::max() );
67  return (offile_off_t)n;
68 }
69 
70 
71 offile_off_t
73 read( void *buf, offile_off_t buflen )
74 {
75  vil_streampos n = vs_->read( buf, buflen );
76  assert( n >= 0 );
77  //assert ensures that the cast will succeed.
78  //apparently dicom streams only support 32 bit positions
79  //whereas vil_streams now support 64 bit positions (when
80  //available)
81  assert( n <= (vil_streampos)std::numeric_limits<offile_off_t>::max() );
82  return (offile_off_t)n;
83 }
84 
85 
86 offile_off_t
88 skip(offile_off_t skiplen)
89 {
90  vs_->seek( vs_->tell() + skiplen );
91  return skiplen;
92 }
93 
94 
95 void
97 putback(offile_off_t num)
98 {
99  vs_->seek( vs_->tell() - (long int)num );
100 }
101 
102 
103 // ===========================================================================
104 // stream factory
105 
108  : vs_( in_vs )
109 {
110  vs_->ref();
111 }
112 
115 {
116  vs_->unref();
117 }
118 
119 
120 DcmInputStream*
122 create() const
123 {
124  return new vil_dicom_stream_input( vs_ );
125 }
126 
127 
128 // ===========================================================================
129 // stream input
130 
133  : DcmInputStream( new vil_dicom_stream_producer( vs ) )
134 {
135 }
136 
137 
140 {
141  delete currentProducer();
142 }
143 
144 
145 DcmInputStreamFactory*
147 newFactory() const
148 {
149  return 0;
150 }
151 
152 #endif // HAS_DCMTK
virtual ~vil_dicom_stream_input()
Stream interface for VIL image loaders.
virtual OFCondition status() const
virtual vil_streampos tell() const =0
Return file pointer.
offile_off_t avail() override
OFBool eos() override
vil_dicom_stream_producer(vil_stream *vs)
offile_off_t read(void *buf, offile_off_t buflen) override
virtual DcmInputStreamFactory * newFactory() const
virtual ~vil_dicom_stream_producer()
virtual void seek(vil_streampos position)=0
Goto file pointer.
virtual vil_streampos read(void *buf, vil_streampos n)=0
Read n bytes into buf. Returns number of bytes read.
vil_dicom_stream_factory(vil_stream *vs)
virtual ~vil_dicom_stream_factory()
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
vil_dicom_stream_input(vil_stream *vs)
virtual DcmInputStream * create() const
void unref()
Definition: vil_stream.cxx:31
virtual bool ok() const =0
Return false if the stream is broken.
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
virtual vil_streampos file_size() const =0
Amount of data in the stream.
offile_off_t skip(offile_off_t skiplen) override
void putback(offile_off_t num) override
virtual OFBool good() const