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: compressed_pstring.cc /main/4 1996/06/11 17:23:44 cde-hal $
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/compressed_pstring.h"
54 buffer* compressed_pstring::working_buffer_ptr;
55 buffer* compressed_pstring::v_cp_io_buf_ptr;
56 #define working_buffer (*working_buffer_ptr)
57 #define v_cp_io_buf (*v_cp_io_buf_ptr)
58 // for pstring's buffer
59 #define v_io_buf (*v_io_buf_ptr)
61 buffer compressed_pstring::working_buffer(LBUFSIZ);
62 buffer compressed_pstring::v_cp_io_buf(LBUFSIZ);
66 compressed_pstring::compressed_pstring(c_code_t c_id) :
67 pstring(c_id), agent(0), v_uncompressed_sz(0)
71 compressed_pstring::~compressed_pstring()
75 MMDB_BODIES(compressed_pstring)
77 char* compressed_pstring::get(buffer& string_buffer)
79 //MESSAGE(cerr, "compressed_pstring::get()");
80 //debug(cerr, v_uncompressed_sz);
83 string_buffer.reset();
84 string_buffer.expand_chunk(v_uncompressed_sz+1);
86 pstring::get(working_buffer);
88 // use cached version of compression agent
89 //debug(cerr, compress_agent_id);
91 if ( (storage_ptr -> my_oid()).ccode() == MEM_STORAGE_CODE )
92 agent = (compress_agent_handler*)
93 (new handler(DICT_AGENT_CODE, storage_ptr));
95 agent = new compress_agent_handler(compress_agent_id, storage_ptr);
97 (*agent) -> decompress(working_buffer, string_buffer);
101 string_buffer.get_base()[v_uncompressed_sz] = 0;
103 //MESSAGE(cerr, "compressed_pstring::get() done");
104 return string_buffer.get_base();
107 io_status compressed_pstring::asciiIn(istream& in)
109 compress_agent_id.asciiIn(in); // compress agent oid part
110 //debug(cerr, compress_agent_id);
111 return this -> _asciiIn(in);
114 io_status compressed_pstring::asciiIn(const char* buf, int size, const oid_t& id)
116 compress_agent_id.become(id); // compress agent oid part
117 return this -> _asciiIn(buf, size);
120 io_status compressed_pstring::asciiIn(const char* buf, int size)
122 return pstring::asciiIn(buf, size);
125 io_status compressed_pstring::_asciiIn(istream& in)
127 // use cached version of compression agent
129 if ( (storage_ptr -> my_oid()).ccode() == MEM_STORAGE_CODE )
130 agent = (compress_agent_handler*)
131 (new handler(DICT_AGENT_CODE, storage_ptr));
133 agent = new compress_agent_handler(compress_agent_id, storage_ptr);
135 pstring::_asciiIn(in);
142 io_status compressed_pstring::_asciiIn(const char* buf, int size)
144 // use cached version of compression agent
145 if ( (storage_ptr -> my_oid()).ccode() == MEM_STORAGE_CODE )
146 agent = (compress_agent_handler*)
147 (new handler(DICT_AGENT_CODE, storage_ptr));
149 agent = new compress_agent_handler(compress_agent_id, storage_ptr);
151 pstring::asciiIn(buf, size); // uncompress data part
158 void compressed_pstring::_compress()
160 v_uncompressed_sz = v_io_buf.content_sz();
162 if ( v_uncompressed_sz > 0 ) {
164 working_buffer.reset();
166 (*agent) -> compress(v_io_buf, working_buffer);
168 //debug(cerr, v_uncompressed_sz);
169 //debug(cerr, working_buffer.content_sz());
171 pstring::update(working_buffer.get_base(), working_buffer.content_sz());
174 set_mode(UPDATE, true);
180 int compressed_pstring::size() const
182 return v_uncompressed_sz;
185 int compressed_pstring::cdr_sizeof()
187 return pstring::cdr_sizeof() + sizeof(v_uncompressed_sz) +
188 compress_agent_id.cdr_sizeof();
191 io_status compressed_pstring::cdrOut(buffer& buf)
193 //MESSAGE(cerr, "compressed_pstring: cdrOut()");
194 //debug(cerr, compress_agent_id);
196 pstring::cdrOut(buf);
197 buf.put(v_uncompressed_sz);
198 return compress_agent_id.cdrOut(buf);
201 io_status compressed_pstring::cdrIn(buffer& buf)
204 buf.get(v_uncompressed_sz);
205 return compress_agent_id.cdrIn(buf);
208 HANDLER_BODIES(compressed_pstring)