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: smart_ptr.cc /main/4 1996/06/11 17:11:33 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.
52 #include "api/smart_ptr.h"
53 #include "object/compressed_pstring.h"
56 smart_ptr::smart_ptr(info_lib* lib_ptr,
57 const char* ibase_name,
59 const handler& query_hd,
64 info_base* ibase = lib_ptr -> get_info_base(ibase_name);
67 throw(stringException(
68 form("unknown base %s in %s\n", ibase_name,
69 lib_ptr -> get_info_lib_path()
72 //debug(cerr, ibase -> num_of_docs());
77 cset_handlerPtr set_ptr = ibase -> get_set(composite_pos);
80 throw(stringException("NULL set ptr"));
82 _init((*set_ptr)->get_first_oid(query_hd, index_selector),
83 set_ptr -> its_store()
89 dl_list_handlerPtr list_ptr = ibase -> get_list(composite_pos);
92 throw(stringException("NULL set ptr"));
94 _init((*list_ptr)->get_first_oid(query_hd, index_selector),
95 list_ptr -> its_store()
100 throw(stringException("unknown tag"));
105 smart_ptr::smart_ptr(info_base* ibase,
107 const handler& query_hd,
115 cset_handlerPtr set_ptr = ibase -> get_set(composite_pos);
118 throw(stringException("NULL set ptr"));
120 _init((*set_ptr)->get_first_oid(query_hd, index_selector),
121 set_ptr -> its_store()
127 dl_list_handlerPtr list_ptr = ibase -> get_list(composite_pos);
130 throw(stringException("NULL set ptr"));
132 _init((*list_ptr)->get_first_oid(query_hd, index_selector),
133 list_ptr -> its_store()
138 throw(stringException("unknown tag"));
145 smart_ptr::smart_ptr()
149 smart_ptr::~smart_ptr()
154 void smart_ptr::_init(const oid_t& id, const abs_storage* x)
156 //MESSAGE(cerr, "smart_ptr::_init()");
158 //obj_id.asciiOut(cerr); cerr << "\n";
160 store = (abs_storage*)x;
163 handler::operator->();
165 //obj_id.asciiOut(cerr); cerr << "\n";
166 //debug(cerr, int(obj_ptr));
167 //MESSAGE(cerr, "smart_ptr::_init() done");
171 handler* smart_ptr::get_handler(int i, c_code_t code)
173 handler* x = _get_component(i);
176 if ( x -> its_oid().ccode() != code )
177 throw(stringException("invalid node data class code"));
182 int smart_ptr::get_int(int i)
184 handler* x = get_handler(i, INTEGER_CODE);
185 int y= (*(integer_handler*)x) -> get();
191 const char* smart_ptr::get_string(int i, buffer& buf)
193 handler* x = _get_component(i);
195 x -> operator->(); // this will bring the its_oid field up-to-date
199 switch ( x -> its_oid().ccode() ) {
202 str = (*(pstring_handler*)x) -> get(buf);
205 case COMPRESSED_STRING_CODE:
207 str = (*(compressed_pstring_handler*)x) -> get(buf);
212 throw(stringException("invalid node data class code"));
220 const char* smart_ptr::get_string(int i)
222 handler* x = _get_component(i);
224 x -> operator->(); // this will bring the its_oid field up-to-date
228 switch ( x -> its_oid().ccode() ) {
231 str = (*(pstring_handler*)x) -> get();
234 case COMPRESSED_STRING_CODE:
236 str = (*(compressed_pstring_handler*)x) -> get();
241 throw(stringException("invalid node data class code"));
250 int smart_ptr::get_string_size(int i)
252 handler* x = _get_component(i);
253 x -> operator->(); // this will bring the its_oid field up-to-date
257 switch ( x -> its_oid().ccode() ) {
259 y = (*(pstring_handler*)x) -> size();
262 case COMPRESSED_STRING_CODE:
263 y = (*(compressed_pstring_handler*)x) -> size();
267 throw(stringException("invalid node data class code"));
275 oid_t smart_ptr::get_oid(int i)
277 handler* x = get_handler(i, OID_CODE);
278 oid_t y = (*(oid_handler*)x) -> my_coid();
284 void smart_ptr::update_oid(int i, const oid_t& x)
288 handler* z = get_handler(i, OID_CODE);
289 oid_handler* y = (oid_handler*)z;
291 snprintf(buf, sizeof(buf), "%d.%d\n", x.ccode(), (int)x.icode());
292 istringstream in(buf);
299 void smart_ptr::update_string(int i, istream& in)
301 handler* x = _get_component(i);
303 x -> operator->(); // this will bring the its_oid field up-to-date
306 switch ( x -> its_oid().ccode() ) {
308 ok =(*(pstring_handler*)x) -> asciiIn(in);
311 case COMPRESSED_STRING_CODE:
312 ok =(*(compressed_pstring_handler*)x) -> _asciiIn(in);
316 throw(stringException("invalid node data class code"));
323 void smart_ptr::update_string(int i, const char* buf, int size)
325 handler* x = _get_component(i);
327 x -> operator->(); // this will bring the its_oid field up-to-date
329 switch ( x -> its_oid().ccode() ) {
331 (*(pstring_handler*)x) -> update(buf, size);
334 case COMPRESSED_STRING_CODE:
335 (*(compressed_pstring_handler*)x) -> _asciiIn(buf, size);
339 throw(stringException("invalid node data class code"));