comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Abstraction over container iterators
@ 2012-08-03 12:01  7% ms
  0 siblings, 0 replies; 1+ results
From: ms @ 2012-08-03 12:01 UTC (permalink / raw)


I'll let the code speak first:

-----------------------------------------------
with Ada.Containers.Hashed_Maps;                                                
with Ada.Strings.Unbounded;                                                     
with Ada.Strings.Unbounded.Hash_Case_Insensitive;                               
with Ada.Strings.Unbounded.Equal_Case_Insensitive;                              

package Environments is                                                         

   type Environment is tagged private;                                          

   function Variable (                                                          
      E    : in Environment;                                                    
      Name : in Ada.Strings.Unbounded.Unbounded_String                          
   )                                                                            
      return Ada.Strings.Unbounded.Unbounded_String                             
      with Inline;                                                              

   procedure Set_Variable (                                                     
      E     : in out Environment;                                               
      Name  : in Ada.Strings.Unbounded.Unbounded_String;                        
      Value : in Ada.Strings.Unbounded.Unbounded_String                         
   )                                                                            
      with Inline;                                                              

private                                                                         

   package Variable_Maps is new Ada.Containers.Hashed_Maps (                    
      Key_Type        => Ada.Strings.Unbounded.Unbounded_String,                
      Element_Type    => Ada.Strings.Unbounded.Unbounded_String,                
      Hash            => Ada.Strings.Unbounded.Hash_Case_Insensitive,           
      Equivalent_Keys => Ada.Strings.Unbounded.Equal_Case_Insensitive,          
      "="             => Ada.Strings.Unbounded."="                              
   );                                                                           

   type Environment is tagged record                                            
      Variables : Variable_Maps.Map;                                            
   end record;                                                                  

end Environments;
-----------------------------------------------

What we have here is an example package fairly well illustrating my problem. I'm storing some environment variables in Hashed_Map, but I want to build a abstraction layer over the standard container, so I can in future change the underlaying container without changing any code in my package's customers.

Getting and setting variables is easy - as declared above. The real problem is iterating. I'd like to let my package's customers to iterate over the environment and get both key and value for each element easily.

As I'm using Ada 2012 the best way would be to use iterators, but how? I could return a cursor to the underlaying container, but again, this cursor's interface would be container-dependent.

What would you say is the best way to achieve such abstraction over standard container iteration?



^ permalink raw reply	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2012-08-03 12:01  7% Abstraction over container iterators ms

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