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
23 /* $XConsortium: vm_storage.cc /main/4 1996/07/18 16:05:10 drk $ */
25 #include "storage/vm_storage.h"
26 #include "utility/mmdb_exception.h"
28 vm_storage::vm_storage( char* _path, char* _name, rep_policy* rep_p):
29 abs_storage( _path, _name, MEM_STORAGE_CODE, rep_p ), f_array(20)
33 vm_storage::~vm_storage()
38 void vm_storage::remove()
40 for ( int i=0; i<f_array.no_elmts(); i++ ) {
41 delete (buffer*)f_array[i];
42 f_array.insert(0, i) ;
44 f_array.reset_elmts(0);
47 int vm_storage::appendString(mmdb_pos_t loc, const char*, int len,
53 int vm_storage::readString(mmdb_pos_t loc, char* base, int len, int str_offset)
55 //MESSAGE(cerr, "vm: read");
58 //debug(cerr, str_offset);
62 int ok = get_str_ptr(loc, x, y);
64 if ( ok == 0 && str_offset+len <= y ) {
65 memcpy(base, x+str_offset, len);
66 //MESSAGE(cerr, "========");
72 int vm_storage::insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush)
74 //MESSAGE(cerr, "vm: insert");
79 int ok = allocString (loc, len, x, 0);
81 //MESSAGE(cerr, "========");
84 return updateString(loc, base, len, 0);
89 int vm_storage::get_str_ptr(mmdb_pos_t loc, char*& x, int& len)
91 //MESSAGE(cerr, "vm: get_str_ptr");
94 if ( loc >= f_array.no_elmts() ) {
96 debug(cerr, f_array.no_elmts());
100 buffer* b = (buffer*)f_array[(int)loc];
103 MESSAGE(cerr, "null pointer");
109 //debug(cerr, (void*)x);
111 //MESSAGE(cerr, "========");
116 int vm_storage::updateString(mmdb_pos_t loc, const char* base, int len,
117 int string_ofst, Boolean flush)
119 //MESSAGE(cerr, "updateString");
123 if ( loc >= f_array.no_elmts() ) {
125 debug(cerr, f_array.no_elmts());
129 buffer* b = (buffer*)f_array[(int)loc];
132 MESSAGE(cerr, "null pointer");
137 if ( b -> buf_sz() < len + string_ofst )
138 b -> expand_chunk(len + string_ofst);
141 for (int i=0; i<len; i++)
142 if ( isascii(base[i]) )
145 cerr << int(base[i]);
147 MESSAGE(cerr, "========");
150 char* x = b -> get_base();
151 memcpy(x+string_ofst, base, len);
155 int vm_storage::deleteString (mmdb_pos_t loc, Boolean flush)
160 int vm_storage::allocString (mmdb_pos_t& loc, int len, char*& x, int mode)
162 //MESSAGE(cerr, "vm: allocate");
165 int c = f_array.no_elmts();
167 if ( c >= f_array.count() ) {
168 f_array.expandWith(10);
171 buffer* b = new buffer(len==0 ? 1 : len);
172 f_array.insert(b, c) ;
174 f_array.reset_elmts(c+1);
178 //debug(cerr, (void*)x);
180 //MESSAGE(cerr, "========");
185 Boolean vm_storage::io_mode(int mode)