Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a different version which stores the Item (not its access) in the Vector. It works by using inheritance, creating a Vector of a base type. That implies an Indefinite_Vector because the size of each individual component is not known in advance.</p> <p>Again, compiled but untested.</p> <pre><code>with Ada.Containers.Indefinite_Vectors; package Boxed_Base is type Base_Item is tagged record null; end record; package Item_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type =&gt; Natural, Element_Type =&gt; Base_Item'Class); use Item_Vectors; type Vector_Ptr is access Vector; end Boxed_Base; </code></pre> <p>This base type has the property that it can be stored in the vector, and have its storage management handled by Indefinite_Vectors. Now we can inherit from it, with the characteristics we need.</p> <pre><code>with Ada.Strings.Wide_Unbounded; use Ada.Strings.Wide_Unbounded; with Ada.Unchecked_Deallocation; with Boxed_Base; package Boxed_Types is type UInteger_64 is new integer; type Green_Task_Ptr is access UInteger_64; -- these two because original testcase was incomplete type String_Ptr is access Unbounded_Wide_String; type Type_T is (T_Null, T_UInt64, T_Text, T_Bool, T_GTask, T_Vector); type Item (IType : Type_T ) is new Boxed_Base.Base_Item with record case IType is when T_Null =&gt; null; when T_UInt64 =&gt; UInt64 : UInteger_64; when T_Text =&gt; String : String_Ptr; when T_Bool =&gt; Bool : Boolean; when T_GTask =&gt; Green_Task : Green_Task_Ptr; when T_Vector =&gt; Item_Vector : Boxed_Base.Vector_Ptr; end case; end record; end Boxed_Types; </code></pre> <p>One feature of the original design has gone : the default discriminant is not allowed for tagged types : that means that you create an instance with a definite discriminant (and thus a definite size!) and cannot modify it later (just replace the object with a new one).</p> <p>Another feature <em>may</em> be worth mentioning : Indefinite_Vectors may have a performance penalty over their Definite cousins : if so, that is the necessary cost incurred by heterogeneous object sizes and will pop up in some form however you slice the problem.</p> <p>It would also be possible to eliminate the discriminant Type_T by creating different subclasses for each type of Item; maybe a cleaner design but at this stage that is more refactoring than you probably want!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload