Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / db / tt_client_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_client_isam_file.h /main/3 1995/10/23 09:59:20 rswiston $                                                         */
28 /*
29  * tt_client_isam_file.h - Defines the TT ISAM file class.  This class
30  *      simplifies opening, closing, reading and writing an ISAM file.
31  *
32  * Copyright (c) 1992 by Sun Microsystems, Inc.
33  */
34
35 #ifndef  _TT_CLIENT_ISAM_FILE_H
36 #define  _TT_CLIENT_ISAM_FILE_H
37
38 #include "util/tt_object.h"
39 #include "db/tt_db_client_utils.h"
40 #include "db/tt_client_isam_key_descriptor_utils.h"
41 #include "db/tt_client_isam_record_utils.h"
42 #include <sys/param.h>
43
44 class _Tt_client_isam_file : public _Tt_object {
45 public:
46   // Dummy constructor needed to make _tt_client_isam_file_utils.cc happy
47   _Tt_client_isam_file () {}
48
49   // Real constructors
50   _Tt_client_isam_file (const _Tt_string        &file,
51                  int                      mode,
52                  const _Tt_db_client_ptr &db_connection);
53   _Tt_client_isam_file (const _Tt_string            &file,
54                  int                          max_record_length,
55                  int                          min_record_length,
56                  _Tt_client_isam_key_descriptor_ptr  primary_key_descriptor,
57                  int                          mode,
58                  const _Tt_db_client_ptr     &db_connection);
59   ~_Tt_client_isam_file ();
60
61   void setErase (bool_t);
62
63   int addIndex (_Tt_client_isam_key_descriptor_ptr);
64   _Tt_client_isam_record_ptr getEmptyRecord ();
65
66   int findStartRecord (const _Tt_client_isam_key_descriptor_ptr &key_descriptor,
67                        int                                length,
68                        const _Tt_client_isam_record_ptr         &record,
69                        int                                mode);
70
71   _Tt_client_isam_record_ptr readRecord (int mode);
72   int                 readRecord (int mode, const _Tt_client_isam_record_ptr&);
73   int                 updateRecord (long recnum, const _Tt_client_isam_record_ptr&);
74   int                 writeRecord (const _Tt_client_isam_record_ptr&);
75   int                 deleteRecord (long                              recnum,
76                                     const _Tt_client_isam_record_ptr &record);
77
78   int        writeMagicString (const _Tt_string&);
79   _Tt_string readMagicString ();
80
81   long getLastRecordNumber () const
82     {
83       return currentRecordNumber;
84     }
85
86   int getFileDescriptor () const
87     {
88       return fileDescriptor;
89     }
90
91   const _Tt_string &getName () const
92     {
93       return fileName;
94     }
95
96   int getErrorStatus () const
97     {
98       return errorStatus;
99     }
100
101   bool_t isNew () const
102     {
103       return newFlag;
104     }
105
106 private:
107   int                              currentRecordLength;
108   long                             currentRecordNumber;
109   _Tt_db_client_ptr                dbConnection;
110   bool_t                           eraseFlag;
111   int                              errorStatus;
112   int                              fileDescriptor;
113   _Tt_string                       fileName;
114   int                              fileMode;
115   _Tt_client_isam_key_descriptor_list_ptr keyDescriptorList;
116   int                              maxRecordLength;
117   int                              minRecordLength;
118   bool_t                           newFlag;
119
120   void                setTtISAMFileDefaults ();
121   _Tt_client_isam_record_ptr getFullRecord (const _Tt_string&);
122   void                getISAMFileInfo ();
123
124   void                getStatusInfo ()
125     {
126       currentRecordLength = dbConnection->isreclen;
127       currentRecordNumber = dbConnection->isrecnum;
128       errorStatus = dbConnection->iserrno;
129     }
130 };
131
132 #endif  /* _TT_CLIENT_ISAM_FILE_H */