Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / bin / ttdbserverd / tt_isam_key_descriptor.C
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_key_descriptor.C /main/3 1995/10/20 16:44:18 rswiston $                                                     
28 /*
29  * tt_isam_key_descriptor.cc - Defines the TT ISAM key descriptor class.
30  *                  This class is used to hold the information required
31  *                  to create a NetISAM key descriptor.  It also makes
32  *                  it very easy to construct the descriptor.
33  *
34  * Copyright (c) 1992 by Sun Microsystems, Inc.
35  */
36
37 #include "tt_isam_key_descriptor.h"
38
39 _Tt_isam_key_descriptor::_Tt_isam_key_descriptor ()
40 {
41   keyDescriptor.k_flags = 0;
42   keyDescriptor.k_nparts = 0;
43 }
44
45 _Tt_isam_key_descriptor::~_Tt_isam_key_descriptor ()
46 {
47 }
48
49 short _Tt_isam_key_descriptor::addKeyPart (short start, short length, short type)
50 {
51   int index = -1;
52
53   if (keyDescriptor.k_nparts < NPARTS-1) {
54     index = keyDescriptor.k_nparts;
55
56     keyDescriptor.k_part [index].kp_start = start;
57     keyDescriptor.k_part [index].kp_leng = length;
58     keyDescriptor.k_part [index].kp_type = type;
59
60     keyDescriptor.k_nparts++;
61   }
62
63   return index;
64 }
65
66 short _Tt_isam_key_descriptor::setKeyPart (short index,
67                                            short start,
68                                            short length,
69                                            short type)
70 {
71   short error = 0;
72
73   if ((index > -1) && (index < keyDescriptor.k_nparts)) {
74     keyDescriptor.k_part [index].kp_start = start;
75     keyDescriptor.k_part [index].kp_leng = length;
76     keyDescriptor.k_part [index].kp_type = type;
77   }
78   else {
79     error = -1;
80   }
81
82   return error;
83 }
84
85 short _Tt_isam_key_descriptor::getKeyPart (short  index,
86                                            short &start,
87                                            short &length,
88                                            short &type) const
89 {
90   short error = 0;
91
92   if ((index > -1) && (index < keyDescriptor.k_nparts)) {
93     
94
95     start = keyDescriptor.k_part [index].kp_start;
96     length = keyDescriptor.k_part [index].kp_leng;
97     type = keyDescriptor.k_part [index].kp_type;
98   }
99   else {
100     start = -1;
101     length = -1;
102     type = -1;
103     error = -1;
104   }
105
106   return error;
107 }