libStatGen Software  1
BgzfFileTypeRecovery.h
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __BGZFFILETYPERECOVERY_H__
19 #define __BGZFFILETYPERECOVERY_H__
20 
21 #ifdef __ZLIB_AVAILABLE__
22 
23 #include "FileType.h"
24 #include <stdio.h> // for NULL
25 
26 class BGZFReader;
27 
28 class BgzfFileTypeRecovery : public FileType
29 {
30 public:
31  BgzfFileTypeRecovery()
32  {
33  bgzfReader = NULL;
34  }
35 
36  ~BgzfFileTypeRecovery()
37  {
38  close();
39  }
40 
41  BgzfFileTypeRecovery(const char * filename, const char * mode);
42 
43  // these methods should not be used. They are
44  // misleading because the rhs could be anything,
45  // (specifically not a BgzfFileTypeRecover object).
46  bool operator == (void * rhs);
47 
48  bool operator != (void * rhs);
49 
50  // Close the file.
51  int close();
52 
53  // Reset to the beginning of the file.
54  inline void rewind()
55  {
56  // Just call rewind to move to the beginning of the file.
57  seek(0LL, SEEK_SET);
58  }
59 
60  // Check to see if we have reached the EOF.
61  int eof();
62 
63  // Check to see if the file is open.
64  bool isOpen()
65  {
66  return (bgzfReader != NULL);
67  }
68 
69  // Write to the file
70  unsigned int write(const void * buffer, unsigned int size);
71 
72  // Read into a buffer from the file. Since the buffer is passed in and
73  // this would bypass the fileBuffer used by this class, this method must
74  // be protected.
75  int read(void * buffer, unsigned int size);
76 
77  // Get current position in the file.
78  // -1 return value indicates an error.
79  int64_t tell();
80 
81  // Seek to the specified offset from the origin.
82  // origin can be any of the following:
83  // Note: not all are valid for all filetypes.
84  // SEEK_SET - Beginning of file
85  // SEEK_CUR - Current position of the file pointer
86  // SEEK_END - End of file
87  // Returns true on successful seek and false on a failed seek.
88  bool seek(int64_t offset, int origin);
89 
90  bool attemptRecoverySync(bool (*checkSignature)(void *data) , int length);
91 
92 protected:
93  // Read via BGZFReader
94  BGZFReader* bgzfReader;
95 
96 };
97 
98 #endif
99 #endif
FileType
Definition: FileType.h:23