Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / bin / ttdbserverd / tt_isam_file.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: tt_isam_file.h /main/3 1995/10/20 16:43:47 rswiston $                                                        */
28 /*
29  * tt_isam_file.h - Defines the TT ISAM file class.  This class simplifies
30  *                  opening, closing, reading and writing an ISAM file.
31  *
32  * Copyright (c) 1992 by Sun Microsystems, Inc.
33  */
34
35 #ifndef  _TT_ISAM_FILE_H
36 #define  _TT_ISAM_FILE_H
37
38 #include "util/tt_object.h"
39 #include "tt_isam.h"
40 #include "tt_isam_key_descriptor_utils.h"
41 #include "tt_isam_record_utils.h"
42
43 typedef int (*FatalErrorHandlerFunction) (char *);
44
45 class _Tt_isam_file : public _Tt_object {
46 public:
47   // Dummy constructor needed to make _tt_isam_file_utils.cc happy
48   _Tt_isam_file () {}
49
50   // Real constructors
51   _Tt_isam_file (const _Tt_string &file, int mode);
52   _Tt_isam_file (const _Tt_string            &file,
53                  int                          max_record_length,
54                  int                          min_record_length,
55                  _Tt_isam_key_descriptor_ptr  primary_key_descriptor,
56                  int                          mode);
57   ~_Tt_isam_file ();
58
59   void setErase (bool_t);
60   int  sync ();
61
62 //
63 // islock and isunlock are not supported by mini-isam
64 //
65 //  int  lock ();
66 //  int  unlock ();
67
68   int  rename (const _Tt_string&);
69
70   int addIndex (_Tt_isam_key_descriptor_ptr);
71   _Tt_isam_record_ptr getEmptyRecord ();
72
73   int findStartRecord (const _Tt_isam_key_descriptor_ptr &key_descriptor,
74                        int                                length,
75                        const _Tt_isam_record_ptr         &record,
76                        int                                mode);
77
78   _Tt_isam_record_ptr readRecord (int mode);
79   int                 readRecord (int mode, const _Tt_isam_record_ptr&);
80   int                 updateCurrentRecord (const _Tt_isam_record_ptr&);
81   int                 updateRecord (long recnum, const _Tt_isam_record_ptr&);
82   int                 writeRecord (const _Tt_isam_record_ptr&);
83   int                 deleteCurrentRecord ();
84   int                 deleteRecord (long recnum);
85
86   int        writeMagicString (const _Tt_string&);
87   _Tt_string readMagicString ();
88
89   int setFatalErrorHandler (FatalErrorHandlerFunction);
90
91   long getLastRecordNumber () const
92     {
93       return currentRecordNumber;
94     }
95
96   int getFileDescriptor () const
97     {
98       return fileDescriptor;
99     }
100
101   const _Tt_string &getName () const
102     {
103       return fileName;
104     }
105
106   int getErrorStatus () const
107     {
108       return errorStatus;
109     }
110
111   bool_t isNew () const
112     {
113       return newFlag;
114     }
115
116 private:
117   int                              currentRecordLength;
118   long                             currentRecordNumber;
119   bool_t                           eraseFlag;
120   int                              errorStatus;
121   int                              fileDescriptor;
122   _Tt_string                       fileName;
123   int                              fileMode;
124   _Tt_isam_key_descriptor_list_ptr keyDescriptorList;
125   int                              maxRecordLength;
126   int                              minRecordLength;
127   bool_t                           newFlag;
128
129   void                setTtISAMFileDefaults ();
130   _Tt_isam_record_ptr getFullRecord (const _Tt_string&);
131   void                getISAMFileInfo ();
132
133   void                getStatusInfo ()
134     {
135       currentRecordLength = isreclen;
136       currentRecordNumber = isrecnum;
137       errorStatus = iserrno;
138     }
139
140   static bool_t       isamFatalErrorHandlerSet;
141   static int          isamFatalErrorHandler (char *message);
142 };
143
144 #endif  /* _TT_ISAM_FILE_H */