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: pstring.C /main/6 1996/09/16 14:26:44 mgreess $
26 * Copyright (c) 1992 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 "object/pstring.h"
54 buffer* pstring::v_io_buf_ptr;
55 #define v_io_buf (*v_io_buf_ptr)
57 buffer pstring::v_io_buf(LBUFSIZ);
60 void pstring::init_persistent_info(persistent_info* x)
62 root::init_persistent_info(x);
63 if ( get_mode(OLD_OBJECT) == false ) {
66 storage_ptr -> insertString(v_str_ptr.loc, y, 0);
70 pstring::pstring(c_code_t c_id) : primitive(c_id),
75 // Make sure the entire union is initialized for 64bit architectures.
77 memset((char*) &v_str_ptr, 0, sizeof(v_str_ptr));
80 pstring::pstring(const char* x, int leng, c_code_t c_id) :
86 pstring::pstring(pstring& x) : primitive(x)
88 _init((const char*)x.get(), x.v_sz);
91 void pstring::_init(const char* x, int leng)
100 v_str_ptr.p = new char[leng+1];
101 memcpy(v_str_ptr.p, x, leng);
102 v_str_ptr.p[leng] = 0;
107 if ( get_mode(PERSISTENT) == false && NULL != v_str_ptr.p )
112 // /////////////////////////////////////
113 // should not delete what get() returns!
114 // /////////////////////////////////////
115 char* pstring::get(buffer& string_buffer)
117 //MESSAGE(cerr, "get()");
118 if ( get_mode(PERSISTENT) == true ) {
121 MESSAGE(cerr, "persistent");
123 debug(cerr, v_str_ptr.loc);
127 string_buffer.reset();
128 string_buffer.expand_chunk(v_sz+1);
130 char* this_v_str_ptr = string_buffer.get_base();
133 readString(v_str_ptr.loc, this_v_str_ptr, v_sz);
137 for (int i=0; i<v_sz; i++)
139 cerr << int(this_v_str_ptr[i]) << " " ;
145 this_v_str_ptr[v_sz] = 0;
147 string_buffer.set_content_sz(v_sz);
149 return this_v_str_ptr;
160 Boolean pstring::value_LS(root& x, Boolean safe) const
163 ( f_oid.ccode() != STRING_CODE ||
164 x.my_oid().ccode() != STRING_CODE
170 char* this_v_str_ptr;
173 if ( get_mode(PERSISTENT) == true ) {
174 this_v_str_ptr = new char[v_sz+1];
175 storage_ptr -> readString(v_str_ptr.loc, this_v_str_ptr, v_sz);
177 this_v_str_ptr = v_str_ptr.p;
179 pstring &casted_x = *(pstring*)&x;
181 if ( casted_x.get_mode(PERSISTENT) == true ) {
182 x_v_str_ptr = new char[v_sz+1];
184 readString(casted_x.v_str_ptr.loc, x_v_str_ptr, casted_x.v_sz);
186 x_v_str_ptr = casted_x.v_str_ptr.p;
188 int min_len = MIN(v_sz, casted_x.v_sz);
190 for ( int i=0; i<min_len; i++ ) {
191 if ( this_v_str_ptr[i] < x_v_str_ptr[i] ) {
196 if ( this_v_str_ptr[i] > x_v_str_ptr[i] ) {
202 if ( i == min_len && v_sz < casted_x.v_sz )
207 if ( get_mode(PERSISTENT) == true )
208 delete this_v_str_ptr;
210 if ( casted_x.get_mode(PERSISTENT) == true )
216 Boolean pstring::value_EQ(root& x, Boolean safe) const
219 ( f_oid.ccode() != STRING_CODE ||
220 x.my_oid().ccode() != STRING_CODE
225 pstring &casted_x = *(pstring*)&x;
227 if ( v_sz != casted_x.v_sz )
231 char* this_v_str_ptr;
234 if ( get_mode(PERSISTENT) == true ) {
235 this_v_str_ptr = new char[v_sz+1];
236 storage_ptr -> readString(v_str_ptr.loc, this_v_str_ptr, v_sz);
238 this_v_str_ptr = v_str_ptr.p;
240 if ( casted_x.get_mode(PERSISTENT) == true ) {
241 x_v_str_ptr = new char[v_sz+1];
243 readString(casted_x.v_str_ptr.loc, x_v_str_ptr, casted_x.v_sz);
245 x_v_str_ptr = casted_x.v_str_ptr.p;
247 //ok = ( bcmp(this_v_str_ptr, x_v_str_ptr, v_sz) == 0 ) ? true : false;
248 ok = ( memcmp(this_v_str_ptr, x_v_str_ptr, v_sz) == 0 ) ? true : false;
250 if ( get_mode(PERSISTENT) == true )
251 delete this_v_str_ptr;
253 if ( casted_x.get_mode(PERSISTENT) == true )
260 io_status pstring::asciiOut(ostream& out)
263 MESSAGE(cerr, "pstring::asciiOut():");
265 debug(cerr, (void*)this);
266 my_oid().asciiOut(cerr);
270 const char* x = get();
274 for ( unsigned int i=0; i<v_sz; i++ )
280 io_status pstring::asciiIn(istream& in)
283 MESSAGE(cerr, "pstring::asciiIn():");
284 debug(cerr, (void*)this);
285 my_oid().asciiOut(cerr);
290 pstring::update(v_io_buf.get_base(), v_io_buf.content_sz());
294 io_status pstring::asciiIn(const char* buf, int size)
297 v_io_buf.expand_chunk(size);
298 memcpy(v_io_buf.get_base(), buf, size);
299 v_io_buf.set_content_sz(size);
303 void pstring::_asciiIn(istream& in)
305 if ( ! cc_is_digit(in) )
306 throw (stringException("a digit expected"));
311 int tab = in.get(); // expect a '\t'
316 throw(stringException("'\\t' expected"));
320 v_io_buf.expand_chunk(len);
323 ( !in.read(v_io_buf.get_base(), len) || in.gcount() != len )
326 debug(cerr, v_io_buf.get_base());
327 throw(stringException("pstring::asciiIn(): read failed"));
330 int ret = in.get(); // expect a '\n'
334 throw(stringException(form("'\\n' expected. %c seen. (count=%d)", ret, len)));
337 v_io_buf.set_content_sz(len);
340 Boolean pstring::update(pstring& new_value)
342 return update((const char*)new_value.get(), new_value.v_sz);
345 Boolean pstring::update(const char* new_value, int new_value_sz)
349 MESSAGE(cerr, "pstring:: update value:");
350 debug(cerr, v_str_ptr.loc);
354 debug(cerr, new_value_sz);
355 for (int i=0; i<new_value_sz; i++)
357 cerr << int(new_value[i]) << " " ;
367 if ( get_mode(PERSISTENT) == true ) {
368 //MESSAGE(cerr, "persist case");
370 if ( v_str_ptr.loc == 0 ) {
371 storage_ptr -> insertString(v_str_ptr.loc, new_value, v_sz);
373 storage_ptr -> updateString(v_str_ptr.loc, new_value, v_sz);
378 if ( old_sz < new_value_sz ) {
380 v_str_ptr.p = new char[v_sz+1];
382 memcpy(v_str_ptr.p, new_value, v_sz);
383 *(v_str_ptr.p + v_sz) = '\0';
386 set_mode(UPDATE, true);
388 //debug(cerr, this -> get());
394 int pstring::cdr_sizeof()
396 return primitive::cdr_sizeof() +
397 sizeof(v_str_ptr.loc) +
401 io_status pstring::cdrOut(buffer& buf)
403 primitive::cdrOut(buf);
404 buf.put(v_str_ptr.loc);
409 io_status pstring::cdrIn(buffer& buf)
411 primitive::cdrIn(buf);
412 buf.get(v_str_ptr.loc);
419 pstring_handler::pstring_handler(const oid_t& v_oid, storagePtr _store) :
420 handler(v_oid, _store)
424 pstring_handler::pstring_handler(const char* str, int sz, storagePtr _store) :
425 handler(STRING_CODE, _store)
427 (this -> operator->()) -> update(str, sz);
430 pstring_handler::~pstring_handler()
434 pstring* pstring_handler::operator ->()
436 return (pstring*)handler::operator->();