Cifstream.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  * Copyright 2008-2015 Daniel Rueckert, Julia Schnabel
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_Cifstream_H
21 #define MIRTK_Cifstream_H
22 
23 #include "mirtk/CommonConfig.h"
24 #include "mirtk/CommonExport.h"
25 
26 #include "mirtk/Object.h"
27 
28 
29 namespace mirtk {
30 
31 
32 /**
33  * Class for reading (compressed) file streams.
34  *
35  * This class defines and implements functions for reading compressed file
36  * streams. The file streams can be either uncompressed or compressed.
37  */
38 
39 class Cifstream : public Object
40 {
41  mirtkObjectMacro(Cifstream);
42 
43  /// File pointer to potentially compressed file
44  void *_File;
45 
46  /// Flag indicating whether file bytes are swapped
47  mirtkPublicAttributeMacro(bool, Swapped);
48 
49 public:
50 
51  /// Constructor
52  Cifstream(const char * = NULL);
53 
54  /// Destructor
55  ~Cifstream();
56 
57  /// Read n data as array (possibly compressed) from offset
58  bool Read(char *, long, long);
59 
60  /// Read n data as array of char (possibly compressed) from offset
61  bool ReadAsChar(char *, long, long = -1);
62 
63  /// Read n data as array of unsigned char (possibly compressed) from offset
64  bool ReadAsUChar(unsigned char *, long, long = -1);
65 
66  /// Read n data as array of short (possibly compressed) from offset
67  bool ReadAsShort(short *, long, long = -1);
68 
69  /// Read n data as array of unsigned short (possibly compressed) from offset
70  bool ReadAsUShort(unsigned short *, long, long = -1);
71 
72  /// Read n data as array of short (possibly compressed) from offset
73  bool ReadAsInt(int *, long, long = -1);
74 
75  /// Read n data as array of unsigned short (possibly compressed) from offset
76  bool ReadAsUInt(unsigned int *, long, long = -1);
77 
78  /// Read n data as array of short compressed) from offset
79  bool ReadAsFloat(float *, long, long offset = -1);
80 
81  /// Read n data as array of unsigned short (possibly compressed) from offset
82  bool ReadAsDouble(double *, long, long = -1);
83 
84  /// Read n data as string (possibly compressed) from current position
85  bool ReadAsString(char *, long, long = -1);
86 
87  /// Open file
88  void Open(const char *);
89 
90  /// Close file
91  void Close();
92 
93  /// Go to position in file
94  void Seek(long);
95 
96  /// Current position in file
97  long Tell() const;
98 
99  /// Returns whether file is swapped
100  /// \deprecated Use Swapped() instead.
101  MIRTK_Common_DEPRECATED int IsSwapped() const;
102 
103  /// Sets whether file is swapped
104  /// \deprecated Use Swapped(bool) instead.
105  MIRTK_Common_DEPRECATED void IsSwapped(int);
106 
107 };
108 
109 
110 } // namespace mirtk
111 
112 #endif // MIRTK_Cifstream_H
Cifstream(const char *=NULL)
Constructor.
void Close()
Close file.
void Seek(long)
Go to position in file.
bool ReadAsUShort(unsigned short *, long, long=-1)
Read n data as array of unsigned short (possibly compressed) from offset.
bool ReadAsUInt(unsigned int *, long, long=-1)
Read n data as array of unsigned short (possibly compressed) from offset.
bool ReadAsShort(short *, long, long=-1)
Read n data as array of short (possibly compressed) from offset.
bool ReadAsInt(int *, long, long=-1)
Read n data as array of short (possibly compressed) from offset.
bool ReadAsString(char *, long, long=-1)
Read n data as string (possibly compressed) from current position.
Definition: IOConfig.h:41
~Cifstream()
Destructor.
bool Read(char *, long, long)
Read n data as array (possibly compressed) from offset.
bool ReadAsFloat(float *, long, long offset=-1)
Read n data as array of short compressed) from offset.
bool ReadAsDouble(double *, long, long=-1)
Read n data as array of unsigned short (possibly compressed) from offset.
MIRTK_Common_DEPRECATED int IsSwapped() const
bool ReadAsChar(char *, long, long=-1)
Read n data as array of char (possibly compressed) from offset.
bool ReadAsUChar(unsigned char *, long, long=-1)
Read n data as array of unsigned char (possibly compressed) from offset.
void Open(const char *)
Open file.
long Tell() const
Current position in file.