/src/dcmtk/dcmdata/libsrc/dcistrma.cc
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1994-2010, 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: Marco Eichelberg |
17 | | * |
18 | | * Purpose: base classes for input streams |
19 | | * |
20 | | */ |
21 | | |
22 | | #include "dcmtk/config/osconfig.h" |
23 | | #include "dcmtk/dcmdata/dcistrma.h" |
24 | | #include "dcmtk/dcmdata/dcistrmz.h" /* for DcmZLibInputFilter */ |
25 | | #include "dcmtk/dcmdata/dcerror.h" /* for EC_IllegalCall */ |
26 | | |
27 | | DcmInputStream::DcmInputStream(DcmProducer *initial) |
28 | 16 | : current_(initial) |
29 | 16 | , compressionFilter_(NULL) |
30 | 16 | , tell_(0) |
31 | 16 | , mark_(0) |
32 | 16 | { |
33 | 16 | } |
34 | | |
35 | | DcmInputStream::~DcmInputStream() |
36 | 16 | { |
37 | | // we cannot access the stream anymore at this point because the |
38 | | // producer has most probably already been deleted. |
39 | 16 | delete compressionFilter_; |
40 | 16 | } |
41 | | |
42 | | OFBool DcmInputStream::good() const |
43 | 0 | { |
44 | 0 | return current_->good(); |
45 | 0 | } |
46 | | |
47 | | OFCondition DcmInputStream::status() const |
48 | 16 | { |
49 | 16 | return current_->status(); |
50 | 16 | } |
51 | | |
52 | | OFBool DcmInputStream::eos() |
53 | 16 | { |
54 | 16 | return current_->eos(); |
55 | 16 | } |
56 | | |
57 | | offile_off_t DcmInputStream::avail() |
58 | 0 | { |
59 | 0 | return current_->avail(); |
60 | 0 | } |
61 | | |
62 | | offile_off_t DcmInputStream::read(void *buf, offile_off_t buflen) |
63 | 0 | { |
64 | 0 | offile_off_t result = current_->read(buf, buflen); |
65 | 0 | tell_ += result; |
66 | 0 | return result; |
67 | 0 | } |
68 | | |
69 | | offile_off_t DcmInputStream::skip(offile_off_t skiplen) |
70 | 16 | { |
71 | 16 | offile_off_t result = current_->skip(skiplen); |
72 | 16 | tell_ += result; |
73 | 16 | return result; |
74 | 16 | } |
75 | | |
76 | | offile_off_t DcmInputStream::tell() const |
77 | 0 | { |
78 | 0 | return tell_; |
79 | 0 | } |
80 | | |
81 | | void DcmInputStream::mark() |
82 | 0 | { |
83 | 0 | mark_ = tell_; |
84 | 0 | } |
85 | | |
86 | | void DcmInputStream::putback() |
87 | 0 | { |
88 | 0 | current_->putback(tell_ - mark_); |
89 | 0 | tell_ = mark_; |
90 | 0 | } |
91 | | |
92 | | const DcmProducer *DcmInputStream::currentProducer() const |
93 | 0 | { |
94 | 0 | return current_; |
95 | 0 | } |
96 | | |
97 | | OFCondition DcmInputStream::installCompressionFilter(E_StreamCompression filterType) |
98 | 0 | { |
99 | 0 | OFCondition result = EC_Normal; |
100 | 0 | if (compressionFilter_) result = EC_DoubleCompressionFilters; |
101 | 0 | else |
102 | 0 | { |
103 | 0 | switch (filterType) |
104 | 0 | { |
105 | 0 | #ifdef WITH_ZLIB |
106 | 0 | case ESC_zlib: |
107 | 0 | compressionFilter_ = new DcmZLibInputFilter(); |
108 | 0 | if (compressionFilter_) |
109 | 0 | { |
110 | 0 | compressionFilter_->append(*current_); |
111 | | // feed the compression engine with data from the producer |
112 | 0 | compressionFilter_->skip(0); |
113 | 0 | current_ = compressionFilter_; |
114 | 0 | } else result = EC_MemoryExhausted; |
115 | 0 | break; |
116 | 0 | #endif |
117 | 0 | case ESC_none: |
118 | 0 | case ESC_unsupported: |
119 | 0 | result = EC_UnsupportedEncoding; |
120 | 0 | break; |
121 | 0 | } |
122 | 0 | } |
123 | | |
124 | 0 | return result; |
125 | 0 | } |