2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * $XConsortium: mmdb_btree.cc /main/3 1996/06/11 17:14:32 cde-hal $
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
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
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.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "btree/mmdb_btree.h"
54 btree::btree(const char* store_name)
56 // let the package figure out all these parameters
58 btree_info.cachesize = 0;
59 btree_info.maxkeypage = 0;
60 btree_info.minkeypage = 0;
62 btree_info.compare = NULL;
63 btree_info.prefix = NULL;
64 btree_info.lorder = 0;
67 int mode = O_CREAT|O_RDWR;
69 //btree_DB = dbopen(store_name, mode, 0640, DB_BTREE, &btree_info);
70 btree_DB = dbopen(store_name, mode, 0640, DB_BTREE, NULL);
73 throw(stringException("btree dbopen failed"));
78 if ( btree_DB->sync(btree_DB, 0) == RET_ERROR )
79 throw(stringException("btree sync failed"));
81 if ( btree_DB->close(btree_DB) == RET_ERROR )
82 throw(stringException("btree close failed"));
87 throw(stringException("void btree::clean(): not implemented yet"));
90 void btree::data_t_2_DBT(data_t& w)
94 key_DBT.data = &w.key.int_key;
95 key_DBT.size = sizeof(w.key.int_key);
99 key_DBT.data = w.key.str_key;
100 key_DBT.size = strlen(w.key.str_key);
104 throw(stringException("btree data_t_2_DBT: unknow key type"));
108 Boolean btree::insert(data_t& w)
113 data_DBT.data = &w.dt;
114 data_DBT.size = sizeof(w.dt);
116 //int status = btree_DB->put(btree_DB, &key_DBT, &data_DBT, R_NOOVERWRITE);
117 int status = btree_DB->put(btree_DB, &key_DBT, &data_DBT, 0);
121 throw(stringException("btree put failed"));
125 throw(stringException("btree put: dup key"));
135 Boolean btree::remove(data_t& w)
139 int status = btree_DB->del(btree_DB, &key_DBT, 0);
143 throw(stringException("btree delete failed"));
154 Boolean btree::member(data_t& w)
159 int status = btree_DB->get(btree_DB, &key_DBT, &data_DBT, 0);
163 throw(stringException("btree get failed"));
170 if ( data_DBT.size != sizeof(w.dt) )
171 throw(stringException("btree get: tree corrupted"));
173 memcpy((char*)&w.dt, data_DBT.data, data_DBT.size);
180 ostream& btree::asciiOut(ostream& out)
185 istream& btree::asciiIn(istream& in)