From: Michal MalĂ˝ Date: Sat, 27 Dec 2014 21:26:30 +0000 (+0100) Subject: - Unify resource prefix handling X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=cdfb24b53c5502b851c5601d4c3bd86037017939;p=Nine-Q.git - Unify resource prefix handling - Prepare for full walkthrough implementation --- diff --git a/src/global_types.ads b/src/global_types.ads index 6d6d4b2..88c1e7d 100644 --- a/src/global_types.ads +++ b/src/global_types.ads @@ -4,7 +4,7 @@ with Ada.Strings.Unbounded; package Global_Types is type Problem_ID is new Ada.Containers.Count_Type; - type RetCode is (OK, E_NOTFOUND, E_UNKW, E_INVAL, E_NOMEM, E_NULLPTR, E_FAIL); + type RetCode is (OK, E_NOTFOUND, E_UNKW, E_INVAL, E_NOMEM, E_NULLPTR, E_FAIL, E_NOTIMPL); type Unique_ID is new Ada.Containers.Count_Type; subtype HTML_Code is Ada.Strings.Unbounded.Unbounded_String; subtype UB_Text is Ada.Strings.Unbounded.Unbounded_String; diff --git a/src/problem_generators/problem_generator-acidobazic_suite.adb b/src/problem_generators/problem_generator-acidobazic_suite.adb index 5bdd0bf..273003f 100644 --- a/src/problem_generators/problem_generator-acidobazic_suite.adb +++ b/src/problem_generators/problem_generator-acidobazic_suite.adb @@ -9,7 +9,7 @@ separate(Problem_Generator) package body Acidobazic_Suite is -- BEGIN: Inherited functions - function Create return access Acidobazic_Problem is + function Create return access Acidobazic_Problem is Parameters: Acidobazic_Parameters; Problem: access Acidobazic_Problem; begin @@ -84,7 +84,7 @@ package body Acidobazic_Suite is end; end Check_Answer; - function Get_Assignment(Problem: in out Acidobazic_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is + function Get_Assignment(Problem: in out Acidobazic_Problem; Assignment: in out Assignment_Info.Map) return RetCode is C: Assignment_Info.Cursor; Success: Boolean; pKx: pH_Float; @@ -151,6 +151,11 @@ package body Acidobazic_Suite is return OK; end Get_Parameters; + function Get_Walkthrough(Problem: in out Acidobazic_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is + begin + return E_NOTIMPL; + end Get_Walkthrough; + procedure New_Problem(Problem: in out Acidobazic_Problem) is package Random_Substance_Type_Gen is new Ada.Numerics.Discrete_Random(Result_Subtype => Substance_Type); diff --git a/src/problem_generators/problem_generator-solubility_suite.adb b/src/problem_generators/problem_generator-solubility_suite.adb index a99af41..d954532 100644 --- a/src/problem_generators/problem_generator-solubility_suite.adb +++ b/src/problem_generators/problem_generator-solubility_suite.adb @@ -68,7 +68,7 @@ package body Solubility_Suite is return Correct_Answer; end Check_Answer; - function Get_Assignment(Problem: in out Solubility_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is + function Get_Assignment(Problem: in out Solubility_Problem; Assignment: in out Assignment_Info.Map) return RetCode is package FH is new Formatting_Helpers(SS_Float); use FH; begin @@ -286,6 +286,11 @@ package body Solubility_Suite is Problem.Answer_Num := Answer_Num; end New_Problem; + function Get_Walkthrough(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is + begin + return E_NOTIMPL; + end Get_Walkthrough; + function Set_Parameters(Problem: in out Solubility_Problem; Parameters: in Parameters_Info.Map) return RetCode is use Parameters_Info; begin diff --git a/src/problem_generators/problem_generator-titration_curve_suite.adb b/src/problem_generators/problem_generator-titration_curve_suite.adb index e1a4606..ffb0ae0 100644 --- a/src/problem_generators/problem_generator-titration_curve_suite.adb +++ b/src/problem_generators/problem_generator-titration_curve_suite.adb @@ -186,7 +186,7 @@ package body Titration_Curve_Suite is return Correct_Answer; end Check_Answer; - function Get_Assignment(Problem: in out Titration_Curve_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is + function Get_Assignment(Problem: in out Titration_Curve_Problem; Assignment: in out Assignment_Info.Map) return RetCode is package FH is new Formatting_Helpers(T_Float); use FH; @@ -196,8 +196,6 @@ package body Titration_Curve_Suite is pKx1_Int, pKx1_Dec: UB_Text; pKx2_Int, pKx2_Dec: UB_Text; begin - Problem.Resource_Prefix := Ada.Strings.Unbounded.To_Unbounded_String(Resource_Prefix); - Split_Integer_Decimal_Exponent_Strs(Problem.Sample_Concentration, DECIMALS, Sample_Conc_Int, Sample_Conc_Dec, Sample_Conc_Exp); Split_Integer_Decimal_Exponent_Strs(Problem.Sample_Volume, DECIMALS, Sample_Volume_Int, Sample_Volume_Dec, Sample_Volume_Exp); Split_Integer_Decimal_Exponent_Strs(Problem.T_Concentration, DECIMALS, Titrant_Conc_Int, Titrant_Conc_Dec, Titrant_Conc_Exp); @@ -242,6 +240,11 @@ package body Titration_Curve_Suite is return OK; end Get_Parameters; + function Get_Walkthrough(Problem: in out Titration_Curve_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is + begin + return E_NOTIMPL; + end Get_Walkthrough; + procedure New_Problem(Problem: in out Titration_Curve_Problem) is package FH is new Formatting_Helpers(T_Float); package TFEF is new Ada.Numerics.Generic_Elementary_Functions(T_Float); diff --git a/src/problem_generators/problem_generator.adb b/src/problem_generators/problem_generator.adb index 93d3603..8e4cae7 100644 --- a/src/problem_generators/problem_generator.adb +++ b/src/problem_generators/problem_generator.adb @@ -12,6 +12,11 @@ package body Problem_Generator is end case; end Get_Problem; + procedure Set_Resource_Prefix(Problem: in out Chem_Problem; Prefix: in String) is + begin + Problem.Resource_Prefix := Ada.Strings.Unbounded.To_Unbounded_String(Prefix); + end Set_Resource_Prefix; + package body Acidobazic_Suite is separate; package body Solubility_Suite is separate; package body Titration_Curve_Suite is separate; diff --git a/src/problem_generators/problem_generator.ads b/src/problem_generators/problem_generator.ads index f1d228a..6ad8862 100644 --- a/src/problem_generators/problem_generator.ads +++ b/src/problem_generators/problem_generator.ads @@ -12,16 +12,20 @@ package Problem_Generator is function Create return access Chem_Problem is abstract; function Check_Answer(Problem: in out Chem_Problem; Answer: in Answer_Info.Map; FillIns: in out FillIns_Map.Map; Message: out UB_Text) return Answer_RetCode is abstract; - function Get_Assignment(Problem: in out Chem_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is abstract; + function Get_Assignment(Problem: in out Chem_Problem; Assignment: in out Assignment_Info.Map) return RetCode is abstract; function Get_Parameters(Problem: in out Chem_Problem; Parameters: out Parameters_Info.Map) return RetCode is abstract; + function Get_Walkthrough(Problem: in out Chem_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is abstract; procedure New_Problem(Problem: in out Chem_Problem) is abstract; function Set_Parameters(Problem: in out Chem_Problem; Parameters: in Parameters_Info.Map) return RetCode is abstract; - + procedure Set_Resource_Prefix(Problem: in out Chem_Problem; Prefix: in String); function Get_Problem(P_Type: in Problem_Type) return access Chem_Problem'Class; private - type Chem_Problem is abstract limited new Ada.Finalization.Limited_Controlled with null record; + type Chem_Problem is abstract limited new Ada.Finalization.Limited_Controlled with + record + Resource_Prefix: Ada.Strings.Unbounded.Unbounded_String; + end record; package Acidobazic_Suite is use Problem_Generator_Syswides.Acidobazic_Suite; @@ -32,8 +36,9 @@ private -- Inherited function Check_Answer(Problem: in out Acidobazic_Problem; Answer: in Answer_Info.Map; FillIns: in out FillIns_Map.Map; Message: out UB_Text) return Answer_RetCode; procedure New_Problem(Problem: in out Acidobazic_Problem); - function Get_Assignment(Problem: in out Acidobazic_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode; + function Get_Assignment(Problem: in out Acidobazic_Problem; Assignment: in out Assignment_Info.Map) return RetCode; function Get_Parameters(Problem: in out Acidobazic_Problem; Parameters: out Parameters_Info.Map) return RetCode; + function Get_Walkthrough(Problem: in out Acidobazic_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode; function Set_Parameters(Problem: in out Acidobazic_Problem; Parameters: in Parameters_Info.Map) return RetCode; private @@ -92,8 +97,9 @@ private -- Inherited function Check_Answer(Problem: in out Solubility_Problem; Answer: in Answer_Info.Map; FillIns: in out FillIns_Map.Map; Message: out UB_Text) return Answer_RetCode; procedure New_Problem(Problem: in out Solubility_Problem); - function Get_Assignment(Problem: in out Solubility_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode; + function Get_Assignment(Problem: in out Solubility_Problem; Assignment: in out Assignment_Info.Map) return RetCode; function Get_Parameters(Problem: in out Solubility_Problem; Parameters: out Parameters_Info.Map) return RetCode; + function Get_Walkthrough(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode; function Set_Parameters(Problem: in out Solubility_Problem; Parameters: in Parameters_Info.Map) return RetCode; private @@ -177,8 +183,9 @@ private function Create return access Titration_Curve_Problem; -- Inherited function Check_Answer(Problem: in out Titration_Curve_Problem; Answer: in Answer_Info.Map; FillIns: in out FillIns_Map.Map; Message: out UB_Text) return Answer_RetCode; - function Get_Assignment(Problem: in out Titration_Curve_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode; + function Get_Assignment(Problem: in out Titration_Curve_Problem; Assignment: in out Assignment_Info.Map) return RetCode; function Get_Parameters(Problem: in out Titration_Curve_Problem; Parameters: out Parameters_Info.Map) return RetCode; + function Get_Walkthrough(Problem: in out Titration_Curve_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode; procedure New_Problem(Problem: in out Titration_Curve_Problem); function Set_Parameters(Problem: in out Titration_Curve_Problem; Parameters: in Parameters_Info.Map) return RetCode; overriding procedure Finalize(Problem: in out Titration_Curve_Problem); @@ -192,7 +199,6 @@ private SType: Sample_Type; pKx1: T_Float; pKx2: T_Float; - Resource_Prefix: Ada.Strings.Unbounded.Unbounded_String; Sample_Volume: T_Float; Sample_Concentration: T_Float; T_Concentration: T_Float; diff --git a/src/problem_generators/problem_generator_syswides.ads b/src/problem_generators/problem_generator_syswides.ads index 77ab92a..29747f6 100644 --- a/src/problem_generators/problem_generator_syswides.ads +++ b/src/problem_generators/problem_generator_syswides.ads @@ -8,6 +8,7 @@ package Problem_Generator_Syswides is package Assignment_Info is new Ada.Containers.Indefinite_Ordered_Maps(String, String); package FillIns_Map is new Ada.Containers.Indefinite_Ordered_Maps(String, String); package Parameters_Info is new Ada.Containers.Indefinite_Ordered_Maps(String, String); + package Walkthrough_Info is new Ada.Containers.Indefinite_Ordered_Maps(String, String); ANSWER_KIND_KEY: constant String := "ANSWER_KIND"; ANSWER_KIND_GOOD: constant String := "answer_kind_good"; diff --git a/src/problem_manager.adb b/src/problem_manager.adb index 990123d..ce40a39 100644 --- a/src/problem_manager.adb +++ b/src/problem_manager.adb @@ -30,7 +30,7 @@ package body Problem_Manager is end if; begin - Ret := Stored.Problem.Get_Assignment(Assignment, Build_Resource_Prefix(UID, Pr_Cat, Pr_ID)); + Ret := Stored.Problem.Get_Assignment(Assignment); if Ret /= OK then Stored.Mutex.Unlock; Logging_System.Log(ERRMSG_GET_ASSIGNMENT & " (" & RetCode'Image(Ret) & ")", Logging_System.ERROR); @@ -80,7 +80,7 @@ package body Problem_Manager is -- Get assignment begin - Ret := Stored.Problem.Get_Assignment(Assignment, Build_Resource_Prefix(UID, Pr_Cat, Pr_ID)); + Ret := Stored.Problem.Get_Assignment(Assignment); if Ret /= OK then Stored.Mutex.Unlock; Logging_System.Log(ERRMSG_GET_ASSIGNMENT & " (" & RetCode'Image(Ret) & ")", Logging_System.ERROR); @@ -113,20 +113,21 @@ package body Problem_Manager is Parameters: in Problem_Generator_Syswides.Parameters_Info.Map := Problem_Generator_Syswides.Parameters_Info.Empty_Map) return RetCode is Problem: Chem_Problem_All_Access; Storage: Stored_Problem_All_Access; - P_Cat: Problem_Category; + Pr_Cat: Problem_Category; + Pr_ID: Problem_ID; Ret: RetCode; begin if Raw_P_Cat = Problem_Manager.Problem_Category'Image(Problem_Manager.Acidobazic) then - P_Cat := Problem_Manager.Acidobazic; + Pr_Cat := Problem_Manager.Acidobazic; elsif Raw_P_Cat = Problem_Manager.Problem_Category'Image(Problem_Manager.Solubility) then - P_Cat := Problem_Manager.Solubility; + Pr_Cat := Problem_Manager.Solubility; elsif Raw_P_Cat = Problem_Manager.Problem_Category'Image(Problem_Manager.Titration_Curve) then - P_Cat := Problem_Manager.Titration_Curve; + Pr_Cat := Problem_Manager.Titration_Curve; else return E_INVAL; end if; - case P_Cat is + case Pr_Cat is when Acidobazic => Problem := Problem_Generator.Get_Problem(Problem_Generator_Syswides.Acidobazic); when Solubility => @@ -159,13 +160,15 @@ package body Problem_Manager is Storage := new Stored_Problem; Storage.Problem := Problem; - Storage.Category := P_Cat; - Active_Sessions.Add_Problem(UID, Storage, Ret); + Storage.Category := Pr_Cat; + Active_Sessions.Add_Problem(UID, Storage, Pr_ID, Ret); if Ret /= OK then Free_Chem_Problem(Problem); Free_Stored_Problem(Storage); end if; + + Problem.Set_Resource_Prefix(Build_Resource_Prefix(UID, Pr_Cat, Pr_ID)); return Ret; end Prepare_Problem; @@ -208,7 +211,7 @@ package body Problem_Manager is protected body Active_Sessions is - procedure Add_Problem(UID: in Unique_ID; Problem: in Stored_Problem_All_Access; Ret: out RetCode) is + procedure Add_Problem(UID: in Unique_ID; Problem: in Stored_Problem_All_Access; Pr_ID: out Problem_ID; Ret: out RetCode) is use Problem_Storage; use Session_Keeping; use Ada.Containers; @@ -228,6 +231,7 @@ package body Problem_Manager is Ret := E_NOMEM; return; end if; + Pr_ID := USD.Last_Problem_ID; USD.Last_Problem_ID := USD.Last_Problem_ID + 1; -- Delete old problems diff --git a/src/problem_manager.ads b/src/problem_manager.ads index 5437473..2af5a99 100644 --- a/src/problem_manager.ads +++ b/src/problem_manager.ads @@ -52,7 +52,7 @@ private package Session_Keeping is new Ada.Containers.Ordered_Maps(Key_Type => Unique_ID, Element_Type => User_Session_All_Access); protected Active_Sessions is - procedure Add_Problem(UID: in Unique_ID; Problem: in Stored_Problem_All_Access; Ret: out RetCode); + procedure Add_Problem(UID: in Unique_ID; Problem: in Stored_Problem_All_Access; Pr_ID: out Problem_ID; Ret: out RetCode); function Contains(UID: in Unique_ID) return Boolean; function Get_Problem(UID: in Unique_ID; Pr_ID: in Problem_ID) return Stored_Problem_All_Access; function Get_Latest_Problem_With_ID(UID: in Unique_ID; Pr_ID: out Problem_ID) return Stored_Problem_All_Access;