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 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $TOG: mp_otype.C /main/4 1998/03/20 14:27:39 mgreess $
31 * Copyright (c) 1990 by Sun Microsystems, Inc.
35 # include <g++/minmax.h>
39 #include "mp/mp_global.h"
42 #include "mp_otype_utils.h"
43 #include "mp_ce_attrs.h"
44 #include "util/tt_enumname.h"
45 #include "util/tt_iostream.h"
48 // This file contains methods for _Tt_otype objects which embody the
49 // behavior of otype definitions.
56 _ancestors = new _Tt_string_list();
57 _children = (_Tt_string_list *)0;
58 _inhs = new _Tt_signature_list();
59 _osigs = new _Tt_signature_list();
60 _hsigs = new _Tt_signature_list();
69 return(_otid.xdr(xdrs) &&
70 _ancestors.xdr(xdrs) &&
74 xdr_int(xdrs, &visitp));
79 _Tt_otype(_Tt_string otid)
81 _ancestors = new _Tt_string_list();
82 _children = (_Tt_string_list *)0;
83 _inhs = new _Tt_signature_list();
84 _osigs = new _Tt_signature_list();
85 _hsigs = new _Tt_signature_list();
99 set_otid(_Tt_string otid)
106 set_ancestors(_Tt_string_list_ptr ancs)
113 // Appends an inherited signature to this object if there isn't the
114 // same signature already.
117 append_inhs(_Tt_signature_ptr sig)
119 if (_inhs.is_null()) {
120 _inhs = new _Tt_signature_list();
123 _Tt_signature_list_cursor sc(_inhs);
136 // Appends an observer signature to this object if there isn't the
137 // same signature already.
140 append_osig(_Tt_signature_ptr sig)
142 sig->set_pattern_category(TT_OBSERVE);
144 if (_osigs.is_null()) {
145 _osigs = new _Tt_signature_list();
148 _Tt_signature_list_cursor sc(_osigs);
161 // Appends a handler signature to this object if there isn't the same
162 // signature already.
165 append_hsig(_Tt_signature_ptr sig, Tt_category category)
167 sig->set_pattern_category(category);
169 if (_hsigs.is_null()) {
170 _hsigs = new _Tt_signature_list();
173 _Tt_signature_list_cursor sc(_hsigs);
186 // Appends a list of observer signatures to this object.
189 append_osigs(_Tt_signature_list_ptr sigs)
191 _Tt_signature_list_cursor sc(sigs);
194 sc->set_pattern_category(TT_OBSERVE);
196 if (_osigs.is_null()) {
199 _osigs->append_destructive(sigs);
205 // Appends a list of handler signature to this object.
208 append_hsigs(_Tt_signature_list_ptr sigs, Tt_category category)
210 _Tt_signature_list_cursor sc(sigs);
213 sc->set_pattern_category(category);
215 if (_hsigs.is_null()) {
218 _hsigs->append_destructive(sigs);
224 // Prints out a _Tt_otype object. Note that the format used to print
225 // the object is the format used to represent this object to the
226 // Classing Engine. It is important to preserve this characteristic
227 // for compatibility's sake.
230 print(const _Tt_ostream &os) const
232 _Tt_string_list_cursor anc;
233 FILE *fs = os.theFILE();
236 fprintf(fs, "\t(\n\t\t(%s,%s,<",
237 _tt_ce_attr_string(_TYPE_NAME),
238 _tt_ce_attr_string(_TT_TOOLTALK_OTYPE));
241 fprintf(fs,"\t\t(%s,string,<%s>)\n",
242 _tt_ce_attr_string(_TT_TOOLTALK_TYPE),
243 _tt_ce_attr_string(_TT_TOOLTALK_OTYPE));
244 if (! _ancestors.is_null()) {
245 anc.reset(_ancestors);
247 fprintf(fs,"\t\t(%s,string,<%s>)\n",
248 _tt_ce_attr_string(_TT_PARENT),
258 // Returns a list of descendant otypes from this otype.
260 _Tt_string_list_ptr & _Tt_otype::
263 _Tt_otype_table_cursor c;
264 _Tt_string_list_ptr plist;
266 _Tt_otype_ptr cparent;
268 if (!_children.is_null()) {
271 _children = new _Tt_string_list;
273 c.reset(_tt_s_mp->otable);
275 plist = c->parents();
276 if (!plist.is_null() && plist->count()!=0) {
277 parname = plist->top();
278 if (! _tt_s_mp->otable->lookup(parname,cparent)) {
279 if (cparent->otid() == otid()) {
280 _children->append(c->otid());
289 _Tt_string_list_ptr & _Tt_otype::
296 _Tt_signature_list_ptr &_Tt_otype::
303 _Tt_signature_list_ptr &_Tt_otype::
311 xdr_version_required() const
313 int version = _Tt_signature::xdr_version_required_( _hsigs );
314 return max(version, _Tt_signature::xdr_version_required_( _osigs ));
318 // Prints out an otype object in source format. This means that the
319 // otype is printed out in such a fashion that the result is parseable
320 // by tt_type_comp and when parsed would reproduce the essential
321 // structure of this object.
324 pretty_print(const _Tt_ostream &os) const
326 _Tt_string_list_cursor anc;
328 FILE *fs = os.theFILE();
330 fprintf(fs,"otype ");
332 if (! _ancestors.is_null() && _ancestors->count()) {
334 anc.reset(_ancestors);
336 fprintf(fs," %s", (char *)*anc);
340 _Tt_signature::pretty_print_( os, _hsigs, TT_HANDLE, 0 );
341 _Tt_signature::pretty_print_( os, _hsigs, TT_HANDLE_PUSH, 0 );
342 _Tt_signature::pretty_print_( os, _hsigs, TT_HANDLE_ROTATE, 0 );
343 _Tt_signature::pretty_print_( os, _osigs, TT_OBSERVE, 0 );
349 // Returns the otid of the given _Tt_object which is assumed to be a
350 // _Tt_otype object. This is used by the generic table package to
351 // generate a key for an entry in the table.
354 _tt_otype_otid(_Tt_object_ptr &o)
356 return(((_Tt_otype *)o.c_pointer())->otid());
361 // Invokes the print method on the given _Tt_object which is assumed to
362 // really point to a _Tt_otype object. This is used by the generic table
363 // and list objects in their print methods.
366 _tt_otype_print(const _Tt_ostream &os, const _Tt_object *obj)
368 ((_Tt_otype *)obj)->print(os);