Cofstream.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_Cofstream_H
21 #define MIRTK_Cofstream_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 writing (compressed) file streams.
34  *
35  * This class defines and implements functions for writing compressed file
36  * streams. At the moment only the writing of uncompressed file streams is
37  * supported.
38  */
39 
40 class Cofstream : public Object
41 {
42  mirtkObjectMacro(Cofstream);
43 
44  /// File pointer to uncompressed file
45  FILE *_File;
46 
47  /// File pointer to compressed file
48 #if MIRTK_Common_WITH_ZLIB
49  void *_ZFile;
50 #endif
51 
52  /// Flag whether file is compressed
53  mirtkPublicAttributeMacro(bool, Compressed);
54 
55  /// Flag whether file is swapped
56  mirtkPublicAttributeMacro(bool, Swapped);
57 
58 public:
59 
60  /// Constructor
61  Cofstream(const char * = NULL);
62 
63  /// Destructor
64  ~Cofstream();
65 
66  /// Write n data as array from offset
67  bool Write(const char *, long, long);
68 
69  /// Write data as char (possibly compressed) from offset
70  bool WriteAsChar(char, long = -1);
71  /// Write data as char (possibly compressed) from offset
72  bool WriteAsChar(const char *, long, long = -1);
73 
74  /// Write data as unsigned char (possibly compressed) from offset
75  bool WriteAsUChar(unsigned char, long = -1);
76  /// Write data as unsigned char (possibly compressed) from offset
77  bool WriteAsUChar(const unsigned char *, long, long = -1);
78 
79  /// Write data as short (possibly compressed) from offset
80  bool WriteAsShort(short, long = -1);
81  /// Write data as short (possibly compressed) from offset
82  bool WriteAsShort(const short *, long, long = -1);
83 
84  /// Write data as unsigned short (possibly compressed) from offset
85  bool WriteAsUShort(unsigned short, long = -1);
86  /// Write data as unsigned short (possibly compressed) from offset
87  bool WriteAsUShort(const unsigned short *, long, long = -1);
88 
89  /// Write data as int (possibly compressed) from offset
90  bool WriteAsInt(int, long = -1);
91  /// Write data as int (possibly compressed) from offset
92  bool WriteAsInt(const int *, long, long = -1);
93 
94  /// Write data as unsigned int (possibly compressed) from offset
95  bool WriteAsUInt(unsigned int, long = -1);
96  /// Write data as unsigned int (possibly compressed) from offset
97  bool WriteAsUInt(const unsigned int *, long, long = -1);
98 
99  /// Write data as float (possibly compressed) from offset
100  bool WriteAsFloat(float, long = -1);
101  /// Write data as float (possibly compressed) from offset
102  bool WriteAsFloat(const float *, long, long = -1);
103 
104  /// Write data as double (possibly compressed) from offset
105  bool WriteAsDouble(double, long = -1);
106  /// Write data as double (possibly compressed) from offset
107  bool WriteAsDouble(const double *, long, long = -1);
108 
109  /// Write data as string (possibly compressed)
110  bool WriteAsString(const char *, long = -1);
111 
112  /// Open file
113  void Open(const char *);
114 
115  /// Close file
116  void Close();
117 
118  /// Returns whether file is compressed
119  /// \deprecated Used Compressed() instead.
120  MIRTK_Common_DEPRECATED int IsCompressed() const;
121 
122  /// Sets whether file is compressed
123  /// \deprecated Used Compressed(bool) instead.
124  MIRTK_Common_DEPRECATED void IsCompressed(int);
125 
126  /// Returns whether file is swapped
127  /// \deprecated Used Swapped() instead.
128  MIRTK_Common_DEPRECATED int IsSwapped() const;
129 
130  /// Sets whether file is swapped
131  /// \deprecated Used Swapped(bool) instead.
132  MIRTK_Common_DEPRECATED void IsSwapped(int);
133 
134 };
135 
136 
137 } // namespace mirtk
138 
139 #endif // MIRTK_Cofstream_H
bool WriteAsFloat(float, long=-1)
Write data as float (possibly compressed) from offset.
bool WriteAsUInt(unsigned int, long=-1)
Write data as unsigned int (possibly compressed) from offset.
bool WriteAsString(const char *, long=-1)
Write data as string (possibly compressed)
~Cofstream()
Destructor.
Definition: IOConfig.h:41
bool WriteAsUShort(unsigned short, long=-1)
Write data as unsigned short (possibly compressed) from offset.
void Close()
Close file.
Cofstream(const char *=NULL)
Constructor.
MIRTK_Common_DEPRECATED int IsCompressed() const
bool WriteAsUChar(unsigned char, long=-1)
Write data as unsigned char (possibly compressed) from offset.
bool WriteAsChar(char, long=-1)
Write data as char (possibly compressed) from offset.
void Open(const char *)
Open file.
bool Write(const char *, long, long)
Write n data as array from offset.
bool WriteAsShort(short, long=-1)
Write data as short (possibly compressed) from offset.
MIRTK_Common_DEPRECATED int IsSwapped() const
bool WriteAsInt(int, long=-1)
Write data as int (possibly compressed) from offset.
bool WriteAsDouble(double, long=-1)
Write data as double (possibly compressed) from offset.