// /*--------------------------------------------------------------------*\ // | Main Program: Simple tester for Partial_Map repeated arguments // |*--------------------------------------------------------------------*| // | Date: 1 October 1997 (revised 12 May 2003) // | Author: Scott Pike (revised by Bruce W. Weide) // | // | Brief User's Manual: // | Allows user to test implementation Partial_Map_1_C, interactively // | or in batch mode, with a special emphasis on repeated arguments. // | See Do_Swap_R_Items; no problem with Text-to-Text. // | // \*--------------------------------------------------------------------*/ ///--------------------------------------------------------------------- /// Global Context ----------------------------------------------------- ///--------------------------------------------------------------------- #include "RESOLVE_Foundation.h" #include "CT/Partial_Map/Kernel_1_C.h" #include "CT/Partial_Map/Put_To_1.h" #include "CT/Array/Kernel_1_C.h" ///--------------------------------------------------------------------- /// Interface ---------------------------------------------------------- ///--------------------------------------------------------------------- // Concrete instances concrete_instance class Partial_Map_Of_Text_To_Text_Base : instantiates Partial_Map_Kernel_1_C < Text, Text > {}; //---------------------------------------------------------------------- concrete_instance class Partial_Map_Of_Text_To_Text : instantiates Partial_Map_Put_To_1 < Text, Text, Partial_Map_Of_Text_To_Text_Base > {}; //---------------------------------------------------------------------- concrete_instance class Array_Of_Partial_Map_Of_Text_To_Text : instantiates Array_Kernel_1_C {}; //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Program control objects object Boolean interactive; object Text command_line; object Character command_code; object Character_IStream ins; object Character_OStream outs; // Test objects object Array_Of_Partial_Map_Of_Text_To_Text m; //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Global operations (omitted for brevity) //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Global operation bodies global_procedure_body Determine_Interactive_Mode () { outs << "Run in interactive mode (y/n)? "; ins >> command_line; command_code = command_line[0]; interactive = (command_code == 'y'); } //------------------------------------------------------------------------ global_procedure_body Get_Command () { if (interactive) { // Show menu of commands: // Concept-specific operations outs << "\n\nCommand: s [Swap]\n" << " c [Clear]\n" << " p [Put_To]\n" << " d [Define]\n" << " u [Undefine]\n" << " a [Undefine_Any]\n" << " i [Is_Defined]\n" << " [ [Swap Using Accessor]\n" << " z [Size]\n" // Repeated argument possibilities << " & [Swap R_Items with repeated arguments]\n" << " < [Less than R_Items with repeated arguments]\n" // Tester control operations << " q [Quit]: "; } // Get next command line and code ins >> command_line; command_code = command_line[0]; } //------------------------------------------------------------------------ global_procedure_body Do_Swap () { object Integer id1, id2; object Partial_Map_Of_Text_To_Text temp; // to avoid repeated argument if (interactive) { outs << "Swap which object? "; } ins >> id1; if (interactive) { outs << " ... with which object? "; } ins >> id2; outs << "\n--------------------------------------------" << "\n |"; outs << "\n--------------------------------------------" << "\nm" << id1 << " &= m" << id2 << "; |"; temp &= m[id1]; temp &= m[id2]; temp &= m[id1]; outs << "\n--------------------------------------------" << "\n |"; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Clear () { object Integer id; if (interactive) { outs << "Clear which object? "; } ins >> id; outs << "\n--------------------------------------------" << "\n |"; outs << "\n--------------------------------------------" << "\nm" << id << ".Clear (); |"; m[id].Clear (); outs << "\n--------------------------------------------" << "\n |"; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Put_To () { object Integer id; if (interactive) { outs << "Put which object? "; } ins >> id; outs << "\n--------------------------------------------" << "\nm" << id << " = "; outs << m[id]; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Define () { object Integer id; object Text d, r; if (interactive) { outs << "Define into which object? "; } ins >> id; if (interactive) { outs << " ... d value? "; } ins >> d; if (interactive) { outs << " ... r value? "; } ins >> r; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------" << "\nm" << id << ".Define (d, r); |"; m[id].Define (d, r); outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Undefine () { object Integer id; object Text d, d_copy, r; if (interactive) { outs << "Undefine from which object? "; } ins >> id; if (interactive) { outs << " ... d value? "; } ins >> d; if (interactive) { outs << " ... d_copy value? "; } ins >> d_copy; if (interactive) { outs << " ... r value? "; } ins >> r; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | d_copy = " << d_copy << "\n | r = " << r; outs << "\n--------------------------------------------" << "\nm" << id << ".Undefine (d, d_copy, r); |"; m[id].Undefine (d, d_copy, r); outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | d_copy = " << d_copy << "\n | r = " << r; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Undefine_Any () { object Integer id; object Text d, r; if (interactive) { outs << "Undefine_Any from which object? "; } ins >> id; if (interactive) { outs << " ... d value? "; } ins >> d; if (interactive) { outs << " ... r value? "; } ins >> r; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------" << "\nm" << id << ".Undefine_Any (d, r); |"; m[id].Undefine_Any (d, r); outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Is_Defined () { object Integer id; object Text d; object Boolean b; if (interactive) { outs << "Is_Defined in which object? "; } ins >> id; if (interactive) { outs << " ... d value? "; } ins >> d; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | b = ?"; outs << "\n--------------------------------------------" << "\nb = m" << id << ".Is_Defined (d); |"; b = m[id].Is_Defined (d); outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | b = " << b; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Swap_Using_Accessor () { object Integer id; object Text d, r; if (interactive) { outs << "Swap using accessor in which object? "; } ins >> id; if (interactive) { outs << " ... d value? "; } ins >> d; if (interactive) { outs << " ... r value to swap with? "; } ins >> r; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------" << "\nr &= m" << id << "[d]; |"; r &= m[id][d]; outs << "\n--------------------------------------------" << "\n | d = " << d << "\n | r = " << r; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Size () { object Integer id; object Integer i; if (interactive) { outs << "Get size of which object? "; } ins >> id; outs << "\n--------------------------------------------" << "\n | i = ?"; outs << "\n--------------------------------------------" << "\ni = m" << id << ".Size (); |"; i = m[id].Size (); outs << "\n--------------------------------------------" << "\n | i = " << i; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ global_procedure_body Do_Swap_R_Items () { object Integer id; object Text d1, d2, r1, r2; if (interactive) { outs << "Swap R_Items in which object? "; } ins >> id; if (interactive) { outs << " ... d1 value? "; } ins >> d1; if (interactive) { outs << " ... d2 value? "; } ins >> d2; outs << "\n--------------------------------------------" << "\n | d1 = " << d1 << "\n | d2 = " << d2; outs << "\n--------------------------------------------" << "\nm" << id << "[d1] &= m" << id << "[d2]; |"; m[id][d1] &= m[id][d2]; outs << "\n--------------------------------------------" << "\n | d1 = " << d1 << "\n | d2 = " << d2; outs << "\n--------------------------------------------"; } //------------------------------------------------------------------------ //------------------------------------------------------------------------ program_body main () { object Boolean finished; // Open input and output streams ins.Open_External (""); outs.Open_External (""); // Set number of test objects (= 10) m.Set_Bounds (0, 9); // Ask user about interactive mode Determine_Interactive_Mode (); // Execute interactive testing loop until finished while (not finished) { // Ask user for next command Get_Command (); // Perform next command case_select (command_code) { // Concept-specific operations case 's': Do_Swap (); break; case 'c': Do_Clear (); break; case 'p': Do_Put_To (); break; case 'd': Do_Define (); break; case 'u': Do_Undefine (); break; case 'a': Do_Undefine_Any (); break; case 'i': Do_Is_Defined (); break; case '[': Do_Swap_Using_Accessor (); break; case 'z': Do_Size (); break; // Repeated argument possibilities case '&': Do_Swap_R_Items (); break; // Tester control operations case 'q': finished = true; break; default: outs << "\n" << command_line; break; } } // Close input and output streams ins.Close_External (); outs.Close_External (); }