Scaffolding for properties in place
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
with Semantic_Versioning;
|
||||
|
||||
package Alire.Properties.Versions is
|
||||
|
||||
type Version is new Property with record
|
||||
Value : Semantic_Versioning.Version;
|
||||
end record;
|
||||
|
||||
end Alire.Properties.Versions;
|
||||
@@ -1,33 +1,18 @@
|
||||
private with Ada.Containers.Indefinite_Holders;
|
||||
with Ada.Containers.Indefinite_Vectors;
|
||||
|
||||
package Alire.Properties with Preelaborate is
|
||||
|
||||
-- Properties are the general mechanism used to store all info about a release.
|
||||
-- They can be specialized (e.g. in version, platform, compiler) but that can be transparent to the user.
|
||||
|
||||
-- Since a property can be checked against a variety of conditions, this would require fully fledged
|
||||
-- multiple inheritance for the simplest design.
|
||||
-- Instead, a first check of matching tags is done and then the checks can proceed.
|
||||
|
||||
type Property is tagged null record;
|
||||
|
||||
package Property_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Property'Class);
|
||||
|
||||
|
||||
type Checker is tagged private;
|
||||
-- A checker verifies against some internally stored data that a property is satisfied.
|
||||
-- Here we provide the basic storage of values but the actual checking function must be overridden
|
||||
-- for particular checks.
|
||||
|
||||
function New_Check (Using : Property'Class) return Checker'Class;
|
||||
|
||||
function Value (Check : Checker'Class) return Property'Class;
|
||||
|
||||
function Check (This : Checker'Class; Prop : Property'Class) return Boolean;
|
||||
-- This classwide helper will match the stored property tag against the one given.
|
||||
-- If the match the actual checking function is used, otherwise False is returned
|
||||
|
||||
private
|
||||
|
||||
package Property_Holders is new Ada.Containers.Indefinite_Holders (Property'Class);
|
||||
|
||||
type Checker is tagged record
|
||||
Property : Property_Holders.Holder;
|
||||
end record;
|
||||
subtype Vector is Property_Vectors.Vector;
|
||||
|
||||
end Alire.Properties;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
with Ada.Containers.Indefinite_Multiway_Trees;
|
||||
|
||||
with Alire.Properties;
|
||||
|
||||
package Alire.Requisites with Preelaborate is
|
||||
|
||||
use Properties;
|
||||
|
||||
type Requisite is tagged null record;
|
||||
-- A Requisite verifies against some internally stored data that a property is satisfied.
|
||||
-- Here we provide the basic storage of values but the actual checking function must be overridden
|
||||
-- for particular checks.
|
||||
|
||||
function Is_Applicable (R : Requisite; P : Property'Class) return Boolean is (False);
|
||||
-- Initially there is no compatibility. See helper package below
|
||||
|
||||
package Requisite_Trees is new Ada.Containers.Indefinite_Multiway_Trees (Requisite'Class);
|
||||
|
||||
subtype Tree is Requisite_Trees.Tree;
|
||||
|
||||
-- The following package is the building block to be used to define new compatibility checks.
|
||||
-- Here we tie a class of properties and requisites (e.g., versions and version sets) that make sense.
|
||||
-- A release has a list of properties, and a tree of requisites to be applied to potential dependencies.
|
||||
|
||||
generic
|
||||
type Compatible_Property is new Property with private;
|
||||
package Property_Checker is
|
||||
|
||||
type Requisite is new Requisites.Requisite with null record;
|
||||
|
||||
function Is_Satisfied (R : Requisite; P : Compatible_Property) return Boolean;
|
||||
-- This is the important function to override by Requisite implementations
|
||||
|
||||
-- The remainder methods are utilities that do not require modifications by the client.
|
||||
|
||||
overriding function Is_Applicable (R : Requisite; P : Property'Class) return Boolean is
|
||||
(P in Compatible_Property);
|
||||
-- Convenience for the evaluator to determine which properties might satisfy a requisite
|
||||
|
||||
function Cast (R : Requisite; P : Property'Class) return Compatible_Property'Class is
|
||||
(Compatible_Property'Class (P))
|
||||
with Pre => R.Is_Applicable (P);
|
||||
-- Convenience cast that can be done inside the package, but not outside, so it must be available here!
|
||||
|
||||
end Property_Checker;
|
||||
|
||||
end Alire.Requisites;
|
||||
Reference in New Issue
Block a user