Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / util / utl_idlist.cpp
blobfb54813d80f8e66072e399dc4244403d2470c221
1 /*
3 COPYRIGHT
5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // Implementation of a list of utl_string nodes.
67 // NOTE: This list class only works correctly because we use single public
68 // inheritance, as opposed to multiple inheritance or public virtual.
69 // It relies on a type-unsafe cast from UTL_List to subclasses, which
70 // will cease to operate correctly if you use either multiple or
71 // public virtual inheritance.
73 #include "utl_idlist.h"
74 #include "utl_identifier.h"
75 #include "ace/OS_Memory.h"
76 #include "ace/OS_NS_string.h"
78 // FUZZ: disable check_for_streams_include
79 #include "ace/streams.h"
81 // Constructor
82 UTL_IdList::UTL_IdList (Identifier *s,
83 UTL_IdList *cdr)
84 : UTL_List ((UTL_List *) cdr),
85 pd_car_data (s)
89 // Public operations
91 // Copy an IdList.
92 UTL_IdList *
93 UTL_IdList::copy ()
95 UTL_IdList *retval = nullptr;
96 ACE_NEW_RETURN (retval,
97 UTL_IdList (this->head ()->copy (),
98 nullptr),
99 nullptr);
101 if (this->tail () != nullptr)
103 retval->nconc ((UTL_IdList *) this->tail ()->copy ());
106 return retval;
109 // Get list item.
110 Identifier *
111 UTL_IdList::head ()
113 return this->pd_car_data;
116 // Get last item of this list.
117 Identifier *
118 UTL_IdList::last_component ()
120 if (this->tail () == nullptr)
122 return this->head ();
125 return ((UTL_IdList *) this->tail ())->last_component ();
128 // Get first item of this list holding a non-empty string.
129 Identifier *
130 UTL_IdList::first_component ()
132 if (ACE_OS::strlen (this->pd_car_data->get_string ()) > 0)
134 return this->pd_car_data;
137 return ((UTL_IdList *) this->tail ())->first_component ();
141 UTL_IdList::compare (UTL_IdList *other)
143 long this_length = this->length ();
145 // Strip away any leading empty segments.
147 if (ACE_OS::strlen (this->pd_car_data->get_string ()) == 0)
149 UTL_List *this_tail = this->tail ();
151 if (this_tail == nullptr)
153 return 1;
156 return ((UTL_IdList *) this_tail)->compare (other);
159 if (ACE_OS::strlen (other->pd_car_data->get_string ()) == 0)
161 UTL_List *other_tail = other->tail ();
163 if (other_tail == nullptr)
165 return 1;
168 return this->compare ((UTL_IdList *) other->tail ());
171 if (this_length != other->length ())
173 return 1;
176 Identifier *this_id = nullptr;
177 Identifier *other_id = nullptr;
179 for (UTL_IdListActiveIterator this_iter (this), other_iter (other);
180 !this_iter.is_done ();
181 this_iter.next (), other_iter.next ())
183 this_id = this_iter.item ();
184 other_id = other_iter.item ();
186 if (ACE_OS::strcmp (this_id->get_string (),
187 other_id->get_string ())
188 != 0)
190 return 1;
194 return 0;
197 // AST Dumping.
198 void
199 UTL_IdList::dump (ACE_OSTREAM_TYPE &o)
201 bool first = true;
202 bool second = false;
204 for (UTL_IdListActiveIterator i (this);
205 !i.is_done ();
206 i.next ())
208 if (!first)
210 o << "::";
212 else if (second)
214 first = second = false;
217 if (i.item ()->get_string ())
219 i.item ()->dump (o);
221 if (first)
223 if (ACE_OS::strcmp (i.item ()->get_string (), "::") != 0)
225 first = false;
227 else
229 second = true;
233 else
235 o << "(null string)";
240 void
241 UTL_IdList::destroy ()
243 if (this->pd_car_data != nullptr)
245 this->pd_car_data->destroy ();
246 delete this->pd_car_data;
247 this->pd_car_data = nullptr;
250 this->UTL_List::destroy ();
253 // UTL_IdList active iterator.
255 // Constructor
256 UTL_IdListActiveIterator::UTL_IdListActiveIterator (UTL_IdList *s)
257 : UTL_ListActiveIterator (s)
261 // Public operations.
263 // Get current item.
264 Identifier *
265 UTL_IdListActiveIterator::item ()
267 if (this->source == nullptr)
269 return nullptr;
272 return ((UTL_IdList *) source)->head ();
275 char *
276 UTL_IdList::get_string_copy ()
279 * Absolute Names have "::" as the first item in the idlist, so delimiters
280 * have to start be inserted depending on if the name is absolute or not
282 size_t delimiter_start = is_absolute () ? 1 : 0;
284 // Get buffer of the correct size
285 size_t n = 0;
286 size_t size = 1;
287 for (UTL_IdListActiveIterator i (this);
288 !i.is_done ();
289 i.next ())
291 if (n > delimiter_start)
293 size += 2; // For delimiter
295 const char *item = i.item ()->get_string ();
296 size += ACE_OS::strlen (item);
297 n++;
299 char *buffer = new char[size];
300 buffer[0] = '\0';
302 // Fill buffer
303 n = 0;
304 for (UTL_IdListActiveIterator i (this);
305 !i.is_done ();
306 i.next ())
308 if (n > delimiter_start)
310 ACE_OS::strcat (buffer, "::");
312 const char *item = i.item ()->get_string ();
313 ACE_OS::strcat (buffer, item);
314 n++;
317 buffer[size - 1] = '\0';
319 return buffer;
322 bool
323 UTL_IdList::is_absolute ()
325 return !ACE_OS::strcmp (first_component ()->get_string (), "::");