comp.lang.ada
 help / color / mirror / Atom feed
* Q: Localizing type and package references
@ 2014-01-05 23:55 b.mcguinness747
  2014-01-06  1:29 ` Jeffrey Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: b.mcguinness747 @ 2014-01-05 23:55 UTC (permalink / raw)


I want to write an Ada program using the Wide_Character type, but I might
want to move to Wide_Wide_Character later on.  So I want to localize all
references to Wide_Character and the associated standard Ada packages to
a single file that I can easily update.  If I was working in C++, I would
use typedefs to create pseudonyms and put these in a header file that I could
#include from various source files.  So I have tried to do something similar
in Ada.  I created the file types.ads:

--------------------------------------------------------------------------------
-- Types - Declarations of data types and related packages
--------------------------------------------------------------------------------
with Ada.Characters;
with Ada.Characters.Wide_Latin_1;
with Ada.Strings;
with Ada.Strings.Wide_Maps;
with Ada.Strings.Wide_Unbounded;
with Ada.Wide_Characters;
with Ada.Wide_Characters.Handling;
with Ada.Wide_Text_IO;
with Ada.Wide_Text_IO.Text_Streams;

package Types is
  package Chars         renames Ada.Characters.Wide_Latin_1;
  package Char_Handling renames Ada.Wide_Characters.Handling;
  package Char_IO       renames Ada.Wide_Text_IO;
  package Char_Maps     renames Ada.Strings.Wide_Maps;
  package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
  package Char_Strings  renames Ada.Strings.Wide_Unbounded;

  subtype Char        is Wide_Character;
  subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
end Types;


and then tried referencing this from the main program file with:


with Types;
use  Types;

with Char_Strings;


but the compiler (Gnat 4.6) complains that there is no file called
char_strings.ads.  I am not sure if I have made a simple mistake that
can be easily corrected to make this work, or if there is a different
approach that I should be trying.

Help would be appreciated.

Thanks.

--- Brian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-05 23:55 Q: Localizing type and package references b.mcguinness747
@ 2014-01-06  1:29 ` Jeffrey Carter
  2014-01-06  8:05   ` Simon Wright
  2014-01-06  8:28 ` Dmitry A. Kazakov
  2014-01-06 22:02 ` b.mcguinness747
  2 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2014-01-06  1:29 UTC (permalink / raw)


On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>
> --------------------------------------------------------------------------------
> -- Types - Declarations of data types and related packages
> --------------------------------------------------------------------------------
> with Ada.Characters;
> with Ada.Characters.Wide_Latin_1;
> with Ada.Strings;
> with Ada.Strings.Wide_Maps;
> with Ada.Strings.Wide_Unbounded;
> with Ada.Wide_Characters;
> with Ada.Wide_Characters.Handling;
> with Ada.Wide_Text_IO;
> with Ada.Wide_Text_IO.Text_Streams;
>
> package Types is
>    package Chars         renames Ada.Characters.Wide_Latin_1;
>    package Char_Handling renames Ada.Wide_Characters.Handling;
>    package Char_IO       renames Ada.Wide_Text_IO;
>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>
>    subtype Char        is Wide_Character;
>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
> end Types;
>
> and then tried referencing this from the main program file with:
>
> with Types;
> use  Types;
>
> with Char_Strings;
>
> but the compiler (Gnat 4.6) complains that there is no file called
> char_strings.ads.  I am not sure if I have made a simple mistake that
> can be easily corrected to make this work, or if there is a different
> approach that I should be trying.

You can only with a library-level package, one not declared in anything else. 
Char_Strings is declared in package types, so it's not library level and can't 
be withed.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-06  1:29 ` Jeffrey Carter
@ 2014-01-06  8:05   ` Simon Wright
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Wright @ 2014-01-06  8:05 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>>
>> --------------------------------------------------------------------------------
>> -- Types - Declarations of data types and related packages
>> --------------------------------------------------------------------------------
>> with Ada.Characters;
>> with Ada.Characters.Wide_Latin_1;
>> with Ada.Strings;
>> with Ada.Strings.Wide_Maps;
>> with Ada.Strings.Wide_Unbounded;
>> with Ada.Wide_Characters;
>> with Ada.Wide_Characters.Handling;
>> with Ada.Wide_Text_IO;
>> with Ada.Wide_Text_IO.Text_Streams;
>>
>> package Types is
>>    package Chars         renames Ada.Characters.Wide_Latin_1;
>>    package Char_Handling renames Ada.Wide_Characters.Handling;
>>    package Char_IO       renames Ada.Wide_Text_IO;
>>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>>
>>    subtype Char        is Wide_Character;
>>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
>> end Types;
>>
>> and then tried referencing this from the main program file with:
>>
>> with Types;
>> use  Types;
>>
>> with Char_Strings;
>>
>> but the compiler (Gnat 4.6) complains that there is no file called
>> char_strings.ads.  I am not sure if I have made a simple mistake that
>> can be easily corrected to make this work, or if there is a different
>> approach that I should be trying.
>
> You can only with a library-level package, one not declared in
> anything else. Char_Strings is declared in package types, so it's not
> library level and can't be withed.

So, you can either reclare package Chars etc at library level: for
example, in char_strings.ads,

   with Ada.Strings.Wide_Unbounded;
   package Char_Strings  renames Ada.Strings.Wide_Unbounded;

or you can change your main program file to say

   with Types;
   use Types;
   use Types.Chars;
   use Types.Char_Handling;
   ...

or perhaps

   with Types;
   use Types;
   procedure Main is
      use Chars;
      use Char_Handling;
      ...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-05 23:55 Q: Localizing type and package references b.mcguinness747
  2014-01-06  1:29 ` Jeffrey Carter
@ 2014-01-06  8:28 ` Dmitry A. Kazakov
  2014-01-06 20:19   ` Florian Weimer
  2014-01-19 12:04   ` Marius Amado-Alves
  2014-01-06 22:02 ` b.mcguinness747
  2 siblings, 2 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2014-01-06  8:28 UTC (permalink / raw)


On Sun, 5 Jan 2014 15:55:05 -0800 (PST), b.mcguinness747@gmail.com wrote:

> I want to write an Ada program using the Wide_Character type, but I might
> want to move to Wide_Wide_Character later on.

I would not do that. Wide_Wide_Character is pretty much useless from either
point of view. Stay with Character and use it as UTF-8 rather than Latin-1. 

P.S. Neither Windows nor Linux use Wide_Wide_Character in their API.
Windows is ASCII/UTF-16, Linux is UTF-8.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-06  8:28 ` Dmitry A. Kazakov
@ 2014-01-06 20:19   ` Florian Weimer
  2014-01-19 12:04   ` Marius Amado-Alves
  1 sibling, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2014-01-06 20:19 UTC (permalink / raw)


* Dmitry A. Kazakov:

> P.S. Neither Windows nor Linux use Wide_Wide_Character in their API.

wchar_t corresponds to Wide_Wide_Character on Linux.  There are few
APIs that use wchar_t, but some do exist.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-05 23:55 Q: Localizing type and package references b.mcguinness747
  2014-01-06  1:29 ` Jeffrey Carter
  2014-01-06  8:28 ` Dmitry A. Kazakov
@ 2014-01-06 22:02 ` b.mcguinness747
  2 siblings, 0 replies; 7+ messages in thread
From: b.mcguinness747 @ 2014-01-06 22:02 UTC (permalink / raw)


Thank you for your advice.  I was mainly looking for a way to write Ada code that could be modified easily later on to change data types if necessary, but the advice about character sets and operating systems is quite useful as well.

--- Brian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Q: Localizing type and package references
  2014-01-06  8:28 ` Dmitry A. Kazakov
  2014-01-06 20:19   ` Florian Weimer
@ 2014-01-19 12:04   ` Marius Amado-Alves
  1 sibling, 0 replies; 7+ messages in thread
From: Marius Amado-Alves @ 2014-01-19 12:04 UTC (permalink / raw)


"Stay with Character and use it as UTF-8 rather than Latin-1." (Kazakov)

In my experience also this is the best approach, specially now with conversion/encoding in the standard library.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-19 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-05 23:55 Q: Localizing type and package references b.mcguinness747
2014-01-06  1:29 ` Jeffrey Carter
2014-01-06  8:05   ` Simon Wright
2014-01-06  8:28 ` Dmitry A. Kazakov
2014-01-06 20:19   ` Florian Weimer
2014-01-19 12:04   ` Marius Amado-Alves
2014-01-06 22:02 ` b.mcguinness747

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox