Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
xbfile.h
Go to the documentation of this file.
1/* xbfile.h
2
3XBase64 Software Library
4
5Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
6
7The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
8
9Email Contact:
10
11 XDB-devel@lists.sourceforge.net
12 XDB-users@lists.sourceforge.net
13
14*/
15
16#ifndef __XB_FILE_H__
17#define __XB_FILE_H__
18
19#ifdef CMAKE_COMPILER_IS_GNUCC
20#pragma interface
21#endif
22
23/*****************************/
24/* File Open Modes */
25#define XB_READ 0
26#define XB_READ_WRITE 1
27#define XB_WRITE 2
28
29/*****************************/
30/* File Access Modes */
31#define XB_SINGLE_USER 0 // file buffering on
32#define XB_MULTI_USER 1 // file buffering off
33
34namespace xb{
35
56class XBDLLEXPORT xbFile : public xbSsv {
57
58 public:
59 // xbFile();
60 xbFile( xbXBase * x );
61
62 ~xbFile();
63
64 xbInt16 SetHomeFolders();
65
66 xbInt16 CreateUniqueFileName( const xbString &sDirIn, const xbString &sExtIn, xbString &sFqnOut );
67 xbInt16 CreateUniqueFileName( const xbString &sDirIn, const xbString &sExtIn, xbString &sFqnOut, xbInt16 iOption );
68
69 const xbString& GetDirectory() const;
70 const xbString& GetFileName() const;
71 const xbString& GetFqFileName() const;
72
73 void SetDirectory ( const xbString &sDirectory);
74 void SetFileName ( const xbString &sFileName );
75 void SetFqFileName( const xbString &sFqName );
76
77 xbUInt32 GetBlockSize () const;
78 xbInt16 SetBlockSize ( xbUInt32 ulBlockSize );
79
80 xbInt16 GetOpenMode () const;
81 xbInt16 GetShareMode () const;
82
83 xbInt16 GetFileDirPart ( xbString &sFileDirPartOut ) const;
84 xbInt16 GetFileDirPart ( const xbString &sCompleteFileNameIn, xbString &sFileDirPartOut ) const;
85 xbInt16 GetFileExtPart ( xbString &sFileExtPartOut ) const;
86 xbInt16 GetFileExtPart ( const xbString &sCompleteFileNameIn, xbString &sFileExtPartOut ) const;
87 xbInt16 GetFileNamePart( xbString &sFileNamePartOut ) const;
88 xbInt16 GetFileNamePart( const xbString &sCompleteFileNameIn, xbString &sFileNamePartOut ) const;
89 xbInt16 GetFileType ( xbString &sFileType ) const;
90
91 xbInt16 GetXbaseFileTypeByte( const xbString &sFileName, xbInt16 &iVersion );
92 xbInt16 GetXbaseFileTypeByte( const xbString &sFileName, unsigned char &cFileTypeByte );
93 xbInt16 GetXbaseFileTypeByte( const xbString &sFileName, unsigned char &cFileTypeByte, xbInt16 &iVersion );
94 xbInt16 DetermineXbaseTableVersion( unsigned char cFileTypeByte ) const;
95 xbInt16 DetermineXbaseMemoVersion( unsigned char cFileTypeByte ) const;
96
97 xbBool FileExists () const;
98 xbBool FileExists ( xbInt16 iOption ) const;
99 xbBool FileExists ( const xbString &sFileName ) const;
100 xbBool FileExists ( const xbString &sFileName, xbInt16 iOption ) const;
101
102 xbBool FileIsOpen () const;
103
104 xbInt16 ReadBlock ( xbUInt32 ulBlockNo, size_t readSize, void *buf );
105 xbInt16 ReadBlock ( xbUInt32 ulBlockNo, xbUInt32 ulBlockSize, size_t readSize, void *buf );
106 xbInt16 WriteBlock( xbUInt32 ulBlockNo, size_t writeSize, void *buf );
107
108 xbInt16 GetFileSize( xbUInt64 &ullFileSize );
109 xbInt16 GetFileMtime( time_t &mtime );
110
111 xbDouble eGetDouble( const char *p ) const;
112 xbInt32 eGetInt32 ( const char *p ) const;
113 xbUInt32 eGetUInt32( const char *p ) const;
114 xbInt16 eGetInt16 ( const char *p ) const;
115 xbUInt16 eGetUInt16( const char *p ) const;
116 void ePutDouble( char *p, xbDouble d );
117 void ePutInt32 ( char *p, xbInt32 l );
118 void ePutUInt32( char *p, xbUInt32 ul );
119 void ePutInt16 ( char *p, xbInt16 s );
120 void ePutUInt16( char *p, xbUInt16 s );
121
122 xbInt16 xbFclose ();
123 xbInt16 xbFeof ();
124 xbInt16 xbFflush ();
125 xbInt16 xbFgetc ( xbInt32 &c );
126 xbInt16 xbFgetc ( char &c );
127
128 #ifdef XB_LOCKING_SUPPORT
129 xbInt16 xbLock ( xbInt16 iFunction, xbInt64 llOffset, size_t stLen );
130 xbInt16 GetLockRetryCount() const;
131 void SetLockRetryCount( xbInt16 iLockRetries );
132 #endif
133
134 xbInt16 xbFopen ( xbInt16 iOpenMode );
135 xbInt16 xbFopen ( const xbString &sOpenMode, xbInt16 iShareMode );
136 xbInt16 xbFopen ( xbInt16 iOpenMode, xbInt16 iShareMode );
137 xbInt16 xbFopen ( const xbString &sMode, const xbString &sFileName, xbInt16 iShareMode );
138
139 xbInt16 xbFputc ( xbInt32 c );
140 xbInt16 xbFputc ( xbInt32 c, xbInt32 iNoTimes );
141 xbInt16 xbFputs ( const xbString &s );
142 xbInt16 xbFread ( void *ptr, size_t size, size_t nmemb );
143 xbInt16 xbFgets ( size_t lSize, xbString &sLine );
144
145 size_t xbFtell ();
146 xbInt16 xbFseek ( xbInt64 llOffset, xbInt32 whence );
147
148 void xbFTurnOffFileBuffering();
149 xbInt16 xbFwrite ( const void *ptr, size_t lSize, size_t lNmemb );
150
151 xbInt16 xbReadUntil ( const char cDelim, xbString &sOut );
152 xbInt16 xbRemove ( const xbString &sFileName, xbInt16 iOption );
153 xbInt16 xbRemove ( const xbString &sFileName );
154 xbInt16 xbRemove ();
155
156 xbInt16 xbRename ( const xbString &sOldName, const xbString &sNewName );
157 void xbRewind ();
158
159 xbInt16 xbTruncate ( xbInt64 llSize );
160 xbInt16 NameSuffixMissing( const xbString &sFileName, xbInt16 iOption ) const;
161
162 #ifdef XB_DEBUG_SUPPORT
163 xbInt16 DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlockSize );
164 xbInt16 DumpMemToDisk ( char *p, size_t lBlockSize );
165 #endif
166
167
168 protected:
169
170 xbXBase *xbase; /* pointer to the main structures */
171
172 private:
173 FILE *fp;
174 xbString sFqFileName; /* fully qualified file name */
175 xbString sFileName; /* file name */
176 xbString sDirectory; /* directory, ends with / or \ */
177 xbBool bFileOpen; /* true if file is open */
178 xbUInt32 ulBlockSize; /* used for memo and index files */
179
180 xbInt16 iOpenMode; /* XB_READ || XB_READ_WRITE || XB_WRITE */
181 xbInt16 iShareMode; /* XB_SINGLE_USER || XB_MULTI_USER - set file buffering */
182 xbInt32 iFileNo; /* Library File No */
183
184 #ifdef XB_LOCKING_SUPPORT
185 xbInt16 iLockRetries; /* file override number of lock attempts */
186 #endif
187
188 #ifdef HAVE_SETENDOFFILE_F
189 HANDLE fHandle;
190 #endif
191
192
193};
194
195} /* namespace */
196#endif /* __XBFILE_H__ */
197
Class for handling low level file I/O.
Definition: xbfile.h:56
xbInt16 xbFopen(xbInt16 iOpenMode)
xbXBase * xbase
Definition: xbfile.h:170
Class for handling shared system variables.
Definition: xbssv.h:59
Class for handling string data.
Definition: xbstring.h:50
xbXbase class.
Definition: xbxbase.h:123
Definition: xbdate.cpp:19
double xbDouble
Definition: xbtypes.h:23
short int xbBool
Definition: xbtypes.h:24