]> Devoid-pointer.net GitWeb - Nine-Q.git/commitdiff
- Unify resource prefix handling
authorMichal Malý <madcatxster@devoid-pointer.net>
Sat, 27 Dec 2014 21:26:30 +0000 (22:26 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sat, 27 Dec 2014 21:26:30 +0000 (22:26 +0100)
- Prepare for full walkthrough implementation

src/global_types.ads
src/problem_generators/problem_generator-acidobazic_suite.adb
src/problem_generators/problem_generator-solubility_suite.adb
src/problem_generators/problem_generator-titration_curve_suite.adb
src/problem_generators/problem_generator.adb
src/problem_generators/problem_generator.ads
src/problem_generators/problem_generator_syswides.ads
src/problem_manager.adb
src/problem_manager.ads

index 6d6d4b2796517dc45f51b0dba0eca7b87aa027a5..88c1e7dec431dde32b44ce616731b74c1dcab1bd 100644 (file)
@@ -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;
index 5bdd0bf63656f410b25c4462e6bfc57e7167f4ae..273003fbeb736a3299193350e1c9aa0d5c6925c0 100644 (file)
@@ -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);
 
index a99af415639e50d36a14dba7f7cadc487a5e11d3..d95453201552d8469cc14f74b17c969d63b25494 100644 (file)
@@ -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
index e1a4606035ff4aed81940427ffba3f93cedf1889..ffb0ae03b3a32a4562d93ad95a61cf10c23a1529 100644 (file)
@@ -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);
index 93d36034679def89b334c27be1817727a0dc5c7d..8e4cae7ba099e14e19aa8e77a619cb8088820bad 100644 (file)
@@ -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;
index f1d228a25b09f6f2d8e2d96852c813674eb1649e..6ad8862cac2da197f3aaadb323917f69c093c1c3 100644 (file)
@@ -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;
index 77ab92a9970779e09d6bc0f6c61b5e9b2969271a..29747f6a990c6711488f3116817a37c0f66cc394 100644 (file)
@@ -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";
index 990123d5be35fe236b5fac7e1d917d44a2ec6174..ce40a39685266a4e84877a90fc8c7012cacbd9b8 100644 (file)
@@ -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
index 5437473000d2436ecaeba1197b984dc6318e803c..2af5a99ef6bc6779cb301bd9c785b3c3a435f2e7 100644 (file)
@@ -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;