Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / index / inv_lists.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 /*
24  * $XConsortium: inv_lists.cc /main/5 1996/07/18 14:37:46 drk $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #include "index/inv_lists.h"
52 #include "utility/funcs.h"
53
54
55 inv_lists::inv_lists(c_code_t c_cd) : oid_list(c_cd)
56 {
57    //set_mode(HEALTH, true);
58 }
59
60 inv_lists::~inv_lists() 
61
62 }
63
64 Boolean inv_lists::insert_list_pinned(int index, oid_list& lst)
65 {
66    if ( lst.count() == 0 ) {
67       throw(boundaryException(0, lst.count(), index));
68    } 
69
70    oid_list_handler list_hd(lst.count(), storage_ptr);
71
72    for ( int i=1; i<=lst.count(); i++ )
73       list_hd -> update_component(i, lst(i)) ;
74
75    oid_list::update_component(index, list_hd.its_oid()) ;
76
77    set_mode(UPDATE, true);
78    return true;
79 }
80
81 Boolean inv_lists::append_list(oid_list& lst)
82 {
83 /*
84 MESSAGE(cerr, "append a inv list");
85 lst.asciiOut(cerr); cerr << "\n";
86 */
87
88    handler hd(OID_LIST_CODE, storage_ptr);
89
90    oid_list_handler& lst_handler = *(oid_list_handler*)&hd;
91
92
93    lst_handler -> expand_space(lst.count());
94
95    for ( int i=1; i<=lst.count(); i++ )
96       lst_handler -> update_component(i, lst(i)) ;
97
98    oid_list::insert_component(hd.its_oid()) ;
99
100    set_mode(UPDATE, true);
101
102    return true;
103 }
104
105 Boolean inv_lists::remove_list(int index)
106 {
107    update_component(index, ground);
108    return true;
109 }
110
111 oid_list_handler* inv_lists::get_list(int index) 
112 {
113    oid_t x((*this)(index));
114
115    if ( x.eq(ground) == true ) {
116       return 0;
117    } else {
118       return new oid_list_handler(x, storage_ptr);
119    }
120 }
121
122 /*
123 oid_list_handler* inv_lists::get_list(mmdb_pos_t) 
124 {
125    throw( stringException("get_list(): not implemented yet"));
126    return 0;
127 }
128 */
129
130 ostream& operator <<(ostream&s, inv_lists& o) 
131 {
132    for (int i=0; i < o.count(); i++) {
133       oid_list_handler* x = o.get_list(i);
134       (*x) -> asciiOut(s);
135       delete x;
136       s << "\n";
137    }
138    return s;
139 }
140
141 void inv_lists::insert_to_list(int index, oid_t& id)
142 {
143    if ( !INRANGE(index, 1, v_sz) ) {
144       throw(boundaryException(1, v_sz, index));
145    }
146
147    oid_t list_id = (*this)(index);
148
149 /*
150 MESSAGE(cerr, "inv::insert");
151 debug(cerr, index);
152 */
153
154    if ( INRANGE(list_id.ccode(), 0, 1) && 
155         id.ccode() != OID_LIST_CODE 
156    ) {
157
158        update_component(index, id);
159
160    } else {
161        if ( list_id.ccode() != OID_LIST_CODE ) {
162           oid_list_handler y(OID_LIST_CODE, storage_ptr);
163           y -> insert_component(list_id);
164           update_component(index, y.its_oid());
165           y -> insert_component(id);
166        } else {
167           oid_list_handler y( list_id, storage_ptr);
168           y -> insert_component(id);
169        }
170    }
171
172 }
173
174 MMDB_BODIES(inv_lists)
175 HANDLER_BODIES(inv_lists)