2010-12-20 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / ada / a-stwiun-shared.ads
blobba4cbce3449745bc993eacf5f5393e0717b8f0b8
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . W I D E _ U N B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 -- This version is supported on:
39 -- - all Alpha platforms
40 -- - all ia64 platforms
41 -- - all PowerPC platforms
42 -- - all SPARC V9 platforms
43 -- - all x86_64 platforms
45 with Ada.Strings.Wide_Maps;
46 private with Ada.Finalization;
47 private with Interfaces;
49 package Ada.Strings.Wide_Unbounded is
50 pragma Preelaborate;
52 type Unbounded_Wide_String is private;
53 pragma Preelaborable_Initialization (Unbounded_Wide_String);
55 Null_Unbounded_Wide_String : constant Unbounded_Wide_String;
57 function Length (Source : Unbounded_Wide_String) return Natural;
59 type Wide_String_Access is access all Wide_String;
61 procedure Free (X : in out Wide_String_Access);
63 --------------------------------------------------------
64 -- Conversion, Concatenation, and Selection Functions --
65 --------------------------------------------------------
67 function To_Unbounded_Wide_String
68 (Source : Wide_String) return Unbounded_Wide_String;
70 function To_Unbounded_Wide_String
71 (Length : Natural) return Unbounded_Wide_String;
73 function To_Wide_String
74 (Source : Unbounded_Wide_String) return Wide_String;
76 procedure Set_Unbounded_Wide_String
77 (Target : out Unbounded_Wide_String;
78 Source : Wide_String);
79 pragma Ada_05 (Set_Unbounded_Wide_String);
81 procedure Append
82 (Source : in out Unbounded_Wide_String;
83 New_Item : Unbounded_Wide_String);
85 procedure Append
86 (Source : in out Unbounded_Wide_String;
87 New_Item : Wide_String);
89 procedure Append
90 (Source : in out Unbounded_Wide_String;
91 New_Item : Wide_Character);
93 function "&"
94 (Left : Unbounded_Wide_String;
95 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
97 function "&"
98 (Left : Unbounded_Wide_String;
99 Right : Wide_String) return Unbounded_Wide_String;
101 function "&"
102 (Left : Wide_String;
103 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
105 function "&"
106 (Left : Unbounded_Wide_String;
107 Right : Wide_Character) return Unbounded_Wide_String;
109 function "&"
110 (Left : Wide_Character;
111 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
113 function Element
114 (Source : Unbounded_Wide_String;
115 Index : Positive) return Wide_Character;
117 procedure Replace_Element
118 (Source : in out Unbounded_Wide_String;
119 Index : Positive;
120 By : Wide_Character);
122 function Slice
123 (Source : Unbounded_Wide_String;
124 Low : Positive;
125 High : Natural) return Wide_String;
127 function Unbounded_Slice
128 (Source : Unbounded_Wide_String;
129 Low : Positive;
130 High : Natural) return Unbounded_Wide_String;
131 pragma Ada_05 (Unbounded_Slice);
133 procedure Unbounded_Slice
134 (Source : Unbounded_Wide_String;
135 Target : out Unbounded_Wide_String;
136 Low : Positive;
137 High : Natural);
138 pragma Ada_05 (Unbounded_Slice);
140 function "="
141 (Left : Unbounded_Wide_String;
142 Right : Unbounded_Wide_String) return Boolean;
144 function "="
145 (Left : Unbounded_Wide_String;
146 Right : Wide_String) return Boolean;
148 function "="
149 (Left : Wide_String;
150 Right : Unbounded_Wide_String) return Boolean;
152 function "<"
153 (Left : Unbounded_Wide_String;
154 Right : Unbounded_Wide_String) return Boolean;
156 function "<"
157 (Left : Unbounded_Wide_String;
158 Right : Wide_String) return Boolean;
160 function "<"
161 (Left : Wide_String;
162 Right : Unbounded_Wide_String) return Boolean;
164 function "<="
165 (Left : Unbounded_Wide_String;
166 Right : Unbounded_Wide_String) return Boolean;
168 function "<="
169 (Left : Unbounded_Wide_String;
170 Right : Wide_String) return Boolean;
172 function "<="
173 (Left : Wide_String;
174 Right : Unbounded_Wide_String) return Boolean;
176 function ">"
177 (Left : Unbounded_Wide_String;
178 Right : Unbounded_Wide_String) return Boolean;
180 function ">"
181 (Left : Unbounded_Wide_String;
182 Right : Wide_String) return Boolean;
184 function ">"
185 (Left : Wide_String;
186 Right : Unbounded_Wide_String) return Boolean;
188 function ">="
189 (Left : Unbounded_Wide_String;
190 Right : Unbounded_Wide_String) return Boolean;
192 function ">="
193 (Left : Unbounded_Wide_String;
194 Right : Wide_String) return Boolean;
196 function ">="
197 (Left : Wide_String;
198 Right : Unbounded_Wide_String) return Boolean;
200 ------------------------
201 -- Search Subprograms --
202 ------------------------
204 function Index
205 (Source : Unbounded_Wide_String;
206 Pattern : Wide_String;
207 Going : Direction := Forward;
208 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
209 return Natural;
211 function Index
212 (Source : Unbounded_Wide_String;
213 Pattern : Wide_String;
214 Going : Direction := Forward;
215 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
217 function Index
218 (Source : Unbounded_Wide_String;
219 Set : Wide_Maps.Wide_Character_Set;
220 Test : Membership := Inside;
221 Going : Direction := Forward) return Natural;
223 function Index
224 (Source : Unbounded_Wide_String;
225 Pattern : Wide_String;
226 From : Positive;
227 Going : Direction := Forward;
228 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
229 return Natural;
230 pragma Ada_05 (Index);
232 function Index
233 (Source : Unbounded_Wide_String;
234 Pattern : Wide_String;
235 From : Positive;
236 Going : Direction := Forward;
237 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
238 pragma Ada_05 (Index);
240 function Index
241 (Source : Unbounded_Wide_String;
242 Set : Wide_Maps.Wide_Character_Set;
243 From : Positive;
244 Test : Membership := Inside;
245 Going : Direction := Forward) return Natural;
246 pragma Ada_05 (Index);
248 function Index_Non_Blank
249 (Source : Unbounded_Wide_String;
250 Going : Direction := Forward) return Natural;
252 function Index_Non_Blank
253 (Source : Unbounded_Wide_String;
254 From : Positive;
255 Going : Direction := Forward) return Natural;
256 pragma Ada_05 (Index_Non_Blank);
258 function Count
259 (Source : Unbounded_Wide_String;
260 Pattern : Wide_String;
261 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
262 return Natural;
264 function Count
265 (Source : Unbounded_Wide_String;
266 Pattern : Wide_String;
267 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
269 function Count
270 (Source : Unbounded_Wide_String;
271 Set : Wide_Maps.Wide_Character_Set) return Natural;
273 procedure Find_Token
274 (Source : Unbounded_Wide_String;
275 Set : Wide_Maps.Wide_Character_Set;
276 From : Positive;
277 Test : Membership;
278 First : out Positive;
279 Last : out Natural);
280 pragma Ada_2012 (Find_Token);
282 procedure Find_Token
283 (Source : Unbounded_Wide_String;
284 Set : Wide_Maps.Wide_Character_Set;
285 Test : Membership;
286 First : out Positive;
287 Last : out Natural);
289 ------------------------------------
290 -- String Translation Subprograms --
291 ------------------------------------
293 function Translate
294 (Source : Unbounded_Wide_String;
295 Mapping : Wide_Maps.Wide_Character_Mapping)
296 return Unbounded_Wide_String;
298 procedure Translate
299 (Source : in out Unbounded_Wide_String;
300 Mapping : Wide_Maps.Wide_Character_Mapping);
302 function Translate
303 (Source : Unbounded_Wide_String;
304 Mapping : Wide_Maps.Wide_Character_Mapping_Function)
305 return Unbounded_Wide_String;
307 procedure Translate
308 (Source : in out Unbounded_Wide_String;
309 Mapping : Wide_Maps.Wide_Character_Mapping_Function);
311 ---------------------------------------
312 -- String Transformation Subprograms --
313 ---------------------------------------
315 function Replace_Slice
316 (Source : Unbounded_Wide_String;
317 Low : Positive;
318 High : Natural;
319 By : Wide_String) return Unbounded_Wide_String;
321 procedure Replace_Slice
322 (Source : in out Unbounded_Wide_String;
323 Low : Positive;
324 High : Natural;
325 By : Wide_String);
327 function Insert
328 (Source : Unbounded_Wide_String;
329 Before : Positive;
330 New_Item : Wide_String) return Unbounded_Wide_String;
332 procedure Insert
333 (Source : in out Unbounded_Wide_String;
334 Before : Positive;
335 New_Item : Wide_String);
337 function Overwrite
338 (Source : Unbounded_Wide_String;
339 Position : Positive;
340 New_Item : Wide_String) return Unbounded_Wide_String;
342 procedure Overwrite
343 (Source : in out Unbounded_Wide_String;
344 Position : Positive;
345 New_Item : Wide_String);
347 function Delete
348 (Source : Unbounded_Wide_String;
349 From : Positive;
350 Through : Natural) return Unbounded_Wide_String;
352 procedure Delete
353 (Source : in out Unbounded_Wide_String;
354 From : Positive;
355 Through : Natural);
357 function Trim
358 (Source : Unbounded_Wide_String;
359 Side : Trim_End) return Unbounded_Wide_String;
361 procedure Trim
362 (Source : in out Unbounded_Wide_String;
363 Side : Trim_End);
365 function Trim
366 (Source : Unbounded_Wide_String;
367 Left : Wide_Maps.Wide_Character_Set;
368 Right : Wide_Maps.Wide_Character_Set) return Unbounded_Wide_String;
370 procedure Trim
371 (Source : in out Unbounded_Wide_String;
372 Left : Wide_Maps.Wide_Character_Set;
373 Right : Wide_Maps.Wide_Character_Set);
375 function Head
376 (Source : Unbounded_Wide_String;
377 Count : Natural;
378 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
380 procedure Head
381 (Source : in out Unbounded_Wide_String;
382 Count : Natural;
383 Pad : Wide_Character := Wide_Space);
385 function Tail
386 (Source : Unbounded_Wide_String;
387 Count : Natural;
388 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
390 procedure Tail
391 (Source : in out Unbounded_Wide_String;
392 Count : Natural;
393 Pad : Wide_Character := Wide_Space);
395 function "*"
396 (Left : Natural;
397 Right : Wide_Character) return Unbounded_Wide_String;
399 function "*"
400 (Left : Natural;
401 Right : Wide_String) return Unbounded_Wide_String;
403 function "*"
404 (Left : Natural;
405 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
407 private
408 pragma Inline (Length);
410 package AF renames Ada.Finalization;
412 type Shared_Wide_String (Max_Length : Natural) is limited record
413 Counter : aliased Interfaces.Unsigned_32 := 1;
414 -- Reference counter.
416 Last : Natural := 0;
417 Data : Wide_String (1 .. Max_Length);
418 -- Last is the index of last significant element of the Data. All
419 -- elements with larger indices are just an extra room.
420 end record;
422 type Shared_Wide_String_Access is access all Shared_Wide_String;
424 procedure Reference (Item : not null Shared_Wide_String_Access);
425 -- Increment reference counter.
427 procedure Unreference (Item : not null Shared_Wide_String_Access);
428 -- Decrement reference counter. Deallocate Item when reference counter is
429 -- zero.
431 function Can_Be_Reused
432 (Item : Shared_Wide_String_Access;
433 Length : Natural) return Boolean;
434 -- Returns True if Shared_Wide_String can be reused. There are two criteria
435 -- when Shared_Wide_String can be reused: its reference counter must be one
436 -- (thus Shared_Wide_String is owned exclusively) and its size is
437 -- sufficient to store string with specified length effectively.
439 function Allocate (Max_Length : Natural) return Shared_Wide_String_Access;
440 -- Allocates new Shared_Wide_String with at least specified maximum length.
441 -- Actual maximum length of the allocated Shared_Wide_String can be
442 -- slightly greater. Returns reference to Empty_Shared_Wide_String when
443 -- requested length is zero.
445 Empty_Shared_Wide_String : aliased Shared_Wide_String (0);
447 function To_Unbounded (S : Wide_String) return Unbounded_Wide_String
448 renames To_Unbounded_Wide_String;
449 -- This renames are here only to be used in the pragma Stream_Convert.
451 type Unbounded_Wide_String is new AF.Controlled with record
452 Reference : Shared_Wide_String_Access := Empty_Shared_Wide_String'Access;
453 end record;
455 -- The Unbounded_Wide_String uses several techniques to increase speed of
456 -- the application:
457 -- - implicit sharing or copy-on-write. Unbounded_Wide_String contains
458 -- only the reference to the data which is shared between several
459 -- instances. The shared data is reallocated only when its value is
460 -- changed and the object mutation can't be used or it is inefficient to
461 -- use it;
462 -- - object mutation. Shared data object can be reused without memory
463 -- reallocation when all of the following requirements are meat:
464 -- - shared data object don't used anywhere longer;
465 -- - its size is sufficient to store new value;
466 -- - the gap after reuse is less then some threshold.
467 -- - memory preallocation. Most of used memory allocation algorithms
468 -- aligns allocated segment on the some boundary, thus some amount of
469 -- additional memory can be preallocated without any impact. Such
470 -- preallocated memory can used later by Append/Insert operations
471 -- without reallocation.
473 -- Reference counting uses GCC builtin atomic operations, which allows to
474 -- safely share internal data between Ada tasks. Nevertheless, this not
475 -- make objects of Unbounded_Wide_String thread-safe, so each instance
476 -- can't be accessed by several tasks simultaneously.
478 pragma Stream_Convert (Unbounded_Wide_String, To_Unbounded, To_Wide_String);
479 -- Provide stream routines without dragging in Ada.Streams
481 pragma Finalize_Storage_Only (Unbounded_Wide_String);
482 -- Finalization is required only for freeing storage
484 overriding procedure Initialize (Object : in out Unbounded_Wide_String);
485 overriding procedure Adjust (Object : in out Unbounded_Wide_String);
486 overriding procedure Finalize (Object : in out Unbounded_Wide_String);
488 Null_Unbounded_Wide_String : constant Unbounded_Wide_String :=
489 (AF.Controlled with
490 Reference => Empty_Shared_Wide_String'Access);
492 end Ada.Strings.Wide_Unbounded;