vtk-dicom  0.8.17
vtkDICOMFile.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkDICOMFile_h
15 #define vtkDICOMFile_h
16 
17 #include "vtkSystemIncludes.h"
18 #include "vtkDICOMModule.h" // For export macro
19 #include "vtkDICOMConfig.h" // For configuration details
20 
21 #if defined(_WIN32)
22 #define VTK_DICOM_WIN32_IO
23 #else
24 #define VTK_DICOM_POSIX_IO
25 #endif
26 
28 
33 class VTKDICOM_EXPORT vtkDICOMFile
34 {
35 public:
37  enum Mode
38  {
39  In,
40  Out
41  };
42 
44  enum Code
45  {
46  Good, // no error
47  UnknownError, // unspecified error
48  AccessDenied, // file permission error
49  FileIsDirectory, // can't open file: directory with that name exists
50  ImpossiblePath, // part of the path doesn't exist or goes through a file
51  FileNotFound, // requested file (or directory) doesn't exist
52  OutOfSpace // disk full or quota exceeded
53  };
54 
56  typedef unsigned long long Size;
57 
59 
63  vtkDICOMFile(const char *filename, Mode mode);
64 
68 
70  void Close();
72 
74 
78  size_t Read(unsigned char *data, size_t size);
79 
81 
85  size_t Write(const unsigned char *data, size_t size);
86 
88 
91  bool SetPosition(Size offset);
92 
95 
97  bool EndOfFile() { return this->Eof; }
98 
100  int GetError() { return this->Error; }
102 
104 
110  static int Access(const char *filename, Mode mode);
111 
113 
118  static int Remove(const char *filename);
119 
121 
127  static bool SameFile(const char *file1, const char *file2);
129 
131  // Copy constructor creates a closed file. The copy constructor would
132  // normally be deleted, but that would cause the VTK python wrappers to
133  // skip this class. Once the wrappers are fixed, this can be deleted.
134  vtkDICOMFile(const vtkDICOMFile&) : Handle(0), Error(0), Eof(false) {}
136 
137 private:
138  vtkDICOMFile& operator=(const vtkDICOMFile&); // = delete;
139 
140 #ifdef VTK_DICOM_POSIX_IO
141  int Handle;
142 #else
143  void *Handle;
144 #endif
145  int Error;
146  bool Eof;
147 };
148 
149 #endif /* vtkDICOMFile_h */
150 // VTK-HeaderTest-Exclude: vtkDICOMFile.h
A class that provides basic input/output operations.
Definition: vtkDICOMFile.h:34
static int Remove(const char *filename)
Delete the specified file (static method).
static bool SameFile(const char *file1, const char *file2)
Check if two files are the same.
Size GetSize()
Check the size of the file, returns ULLONG_MAX on error.
Code
Error codes.
Definition: vtkDICOMFile.h:45
int GetError()
Return an error indicator (zero if no error).
Definition: vtkDICOMFile.h:100
size_t Read(unsigned char *data, size_t size)
Read data from the file.
vtkDICOMFile(const char *filename, Mode mode)
Construct the file object.
static int Access(const char *filename, Mode mode)
Test the specified file for accessibility (static method).
unsigned long long Size
Typedef for a file size.
Definition: vtkDICOMFile.h:56
bool SetPosition(Size offset)
Go to a specific location in the file.
~vtkDICOMFile()
Destruct the object and close the file.
bool EndOfFile()
Check for the end-of-file indicator.
Definition: vtkDICOMFile.h:97
size_t Write(const unsigned char *data, size_t size)
Write data to a file.
Mode
The file mode (input or output).
Definition: vtkDICOMFile.h:38